<person id="1">
<name>Gaby</name>
<age>12</age>
<address>GuangZhou</address>
</person>
<person id="2">
<name>Bill</name>
<age>33</age>
<address>USA</address>
</person>
<person id="3">
<name>BiLy</name>
<age>19</age>
<address>HuNan</address>
</person>
如果要创建如上的XML树:
代码示例:
XElement xmlTree = new XElement("Root",
new XElement("person", new XElement("name", "Gaby"),
new XElement("age",18),
new XElement("address","GuangZhou")),
new XElement("person", new XElement("name", "Lily"),
new XElement("age",20),
new XElement("address","USA")),
new XElement("person", new XElement("name", "Bill"),
new XElement("age",55),
new XElement("address","English"))
);
foreach (var item in xmlTree.Elements())
{
Console.WriteLine(item);
}
输出结果: