Parsing XML in VB.Net

I'm attempting to parse an XML document (see attachment) in VB.Net.  Unfortunately, I'm having trouble identifying the nodes for which I'd like to parse elements.  Here's my current code:

        Dim xmlDoc As New XmlDocument
        Dim nodes As XmlNodeList = xmlDoc.DocumentElement.SelectNodes("/Employees/Employee")
        Dim strField1 As String = "", strField2 As String = "", strField3 As String = ""
        For Each node As XmlNode In nodes
            strField1 = node.SelectSingleNode("FirstName").InnerText
            strField2 = node.SelectSingleNode("LastName").InnerText
            strField3 = node.SelectSingleNode("Address").InnerText


Open in new window

However, the code within the 'For Each' was bypassed.  I also tried "/EmployeeResponse/Employees/Employee") to SelectNodes, but got the same result.

Any help is greatly appreciated.XMLSample.xml
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi DaneBigham;

I am really bad using the older XML technology, XmlDocument, but well versed using Linq to XML. The following is a code snippet that should do what you need using Linq.
'' Load the XML document from the file system
Dim xdoc As XDocument = XDocument.Load("C:\temp\XMLSample.xml")
'' Get a reference to the XML Namespace used to access the nodes
Dim ns As XNamespace = xdoc.Root.Name.NamespaceName

'' Query for the Employee info and return them as an Anonymous type
Dim results = (From node In xdoc.Root.Descendants(ns + "Employee")
               Select New With
                   .FirstName = node.Element(ns + "FirstName").Value,
                   .LastName = node.Element(ns + "LastName").Value,
                   .Address = node.Element(ns + "Address").Value & ", " & node.Element(ns + "City").Value

'' Process the returned info as needed
For Each employee In results
    Console.WriteLine("Name : {0} {1}; Address : {2}", employee.FirstName, employee.LastName, employee.Address)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando SotoRetiredCommented:
@DaneBigham, did my post answered your question?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.