Solved

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

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

Turn Insights Into Action

You’ve already invested in ITSM tools, chat applications, automation utilities, and more. Fortify these solutions with intelligent communications so you can drive business processes forward.

With xMatters, you'll never miss a beat.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

690 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