Evaluates an 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
Imports System.Collections
Imports System.Collections.Generic
Public Class MainClass
Public Shared Sub Main()
Dim markup As XElement = _
<Root xmlns:aw='http://www.domain.com'>
<Child1 Att='attdata'>child one data 1</Child1>
</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 atts As IEnumerable = CType(markup.XPathEvaluate("./my:Child1/@my:Att", namespaceManager), IEnumerable)
Dim attList As IEnumerable(Of XAttribute) = atts.Cast(Of XAttribute)()
Dim att As XAttribute = attList.First()
Console.WriteLine(att)
End Sub
End Class
Related examples in the same category