XML to DataSet - 嵌套表/多个命名空间错误 [英] XML to DataSet - Nested table/Multiple namespace Error

查看:116
本文介绍了XML to DataSet - 嵌套表/多个命名空间错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试使用DataSet.ReadXML()方法将XML加载到数据集中。


遇到以下内容错误 -


 



System.InvalidOperationException:嵌套表‘地址’继承其命名空间不能在不同的命名空间中拥有多个父表



从第三方检索XML,这些是一些值得注意的要点:


1)"地址"类型作为儿童元素存在于各种级别,如电子邮件,联系等。虽然这些子元素中的一些是简单类型和有"type = string" ,其他人指的是"type = nis:Address"。其中nis:地址由(如下所示)
-


< element name =" 地址 ">


< complextype>


< sequence>


< element name =" AddressTypeCode"类型= QUOT; NIS:AddressTypeCodeType" />


< element name =" 地址 "类型= QUOT;串QUOT; />


< element name =" IsPreferred"类型= QUOT; NIS:布尔" />


< / sequence>


< attribute use =" required" REF =" NIS:referenceNumber" />


< / complextype>


< / element>


 


2)第三方表示他们正在单个命名空间下生成XML,并且它在PHP解析器上工作正常。我正在使用C#。


3)我尝试过XmlReadMode.IgnoreSchema,虽然没有看到错误,但是retreived的数据集是空的。



我有什么建议可以解决这个问题吗?



最佳。

解决方案

当DataSet加载XML时,它会将其加载到表和列的关系结构中。  执行以XML为中心的处理时,您可能会发现更好的服务于XDocument比DataSet(但如果你使用
DataSet的数据绑定则不行)。 在XDocument(或较旧的XmlDocument)是更好的选择的情况下,DataSet类经常被过度使用。 应该将DataSet视为具有XML互操作性的关系结构。


(这与几分钟前我的回复几乎相同,是一个无关的问题。 这是因为同样的建议适用。)


> 第三方表示他们正在单个命名空间下生成XML,并且它在PHP解析器上工作正常。我正在使用C#。


他们没有使用像DataSet这样的东西:)


你可能能够让它工作,实际上,通过修改XML Schema。 我不确定你是否发布了足够的模式来解决这个问题(你能提供一个完整的XML Schema来重现错误吗?) 在任何情况下,请考虑XDocument
或XmlDocument是否足以满足您的需求。


 


 


Hi,

I am trying to load XML into a Dataset using DataSet.ReadXML( ) method.

Encountering the below error -

 

System.InvalidOperationException: Nested table ‘Address’ which inherits its namespace cannot have multiple parent tables in different namespaces

XML is retrieved from a third party and these are a few notable points :

1 ) The "Address" type is present as child elements at various levels like Email, contact etc. While some of these child elements are of simple type & have "type=string" , the others refer to a "type=nis:Address" where nis:address is given by (as below) -

<element name="Address">

<complextype>

<sequence>

<element name="AddressTypeCode" type="nis:AddressTypeCodeType" />

<element name="Address" type="string" />

<element name="IsPreferred" type="nis:Boolean" />

</sequence>

<attribute use="required" ref="nis:referenceNumber" />

</complextype>

</element>

 

2) The third party says they are generating the XML under a single namespace and it works fine on a PHP parser. I am using C#.

3) I have tried the XmlReadMode.IgnoreSchema , though the error is not seen then , the dataset retreived is empty.

Any suggestion how I can work this around?

Best.,

解决方案

When DataSet loads XML, it loads it into a relational structure of tables and columns.  When performing XML-centric processing, you might find that you are better served by XDocument than DataSet (but not if you are using data binding for the DataSet).  The DataSet class is often overused in situations where XDocument (or the older XmlDocument) would be a better choice.  DataSet should be viewed as a relational structure with XML interoperability.

(This is almost the same as my response a couple minutes ago to an unrelated question.  This is because the same advice applies.)

>  The third party says they are generating the XML under a single namespace and it works fine on a PHP parser. I am using C#.

They aren't using anything like a DataSet :)

You might be able to get this to work, actually, by modifying the XML Schema.  I'm not sure you've posted enough of the schema to figure this out (can you provide a complete XML Schema that reproduces the error?)  In any case, consider if XDocument or XmlDocument is sufficient for your needs first.

 

 


这篇关于XML to DataSet - 嵌套表/多个命名空间错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆