[英]Read all nodes and elements in XML (VB.net)
I'm trying to read an xml file, and that's usually no problems. 我正在尝试读取xml文件,通常没有问题。
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. 但是,在这种情况下,我对这个xml文件一无所知,我只想读取所有内容,包括所有子节点,并从每个节点获取名称和值。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.