简体   繁体   中英

Read all nodes and elements in XML (VB.net)

I'm trying to read an xml file, and that's usually no problems.

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.

Another option:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM