Solved

Parse XML in VB .NET 2003 <result id="example">

Posted on 2009-07-02
5
500 Views
Last Modified: 2013-11-07
The function in the attached code works great if I have an xml as shown on the top. However, I do not know how to read the bottom xml. Anyone want to help me out on this?
<xml>
  <area>
    <test>
      <result> Example </result>
    </test>
  </area>
</xml>
 
 
Public Fuction ReadXML()     
   Dim xml As Object
        Dim XMLDoc As New XmlDocument
        Dim nodeList As XmlNodeList
        ' Dim node As XmlNode
 
        XMLDoc.Load("C:\temp\example.xml")
 
        nodeList = XMLDoc.SelectNodes("area/test/result")
        For Each node As XmlNode In nodeList
            Dim lsted As String = node.InnerText
            lblisted.Items.Add(lsted)
        Next
End Function
 
 
<xml>
  <area>
    <test>
      <result id="example" hid="example2" other="example3">
    </test>
  </area>
</xml>

Open in new window

0
Comment
Question by:zerogeek
  • 2
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 300 total points
ID: 24767628
Use the Attributes property. For example....

    Dim id As String = node.Attributes("id").Value

Wayne
0
 
LVL 15

Assisted Solution

by:jinal
jinal earned 200 total points
ID: 24769003
Public Fuction ReadXML()    
   Dim xml As Object
        Dim XMLDoc As New XmlDocument
        Dim nodeList As XmlNodeList
        ' Dim node As XmlNode
 
        XMLDoc.Load("C:\temp\example.xml")
 
        nodeList = XMLDoc.SelectNodes("area/test/result")
        For Each node As XmlNode In nodeList
            Dim lsted As String = String.Empty
            For Each attrib as XmlAttribute in node.Attributes
            lsted  = lsted + attrib.Value
            Next  
            lblisted.Items.Add(lsted)
        Next
End Function
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 24769481
jinal,

If you are going to make use of suggestions made by other experts, please be courteuos enough to acknowledge them.

Wayne
0
 
LVL 15

Expert Comment

by:jinal
ID: 24769762
Hello Wayne,
When i posted my code i did not read the comment by other expert.
I realize that partial part of my code already there.  I will take care of this next time.
Thanks.
0
 

Author Closing Comment

by:zerogeek
ID: 31599364
Thank you. Both answers were great.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What namespace do I need to import? 2 27
Regular expression help 2 24
VB.Net Tranfer data between to VB.Net apps 8 25
How come this regular expression allows "e"? 14 35
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question