我必須從一個工具中消費xml。在xml中,有這樣的部分:
<profile>/span>
< details environment="sd98qlx" severity="critical">
< detail unit="sec" value="12"/>
< detail unit="sec" value="25"/>
< detail unit="msec" value="950"/>/span>
</details>/span>
</profile>/span>
對于用C#中的XMLSerializer反序列化上述內容,我應該如何在我的模型類上使用屬性來實作?問題在于陣列與屬性的組合。
uj5u.com熱心網友回復:
使用樣本模型類的方向
[XmlRoot(ElementName = "detail")/span>]
public class Detail
{
[XmlAttribute(AttributeName = "unit")]
public string Unit { get; set; }
[XmlAttribute(AttributeName = "value")/span>]
public intValue { get; set; }
}
[XmlRoot(ElementName = "details")]
public class Details
{
[XmlElement(ElementName = "detail")]
public List<Detail> Detail { get; set; }
[XmlAttribute(AttributeName = "environment")]
public string Environment { get; set; }
[XmlAttribute(AttributeName = "severity")]
public string Severity { get; set; }
}
[XmlRoot(ElementName = "file")]
public class Profile
{
[XmlElement(ElementName = "details")]
public Details Details { get; set; }
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/324045.html
標籤:
