忽略XML反序列化中的名称空间

时间:2019-08-08 08:11:08

标签: c# xml

我想将XML反序列化为对象。我无法控制要接收的xml,以及要反序列化的对象。

我尝试了这个操作:Can I make XmlSerializer ignore the namespace on deserialization?,它几​​乎可以正常工作。

我的xml

    <request xmlns:a="http://schemas.datacontract.org/2004/07/My.Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://tempuri.org/">
      <a:ProfileInfo i:type="a:ProfileAndBSymbol">
        <a:BSymbol>_47</a:BSymbol>
        <a:ProfileSymbol>FAJNY</a:ProfileSymbol>
      </a:ProfileInfo>
    </request>

a:ProfileInfo可以正常工作,但是i:type引发了异常。如何忽略i:

例外是波兰语,它是这样的:

  

InvalidOperationException:类型无效。名称= ProfileAndBSymbol,   namespace = http://schemas.datacontract.org/2004/07/My.Contracts

0 个答案:

没有答案