Selects an XElement using a XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.
Imports System
Imports System.Xml.Linq
Imports System.Linq
Imports System.Xml.XPath
Imports System.Xml
Public Class MainClass
Public Shared Sub Main()
Dim markup As XElement = _
<Root xmlns:aw='http://www.domain.com'>
<Child1>child one data</Child1>
<Child2>child two data</Child2>
</Root>
Dim reader As XmlReader = markup.CreateReader
Dim nameTable As XmlNameTable = reader.NameTable
Dim namespaceManager As XmlNamespaceManager = New XmlNamespaceManager(nameTable)
namespaceManager.AddNamespace("aw", "http://www.domain.com")
Dim child1 As XElement = markup.XPathSelectElement("./my:Child1", namespaceManager)
Console.WriteLine(child1)
End Sub
End Class
Related examples in the same category