简体   繁体   English

C#中对DataTable的SOAP响应

[英]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. 我一直在搜索并尝试以多种形式将XML响应以与Excel相同的方式传递给简单的DataTable。

The XML is like: XML就像:

<?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. Excel所做的工作可以帮助我满足需要,那就是用此数据及其关系填充4个表。

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. 我试过使用DataSet.ReadXML,但是它的问题是由于某种原因,此方法生成14个表,而数据却毫无用处,因为根本没有关系。 Later I tried with DataTable.ReadXML but it gave me the problem "DataTable does not support schema inference from Xml." 后来我尝试使用DataTable.ReadXML,但是它给了我一个问题:“ DataTable不支持从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. 然后尝试使用DataTable.ReadXmlSchema(XML),它给出了没有根文档的错误,然后我用命令提示符创建了一个XSD,并且生成的两个给出了错误,最后我使用Visual Studio生成了XSD,它生成了4 XSD没有错误,但是没有创建任何列,也没有添加任何数据。

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? 也许不是没有标准化数据的DataTable(Excel做什么),而是直接与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. 我的建议是使用C#3中的Linq.XML技术。LINQ to XML提供了一个内存XML编程接口,该接口利用了.NET语言集成的查询(LINQ)框架。 LINQ to XML uses the latest .NET Framework language capabilities and is comparable to an updated, redesigned Document Object Model (DOM) XML programming interface. LINQ to XML使用最新的.NET Framework语言功能,可与经过重新设计的更新的文档对象模型(DOM)XML编程接口进行比较。

There are few interesting quick relevant examples are available at http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx上提供了一些有趣的快速相关示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM