如何忽略XML命名空间? [英] how to ignore xml namespaces?
本文介绍了如何忽略XML命名空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有看起来像这样的测试XML文件:
I've got test xml file that looks like this:
<Person>
<ContactInfo>
...
<ContactInfo>
</Person>
当我试图反序列化,一切工作正常。 但问题是,有时这个XML文件的结构是不同的 - XML命名空间,有时添加
When I'm trying to deserialize, everything works fine. But the problem is that sometimes the structure of this xml file is different - xml namespaces are added sometimes.
<Person xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<ContactInfo>
...
<ContactInfo>
</Person>
而现在当我序列化,我得到IOnvalidOperationException:有一个在XML文档中的错误(1,2)。内部异常消息称&LT;人的xmlns =HTTP://tempuri.org/PaymentInformationXml.xsd'>
是没有预料到
所以,任何人都可以帮助我?
So could anyone help me with this?
推荐答案
一个命名空间是基本的XML(不同于命名空间,这是可以互换)。如果人在该命名空间,你必须告诉它:
A namespace is fundamental in XML (unlike namespaces which are interchangeable). If Person is in that namespace, you must tell it:
[XmlRoot(Namespace="http://tempuri.org/PaymentInformationXml.xsd")]
public class Person {...}
这篇关于如何忽略XML命名空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文