Home > DeveloperSection > Forums > Read all nodes and elements in XML (VB.net)
Andrew Deniel
Andrew Deniel

Total Post:29

Points:203
Posted on    June-11-2013 8:33 AM

 VB.Net VB.Net 
Ratings:


 1 Reply(s)
 4651  View(s)
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. 


AVADHESH PATEL

Total Post:604

Points:4228
Posted on    June-12-2013 7:26 AM

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. 

Don't want to miss updates? Please click the below button!

Follow MindStick