Solved

How to parse this XML document in vb.net

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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

778 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