我有测试的xml文件,看起来像这样:如何忽略xml命名空间?
<Person>
<ContactInfo>
...
<ContactInfo>
</Person>
当我尝试反序列化,一切工作正常。 但问题是,有时这个XML文件的结构是不同的 - 有时会添加XML名称空间。
<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)有错误”。内部异常消息表明<Person xmlns='http://tempuri.org/PaymentInformationXml.xsd'>
不是预期的。
那么有人能帮助我吗?
你用什么来反序列化? –
您的示例XML和错误消息不一致; xsi/xsd只是名称空间别名 - 它们不会更改任何内容。你可以非常忽略这两个。然而,'xmlns ='... blah ...''非常重要。请澄清:这是否在您的XML或不?如果是,则必须提前告知XmlSerializer –