' Collection of code snippets by Arne Vajhøj 
' (from articles on eksperten.dk / vajhoej.dk written sometime between 2004 and now) 
﻿Imports System
Imports System.IO
Imports System.Xml

Namespace XmlProc.XPath
    Public Class Program
        Private Const XML_FILE As String = "C:\work\employees.xml"
        Public Shared Sub Main(args As String())
            ' read from file to DOM tree
            Dim doc As New XmlDocument()
            doc.Load(XML_FILE)
            ' iterate over all employee elements
            For Each employee As XmlElement In doc.SelectNodes("//employee[@no>1 and role!='Intern']")
                ' find attribute no
                Dim no As String = employee.SelectSingleNode("@no").Value
                ' find sub elements name and role
                Dim name As String = employee.SelectSingleNode("name/text()").Value
                Dim role As String = employee.SelectSingleNode("role/text()").Value
                ' print
                Console.WriteLine("no = " & no)
                Console.WriteLine("name = " & name)
                Console.WriteLine("role = " & role)
            Next
        End Sub
    End Class
End Namespace
