Evaluates an XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver. : XPath « XML LINQ « VB.Net






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

1.Loop through the query results and display the information to the screen.
2.Use XPath to get the tasks for each employee.
3.Selecting node by XPath
4.Selects a collection of elements using an XPath expression.
5.XPathExpression Class provides a typed class that represents a compiled XPath expression.
6.Selects a collection of elements using an XPath expression.