Reputation: 395
I am trying to write a small program to get some data from an XML file which is already being used by another application (NOT MY OWN).
The XML Looks like this ...
?xml version="1.0" encoding="utf-8"?
sunjournal
rvcmappings default="MISSING"
rvcmap unitId="2" rvcnum="443" /
rvcmap unitId="3" rvcnum="103" /
rvcmap unitId="5" rvcnum="701" /
/rvcmappings
/sunjournal
I am trying to use the below Code in VB to get the "rvcnum" for the UnitId of 5.
Dim doc As XmlDocument = New XmlDocument()
doc.Load("C:\BootDrv\Aloha\RptExport\GLMapping_Master.xml")
Dim acc As String = doc.SelectSingleNode("sunjournal/rvcmappings/rvcmap[UNitId='5']/rvcnum").InnerText
msgbox(acc)
Can anyway point me in the right direction as I do not receive any Errors in Runtime just doesn't show the any Msgbox Data??
Many Thanks Rob
Upvotes: 0
Views: 131
Reputation: 1045
I believe the syntax you are looking for is:
node = doc.SelectSingleNode("//sunjournal//rvcmappings//rvcmap[@unitId='5']")
This will get you the element. From there you can access the attribute:
node.Attributes("rvcnum").Value
Use these docs for some more examples as you work through your program.
Upvotes: 1