Solved

How to parse this XML document in vb.net

Posted on 2011-02-28
4
460 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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

751 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