【发布时间】:2017-06-30 21:33:54
【问题描述】:
目前我正在尝试解析 xml。当我用作容器时,所有信息都正确返回。当我使用程序时不返回任何信息
所以当我尝试使用这种 XML 格式列出节点时,一切正常;
<feed>
<entry>
<childnode1>blue</childnode1>
<childnode2>red</childnode2>
<childnode3>green</childnode3>
<childnode4>yellow</childnode4>
</entry>
</feed>
但我需要它以这种格式工作; (这目前不起作用)
<feed xmlns='x' xmlns:openSearch='y' xmlns:gsx='z'>
<entry>
<childnode1>blue</childnode1>
<childnode2>red</childnode2>
<childnode3>green</childnode3>
<childnode4>yellow</childnode4>
</entry>
</feed>
所以在我给出的第一个 XML 示例中,这个程序运行良好;
Imports System.IO
Imports System.Xml
Module ParsingUsingXmlDocument
Sub Main()
Dim document As XmlDocument
Dim nodelist As XmlNodeList
Dim node As XmlNode
document = New XmlDocument()
document.Load("C:\Users\Joe\Documents\family.xml")
nodelist = document.SelectNodes("/feed/entry")
For Each node In nodelist
Dim stockinfo = node.ChildNodes.Item(4).InnerText
Console.WriteLine("Info: " & stockinfo)
Console.Write(vbCrLf)
Next
Console.ReadLine()
End Sub
End Module
但是当我使用我展示的第二种 xml 格式时,其中有属性,没有任何作用。我的程序完全是空白的。
谁能建议我需要做些什么来解决这个问题?
谢谢
【问题讨论】:
-
deserialize XML 不是更容易吗?
标签: xml vb.net parsing attributes element