Solved

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

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get distinct values from excel or comm seperated file 4 30
Sort GridView by ID Descending 1 17
Help with error in Query 2 31
VB.net Open video relating to control 2 19
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

856 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