Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

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
0
broadbent
Asked:
broadbent
  • 2
1 Solution
 
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
 
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
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now