【问题标题】:Serialize different XML with equal node count and type, but different node names序列化具有相同节点数和类型但节点名称不同的不同 XML
【发布时间】:2013-06-19 11:14:33
【问题描述】:

如果 XML 具有相同数量的具有相同值类型的节点,是否有任何方法可以将一个类用于 2 个或多个 XML 文件序列化?

例如

<root>
   <element1> string </element1>
   <element2> int </element2>
<root>

<root>
   <otherElement> string <otherElement>
   <otherElement2> int </otherElement2>
</root>

我想像下面的类对象一样序列化它们:

public class root
{
   public string stringElement {get; set;}
   public string intElement {get; set;}
}

我可以使用 Linq to XML,使 XML 与类匹配,但我正在努力寻找轻松的解决方案。有没有类似 [XmlElement("element1") or ("otherElement")] 的东西? 希望您能理解我要问的问题,并提前致谢!

【问题讨论】:

    标签: c# xml xml-serialization


    【解决方案1】:

    希望对你有用

    http://msdn.microsoft.com/en-us/library/aa335724.aspx

    您可以使用您需要的名称创建特殊的 XmlSerializer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-08
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多