我想閱讀我的XML的特定節點,但我在如何關注問題方面遇到問題。使用隨機Id節點獲取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
@chateaur這是一個測試,看看我是否可以訪問。我需要全部。 –
smtdev