【问题标题】:Use multiple root namespaces when deserializing with .NET XmlSerializer使用 .NET XmlSerializer 反序列化时使用多个根命名空间
【发布时间】:2015-05-21 14:00:26
【问题描述】:

我的问题很像one。但是,我需要在同一个根目录上允许两个不同的命名空间。

类似:

    [XmlType(Namespace = "")]
[XmlRoot("included_parameters", Namespace = "http://apif.freescale.net/schemas/paramdef/1.0")]
[XmlRoot("included_parameters", Namespace = "http://apif.freescale.net/schemas/paramdef/1.1")]
public class IncludedParameters
{
}

所以基本上,我想将 1.0 版架构或 1.1 版架构的 xml 文件反序列化为同一个 .net 类。

如果您需要更多详细信息,请告诉我。

克里斯

【问题讨论】:

  • 不包含命名空间:[XmlRoot("included_pa​​rameters")]
  • @jdweng - 如果我删除命名空间属性,反序列化会抛出一个异常,说 不是预期的。

标签: .net xml serialization


【解决方案1】:

有一个SerializationBinder 类可以进行这种类型转换操作。

https://msdn.microsoft.com/en-us/library/system.runtime.serialization.serializationbinder%28v=vs.110%29.aspx

"Some users need to control which class to load, either because the class has moved between assemblies or a different version of the class is required on the server and client"

【讨论】:

    猜你喜欢
    • 2015-06-30
    • 1970-01-01
    • 1970-01-01
    • 2012-01-04
    • 1970-01-01
    • 1970-01-01
    • 2011-12-09
    • 1970-01-01
    相关资源
    最近更新 更多