我有一个以下格式的 xml。
<BOOKS>
<BOOK>
<TITLE>book 1</TITLE>
<AUTHOR>author 1</AUTHOR>
<PRICE>10.90</PRICE>
<YEAR>1985</YEAR>
</BOOK>
<BOOK>
<TITLE>book 2</TITLE>
<AUTHOR>author 2</AUTHOR>
<PRICE>20.90</PRICE>
<YEAR>1995</YEAR>
</BOOK>
</BOOKS>
我有一个Add(XmlDocument xDoc, Book newBook)
添加新书的方法XmlDocument
传递给的对象Add(..)
方法。我怎样才能做到这一点。
XmlDocument doc = new XmlDocument();
doc.Load("file.xml");
XmlElement foo = doc.CreateElement("foo");
XmlElement bar = doc.CreateElement("bar");
bar.InnerText = "whatever";
foo.AppendChild(bar);
doc.DocumentElement.AppendChild(foo);
doc.Save("file.xml");
see 马丁·霍南发表于:向现有 XML 文档添加新节点
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)