【发布时间】:2017-03-22 12:56:48
【问题描述】:
我想读取我的 XML 的特定节点,但我在如何集中问题上遇到问题。
目前 XML 文件具有以下结构:
<?xml version="1.0" encoding="utf-8"?>
<Assessment xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www1.macadam.eu/Webservices/FleetCarV3/">
<Damages>
<Damage>
<Id>15724669</Id>
<AssessmentId>1959065</AssessmentId>
<Location>
<Id>5</Id>
<DescriptionEN>Panel R R</DescriptionEN>
<DescriptionNL>Panneel A R</DescriptionNL>
<DescriptionFR>Panneau ARD</DescriptionFR>
<DescriptionDE>Panel HR</DescriptionDE>
<DescriptionES>Panel TRAS DR</DescriptionES>
</Location>
<Type>
<Id>1274</Id>
<DescriptionEN>Bump(s)</DescriptionEN>
<DescriptionNL>Deuk(en)</DescriptionNL>
<DescriptionFR>Bosse(s)</DescriptionFR>
<DescriptionDE>Dell(en)</DescriptionDE>
<DescriptionES>Abolladuras</DescriptionES>
</Type>
<Repair>
<Id>1307</Id>
<DescriptionEN>Le - Replace and paint</DescriptionEN>
<DescriptionNL>Le - Vervangen en spuiten</DescriptionNL>
<DescriptionFR>Le - Remplacer et peindre</DescriptionFR>
<DescriptionDE>Erneuern + lackieren</DescriptionDE>
<DescriptionES>Le - Reemplazar Y Pintar</DescriptionES>
</Repair>
<Comment />
</Damage>
<Damage>
...
...
</Damage>
<Damage>
...
...
</Damage>
</Damages>
</Assessment>
请注意,我放置了更多<Damage> 标签。每个<Id> 每个<Damage> 节点都不同,我需要的是<DescriptionES> 节点内的文本。
以下是尝试获取<Location> 节点的代码:
nsmgr = New XmlNamespaceManager(m_xmld.NameTable)
nsmgr.AddNamespace("sd", "http://www1.macadam.eu/Webservices/FleetCarV3/")
m_nodelist = m_xmld.DocumentElement.SelectNodes("/sd:Assessment/sd:Damages/sd:Damage/sd:Location", nsmgr)
For Each m_node In m_nodelist
For j = 0 To 5000
Dim Location = m_node.SelectSingleNode("/sd:Assessment/sd:Damages/sd:Damage/sd:Location[sd:Id=" & j & "]", nsmgr).InnerText
If Location IsNot Nothing Then
MsgBox("i'm in")
'txtDamageReport.Text = Location
End If
Next j
Next
正如预期的那样,它不起作用。我不知道如何继续。
【问题讨论】:
-
您的代码似乎没有针对特定节点。你想得到所有伤害的所有位置吗?
-
@chateaur 这是一个测试,看看我是否可以访问
。我需要所有的 。
标签: xml vb.net xml-parsing