XPathNavigator.InsertAfter creates node after the selected node
using System;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml.XPath;
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.MoveToChild("price", "http://www.domain.com/books");
XmlDocument childNodes = new XmlDocument();
childNodes.Load(new StringReader("<pages xmlns=\"http://www.domain.com/books\">100</pages>"));
XPathNavigator childNodesNavigator = childNodes.CreateNavigator();
navigator.InsertAfter(childNodesNavigator);
navigator.MoveToParent();
Console.WriteLine(navigator.OuterXml);
}
}
Related examples in the same category