我有一个测试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'>
是不被预期的。
是否有人可以帮助我解决这个问题呢?
xmlns ='... blah ...'
非常重要。请澄清:这是否在您的XML中?如果是,则必须提前告诉XmlSerializer。 - Marc Gravell