XPathNavigator.DeleteRange deletes a range of sibling nodes
Imports System
Imports System.Xml
Imports System.Xml.XPath
Public Class MainClass
Public Shared Sub Main()
Dim document As XmlDocument = New XmlDocument()
document.Load("domainBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()
Dim manager As XmlNamespaceManager = New XmlNamespaceManager(document.NameTable)
manager.AddNamespace("bk", "http://www.domain.com/books")
Dim first As XPathNavigator = navigator.SelectSingleNode("/bk:bookstore/bk:book[1]", manager)
Dim last As XPathNavigator = navigator.SelectSingleNode("/bk:bookstore/bk:book[2]", manager)
navigator.MoveTo(first)
navigator.DeleteRange(last)
Console.WriteLine(navigator.OuterXml)
End Sub
End Class
Related examples in the same category