假设我有这个XML文件:
<weather>
<temp>24.0</temp>
<current-condition iconUrl="http://....">Sunny</current-condition>
</weather>
我试图使用属性(Attribute)创建一个C#类来表示这个内容,以便调用XmlSerializer并具有强类型标签访问。 我认为结构将类似于:
[XmlRoot("weather")]
public class WeatherData
{
[XmlElement("temp")]
public string Temp { get; set; }
[XmlElement("current-condition")]
public CurrentCondition currentCond = new CurrentCondition();
}
public class CurrentCondition
{
[XmlAttribute("iconUrl")
public string IconUrl { get; set; }
// Representation of Inner Text?
}
处理'temp'标签很简单。然而,如果有一个像current-condition这样既有内部文本又有属性的标签,如何表示内部文本呢?
我可能过于复杂化了这个问题,因此请随意提出其他建议。