htabbach
asked on
How to parse this XML document in vb.net
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
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
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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