bookstore.xml:
- XML code
<?xml version="1.0" encoding="utf-8"?> <bookstore> <book genre="fantasy" ISBN="2-3631-4" old="29"> <title>Oberon's Legacy</title> <author>Corets, Eva</author> <price>5.95</price> </book> <applenote genre="fantasy" ISBN="2-3631-4"> <title>Oberon's Legacy</title> <author>Corets, Eva</author> <price>5.95</price> </applenote> <book genre="fantasy" ISBN="2-3631-6"> <title>Oberon's Legacy</title> <author>Corets, Eva</author> <price>5.96</price> </book> <book genre="fantasy" ISBN="2-3631-6"> <title>Oberon's Legacy</title> <author>Corets, Eva</author> <price>5.97</price> </book> </bookstore>
c#文件中:
- C# code
XmlElement xe1 = xmlDoc.CreateElement(childNodeName);//创建一个节点 parentNode.AppendChild(xe1);//添加到父节点节点中 for (int i = 0; i < tmpXe.Count; i++) { xe1.AppendChild(tmpXe.Item(i));//将临时节点添加到新元素中 xmlDoc.Save(xmlFile); }
只能添加Item(0)和Item(2)的值,缺没有添加到 Item(1)的值,请教为何会这样。
------解决方案--------------------
for (int i = tmpXe.Count-1; i>-1; i--)
试试