XPathNavigator.DeleteRange deletes a range of sibling nodes
using System;
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();
XmlNamespaceManager manager = new XmlNamespaceManager(document.NameTable);
manager.AddNamespace("bk", "http://www.domain.com/books");
XPathNavigator first = navigator.SelectSingleNode("/bk:bookstore/bk:book[1]", manager);
XPathNavigator last = navigator.SelectSingleNode("/bk:bookstore/bk:book[2]", manager);
navigator.MoveTo(first);
navigator.DeleteRange(last);
Console.WriteLine(navigator.OuterXml);
}
}
Related examples in the same category