将新节点添加到现有XmlDocument对象

我有一个以下格式的xml。

  book 1 author 1 10.90 1985   book 2 author 2 20.90 1995   

我有一个Add(XmlDocument xDoc, Book newBook)方法将新书添加到传递给Add(..)方法的XmlDocument对象。 我怎样才能做到这一点。

 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"); 

请参阅Martin Honnen发表于: 在现有XML文档中添加新节点