开发者

SOAP Response to DataTable in C#

I have been searching and trying in many forms to pass an XML Response to a simple DataTable in the same way Excel does.

The XML is like:

<?xml version="1.0" standalone="no"?>
<SOAP-ENV:Envelope xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema" xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        <SOAPSDK4:Function xmlns:SOAPSDK4="http://www.externalwebservice.com/message/">
            <Lists>
                <ListCode>12345</ListCode>
                <ListGroups>
                    <ListGroup>
                        <CodeGroup>ASDF</CodeGroup>
                        <DescriptionGroup>Example</DescriptionGroup>
                    </ListGroup>
                </ListGroups>
                <List>
                    <CodeList>ABC</CodeList>
                    <DescriptionList>Example List</DescriptionList>
                    <ListCategories>
                        <ListCategory>Type1</ListCategory>
                        <ListCategory>Type2</ListCategory>
                    </ListCategories>
                    <ListKinds>
                        <Kind>
                            <KindType>A</KindType>
                            <KindTarget>1</KindTarget>
                            <KindAttributes>
                                <KindAttribute1>A</KindAttribute1>
                                <KindAttribute2>B</KindAttribute2>
                            </KindAttributes>
                        </Kind>
                    </ListKinds>
                </List>
开发者_如何学编程            </Lists>
        </SOAPSDK4:Function>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

What Excel does could help me in what I need and that is to fill 4 tables with this data and its relations.

I have tried using DataSet.ReadXML but the problem with it is that for some reason this method generates 14 tables with the data being of no use because there is no relation at all. Later I tried with DataTable.ReadXML but it gave me the problem "DataTable does not support schema inference from Xml." then tried to use DataTable.ReadXmlSchema(XML) and it gave an error with no root document, then I created an XSD with the command prompt and the two generated gave an error, finally I used Visual Studio to generate the XSD, it generated 4 XSD with no errors but no columns where created and no data was added with none of them.

I am out of ideas now. Any suggestions? Maybe not a DataTable with no normalized data (what Excel does) but another approach going directly with the XML?

Thank you.


My suggestion would be Linq.XML technique in C# 3. LINQ to XML provides an in-memory XML programming interface that leverages the .NET Language-Integrated Query (LINQ) Framework. LINQ to XML uses the latest .NET Framework language capabilities and is comparable to an updated, redesigned Document Object Model (DOM) XML programming interface.

There are few interesting quick relevant examples are available at http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜