Solved

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

Posted on 2009-07-02
5
495 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now