【问题标题】:Provide path to XmlElement when Deserialize C#反序列化 C# 时提供 XmlElement 的路径
【发布时间】:2014-04-09 21:59:51
【问题描述】:

我有一个这样的xml

  <order>
    <id>1</id>
    <location>
      <city>
       Test
      </city>
      <state>
      </state>
    </location>
  </order>

还有这样的订单类:

[XmlRoot(ElementName = "ordertransaction") ]
    class Order{
     [XmlElement("id")]
     public String id {get;set;}
     [XmlElement("location/city")]
     public String city {get;set;}
    }

是否可以在反序列化时访问“城市”标签而无需创建位置类?

【问题讨论】:

    标签: .net xml serialization


    【解决方案1】:

    这是不可能的。该类必须具有与 xml 相同的结构。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-10
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 2019-07-20
      相关资源
      最近更新 更多