简体   繁体   中英

VB.net - Getting Data from an XML File

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM