READ ALL NODES AND ELEMENTS IN XML (VB.NET)

Andrew Deniel

Total Post:29

Points:203
Posted by  Andrew Deniel
VB.Net 
 7205  View(s)
Ratings:
Rate this:
Hi Expert,

I'm trying to read an xml file, there is no problem to doing this

But, in this case I will not know anything about this xml file, I just want to read everything, including all child nodes and get the name and value from each node.

This code gives me only the name of the first node and skips all children:

Dim xml As New XmlDocument
xml.Load(myxml.xml)
For Each node As XmlNode In xml.DocumentElement.SelectNodes("*")
    MsgBox(node.Name)
Next

Since i don't know dept or anything, i don't know how I will do this. And every solution I find is based by knowing element names.

Thanks in advance. 
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Read all nodes and elements in XML (VB.net)

    Hi Andrew,


    You can try as following

    Dim xml As New Xml.XmlTextReader(sFilePath)

    While xml.Read
        If xml.NodeType = Xml.XmlNodeType.Element Then 
            MessageBox.Show(xml.Name)      
        End If
    End While

    I hope it resolve your problem. 

  1. rahul kumar

    Post:1

    Points:7
    Re: Read all nodes and elements in XML (VB.net)

    Hope this will help you....

    http://vb.net-informations.com/xml/open-xml-vb.net.htm

    Patter

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!