Reading XML

I don't know about everyone else, but I find the Help file in Visual Studio less than helpful, and no matter how I experiment, I can't find a way of reading an xml file through the VB Namespace xml.

I really wish to parse the file to return the value of some attribute or other -

- <Block name="fred">
     <Handle>1234</Handle>
     - <Attribute>
          <Handle>2345</Handle>
           <Tag>George</Tag>
           <Value>likes to drink</Value>
         </Attribute>

etc.

How do "I return likes to drink" given "George"

as an example

Thanks
LVL 4
broadbentAsked:
Who is Participating?
 
lengreenCommented:
broadbent,

Dim myDocument As New XmlDocument()
        myDocument.LoadXml("<?xml version=""1.0"" encoding=""ISO-8859-1""?><Block name=""fred""><Handle>1234</Handle><Attribute><Handle>2345</Handle><Tag>George</Tag><Value>likes to drink</Value></Attribute></Block>")
        MsgBox(myDocument.SelectSingleNode("/Block/Attribute[Tag='George']").SelectSingleNode("Value").InnerText)
0
 
iboutchkineCommented:
convert XML file to datset and then read dataset. It is the easiest way

ds.readXml("file.xml")
0
 
lengreenCommented:
Hi broadbent,

you need to learn xpath, for a good tutorial try http://www.w3schools.com/xpath/default.asp

as for your question

wait a mo


Cheers!
0
 
broadbentAuthor Commented:
Actually, I've said to hell with xml.
Instead I read the whole file into a string, and then parse it myself. I am sure its much simpler and quicker.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.