Reputation: 464
I need to get a specific part from a xml string in vb.net.
<![CDATA[<Report id="GDC_CO" version="5" timestamp="1537843272109">
<Answer question="viaPlanning">
<Value option="01" value="true"/>
</Answer>
<Answer question="infoFromTMS">
<Value option="02" value="true"/>
</Answer>
<Answer question="trailerOK">
<Value option="01" value="true"/>
</Answer>
<Answer question="trailerOK2">
<Value option="01" value="true"/>
</Answer>
<Answer question="copyTrailer">
<Value option="copyTrailer" value="1QDV832 "/>
</Answer>
<Answer question="trailer">
<Value option="trailer" value="1QDV832 "/>
</Answer>
<Answer question="schade">
<Value option="01" value="true"/>
</Answer>
</Report>]]>
the part that i need is the value of value option="trailer". so that means is that i need to get "QDV832 "
what is the most effecient way of getting that out of this?
Upvotes: 0
Views: 67
Reputation: 693
example
Try
Dim xmlString as String = "<Report> ... </Report>"
Dim xmlDoc As New XmlDocument
xmlDoc.LoadXml(xmlString)
Dim nodeList As XmlNodeList = xmlDoc.SelectNodes("/Report/Answer/Value")
For Each node In nodeList
Dim optionAttribute As String = node.Attributes.GetNamedItem("option").Value
If optionAttribute.Equals("trailer") Then
Console.WriteLine(node.Attributes.GetNamedItem("value").Value)
Exit For
End If
Next
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Upvotes: 1