c#中对数据表的SOAP响应

本文关键字:SOAP 响应 数据表 | 更新日期: 2023-09-27 18:06:54

我一直在寻找并尝试以多种形式将XML响应传递给简单的DataTable,就像Excel一样。

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>

Excel所做的可以帮助我做我需要的,那就是用这些数据和它们的关系填充4个表。

我已经尝试使用数据集。ReadXML,但它的问题是,由于某种原因,该方法生成14个表,其中的数据没有用处,因为根本没有关系。后来我尝试了DataTable。ReadXML,但它给了我问题"DataTable不支持Xml的模式推断",然后试图使用DataTable. readxmlschema (Xml),它给出了一个没有根文档的错误,然后我用命令提示符创建了一个XSD,两个生成的XSD给出了一个错误,最后我使用Visual Studio生成XSD,它生成了4个XSD,没有错误,但没有列在哪里创建,没有数据被添加。

我现在没有主意了。有什么建议吗?也许不是一个没有规范化数据的DataTable (Excel是这样做的),而是直接使用XML的另一种方法?

谢谢。

c#中对数据表的SOAP响应

我的建议是c# 3中的Linq.XML技术。LINQ to XML提供了一个内存中的XML编程接口,它利用了。net语言集成查询(LINQ)框架。LINQ to XML使用最新的。net框架语言功能,可与更新、重新设计的文档对象模型(DOM) XML编程接口相媲美。

有一些有趣的快速相关的例子可以在http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx