C# 中对 DataTable 的 SOAP 响应

发布于 2024-12-01 06:48:10 字数 2464 浏览 1 评论 0原文

我一直在搜索并尝试多种形式,以与 Excel 相同的方式将 XML 响应传递到简单的 DataTable。

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 个表。

我尝试过使用 DataSet.ReadXML,但问题是,由于某种原因,该方法生成 14 个表,其中的数据没有用处,因为根本没有关系。 后来我尝试使用 DataTable.ReadXML 但它给了我一个问题“DataTable 不支持从 Xml 进行架构推断”。然后尝试使用 DataTable.ReadXmlSchema(XML) ,它给出了没有根文档的错误,然后我使用命令提示符创建了一个 XSD,生成的两个给出了错误,最后我使用 Visual Studio 生成了 XSD,它生成了 4 XSD 没有错误,但没有创建列,也没有添加数据。

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

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

乄_柒ぐ汐 2024-12-08 06:48:10

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

http://www.hookedonlinq.com/LINQtoXML5MinuteOverview.ashx

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文