我一直在搜索并尝试以多种形式将 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 个表。
我曾尝试使用 DataSet.ReadXML,但它的问题是由于某种原因,该方法生成了 14 个表,其中的数据没有用,因为根本没有关系。后来我尝试使用 DataTable.ReadXML,但它给了我“DataTable 不支持来自 Xml 的模式推断”的问题。然后尝试使用 DataTable.ReadXmlSchema(XML) 并且它给出了一个没有根文档的错误,然后我使用命令提示符创建了一个 XSD 并且两个生成的都给出了错误,最后我使用 Visual Studio 生成了 XSD,它生成了 4 XSD 没有错误,但没有创建列,也没有添加任何数据。
我现在没有主意了。有什么建议么?也许不是没有标准化数据的 DataTable(Excel 所做的),而是另一种直接使用 XML 的方法?
谢谢你。