我需要通过以下任何一种方式读取/写入xml元素。
<element param="..." set="...">
</element>
<element>
<param>...</param>
<set>...</set>
</element>
<element param="...">
<set>...</set>
</element>
<element set="...">
<param>...</param>
</element>
是否可以使用这种形式的课程来做这项工作?
[XmlType("element")]
public class Element
{
[XmlAttribute, XmlElement]
public string param { get; set; }
[XmlAttribute, XmlElement]
public string set { get; set; }
}
答案 0 :(得分:1)
您是否正在寻找一个XML类,该类可以具有与此名称相同的Element和Attribute?
[XmlRootAttribute(ElementName = "element")]
public class ElementRoot
{
[XmlAttribute("param")]
public string paramAtribute;
[XmlElement("param")]
public string paramElement;
[XmlAttribute("set")]
public string setAtribute;
[XmlElement("set")]
public string setElement;
}
XML:
<?xml version="1.0" encoding="UTF-8"?>
<element xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" param="..." set="...">
<param>...</param>
<set>...</set>
</element>