解析这个xml的最佳方式是什么???
<?xml version="1.0" encoding="UTF-8"?>
<DOCWARE Version="1.1">
<Order Count="2">
<Pos0>
<M_TEXTNR>sAuspuffendrohr</M_TEXTNR>
<VM_BESTNR>s02010000373</VM_BESTNR>
<P_PREIS>s715.80</P_PREIS>
</Pos0>
<Pos1>
<M_TEXTNR>sMutter</M_TEXTNR>
<VM_BESTNR>s02010000373</VM_BESTNR>
<P_PREIS>s0.70</P_PREIS>
</Pos1>
</Order>
<TotalSum>s</TotalSum>
</DOCWARE>
我试着这样做,但不起作用,然后I=1
Dim xmldoc As New XmlDataDocument()
Dim xmlnode As XmlNodeList
Dim fs As New FileStream(myFileName, FileMode.Open, FileAccess.Read)
xmldoc.Load(fs)
For i As Integer = 0 To 1
xmlnode = xmldoc.GetElementsByTagName("Pos" & i)
dim val as string = xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
MsgBox(val)
Next
提前感谢
要读取名称已更改的标记,可以使用xmlReader并查找文档。名称包含此前缀"Pos",请尝试使用此代码:
Dim document As XmlReader = New XmlTextReader(fileName)
While (document.Read())
Dim type = document.NodeType
If (type = XmlNodeType.Element) Then
If (document.Name.Contains("Pos")) Then
Dim test As String = document.ReadInnerXml.ToString()
Dim doc As New XmlDocument()
doc.LoadXml("<Pos>" & test & "</Pos>")
Dim root As XmlNode = doc.FirstChild
If root.HasChildNodes Then
dim _value = root.ChildNodes.Item(0).InnerText.Trim()
End If
End If
End If
End While