?
Solved

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

Posted on 2009-07-02
5
Medium Priority
?
510 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 1200 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 800 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

762 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