Select all Nodes Innertext 任意深度
Select all Nodes Innertext any depth
我有一个问题想了好几个小时。可能我只是想错了……随便吧:
我搜索了多个 XML 文档(递归文件搜索)并加载为 "XmlDocument"
Dim doc As XmlDocument = New XmlDocument()
doc.Load(New StreamReader(File.Open(strFilePathAndName, FileMode.Open), Encoding.GetEncoding("iso-8859-15")))
Dim root As XmlElement = doc.DocumentElement
然后我必须在这个文档中搜索每个子笔记,但不是 "parent"
有点难以解释......举个例子:
<?xml version="1.0"?>
<rootnode>
<node1>Users</node1> '<- Get "Users" from that
<node2>xxxxxx</node2> '<- Get "xxxxxxx" from that
<node3> '<- Don't get that
<node4> '<- Don't get that
<nodeX>xxxxxx</nodeX> '<- Get xxxxx that
<node5> '<- Don't get that
<bla>335</bla> '<- Get 335 fromthat
<bla2>3353</bla2> '<- Get 3353 from that
</node5>
<node4>
</rootnode>
原版有点大...
我尝试将它们保存在 NodeList 中:
nodeList = root.SelectNodes("descendant::*")
然后将所有找到的项目保存到一个字符串中,以“;”分隔:
For Each node As XmlNode In nodeList
ergstring = ergstring & """" & node.InnerText & """" & ";"
Next
使用 nodeList = root.SelectNodes("descendant::*[not(*)]")
到 select 所有没有子元素的元素。
我有一个问题想了好几个小时。可能我只是想错了……随便吧:
我搜索了多个 XML 文档(递归文件搜索)并加载为 "XmlDocument"
Dim doc As XmlDocument = New XmlDocument()
doc.Load(New StreamReader(File.Open(strFilePathAndName, FileMode.Open), Encoding.GetEncoding("iso-8859-15")))
Dim root As XmlElement = doc.DocumentElement
然后我必须在这个文档中搜索每个子笔记,但不是 "parent" 有点难以解释......举个例子:
<?xml version="1.0"?>
<rootnode>
<node1>Users</node1> '<- Get "Users" from that
<node2>xxxxxx</node2> '<- Get "xxxxxxx" from that
<node3> '<- Don't get that
<node4> '<- Don't get that
<nodeX>xxxxxx</nodeX> '<- Get xxxxx that
<node5> '<- Don't get that
<bla>335</bla> '<- Get 335 fromthat
<bla2>3353</bla2> '<- Get 3353 from that
</node5>
<node4>
</rootnode>
原版有点大...
我尝试将它们保存在 NodeList 中:
nodeList = root.SelectNodes("descendant::*")
然后将所有找到的项目保存到一个字符串中,以“;”分隔:
For Each node As XmlNode In nodeList
ergstring = ergstring & """" & node.InnerText & """" & ";"
Next
使用 nodeList = root.SelectNodes("descendant::*[not(*)]")
到 select 所有没有子元素的元素。