XPathNavigator.AppendChildElement Creates a child element node at the end of the list
using System;
using System.Linq;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass
{
public static void Main()
{
XmlDocument document = new XmlDocument();
document.Load("domainBooks.xml");
XPathNavigator navigator = document.CreateNavigator();
navigator.MoveToChild("bookstore", "http://www.domain.com/books");
navigator.MoveToChild("book", "http://www.domain.com/books");
navigator.AppendChildElement(navigator.Prefix, "pages", navigator.LookupNamespace(navigator.Prefix), "100");
Console.WriteLine(navigator.OuterXml);
}
}
/*
<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.domain.com/books">
<book genre="Programming" publicationdate="2010-03-22" ISBN="1-111111-11-0">
<title>C#</title>
<author>
<first-name>A</first-name>
<last-name>B</last-name>
</author>
<price>8.99</price>
</book>
<book genre="data" publicationdate="2010-11-17" ISBN="0-201-11111-2">
<title>XML</title>
<author>
<first-name>D</first-name>
<last-name>E</last-name>
</author>
<price>11.99</price>
</book>
</bookstore>
*/
Related examples in the same category