Solved

How to parse this XML document in vb.net

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

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now