Solved

How to parse this XML document in vb.net

Posted on 2011-02-28
4
462 Views
Last Modified: 2012-06-27
Hello,

I have this xmlDocument and I need to parse the Attribute: step:AcctPlayBack and get the value in it in vb.net

<?xml version="1.0"?>
      <state>
            <variable name="call_id" value="1298923172.61383" />
            <variable name="unique_id"" value=""1298923172.61383" />
            <variable name="dnis" value="13456789" />
            <variable name="callerid" value="123456789" />
            <variable name="callerid_name" value="username" />
            <variable name="step:9" value=""3132278"" />
            <variable name="step:AccountEntry" value="3132278" />
            <variable name="step:17" value="2" />
            <variable name="step:AcctPlayBack" value="2" />
      </state>
</xml>


I tried working with attributes but I am getting errors, how do I parse the value for that attribute?

Thanks
0
Comment
Question by:htabbach
[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
4 Comments
 
LVL 17

Expert Comment

by:nepaluz
ID: 35002291
try linq to xml

                Dim MyDoc As XDocument = XDocument.Load("Path2File")
                Dim xString = From seg In MyDoc...<state> Where seg.@<name> = "step:AcctPlayBack" Select seg.<Value>

Open in new window

0
 

Author Comment

by:htabbach
ID: 35002336
               Dim MyDoc As XDocument = XDocument.Load("Path2File")
                Dim xString = From seg In MyDoc...<state> Where seg.@<name> = "step:AcctPlayBack" Select seg.<Value>

I am sorry bit I have no idea what that was.
0
 
LVL 17

Accepted Solution

by:
nepaluz earned 500 total points
ID: 35002576
linq to xml
you will find your value in xString
NOTE: xString is a String(), and if there is more than one element whose attribute value for name is ....., then their  value attribute value will be in xString

PS> Change the second line to

Dim xString = From seg In MyDoc...<state> Where seg.@<name> = "step:AcctPlayBack" Select seg.@<Value>

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 35036938
Try the following:
Imports System.Xml

...

Dim xdoc As New XmlDocument
Dim value As String = String.Empty

xdoc.Load("filename.xml")

Dim node As XmlNode = xdoc.SelectSingleNode("//variable[@name='step:AcctPlayBack']/@value")

If node IsNot Nothing Then
    value = node.InnerText
End If

Open in new window

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

632 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