Click here to Skip to main content
15,886,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HTML
<booking>
<booking_parts>

<quote>

 <quote_entry cet_id="A" amoount="20" /> 
<quote_entry cet_id="B" amoount="40" /> 

</quote>

</booking_parts>

</booking>


I want to get amount 20 from this xml, any idea?
Posted
Updated 26-Mar-15 23:19pm
v3
Comments
Member 11491784 27-Mar-15 6:41am    
doc.LoadXml(strdata)
Dim root As System.Xml.XmlNode = doc.SelectSingleNode("//quote")
Dim Book As System.Xml.XmlNode
Book = root.SelectSingleNode("quote_entry[@cet_id='A']")


From this code i got 1 row of quote entry, how can i extract the value 20?

1 solution

Hi, well I see you have successfully retrieved the desired XmlNode. All that is left for you is to retrieve the required attribute from that node.
So something like this:
VB
Dim bookAmoount = Book.Attributes("amoount").Value

Also just in case you're interested you can simplify your code with something like this:
VB
Dim bookAmoount = doc.SelectSingleNode("//quote/quote_entry[@cet_id='A']").Attributes("amoount").Value
 
Share this answer
 
Comments
Member 11491784 31-Mar-15 3:45am    
And can you tell me how Can I update the Xml with updated value. Thanks
Mario Z 31-Mar-15 4:32am    
Well that depends on where you want your XML, do you want it in a file or a string?

In case it's in a file you would use Save method on your XmlDocument, for example:

doc.Save("desired-output-file path.xml")

In case it's in a string you can either use a OuterXml property of your XmlDocument, for example:

Dim xmlData = doc.OuterXml

Or you can write it to StringBuilder with an XmlWriter, for example:

Dim xmlData As String
Using stringWriter As New StringWriter()
Using writer As XmlWriter = XmlWriter.Create(stringWriter)
doc.WriteTo(writer)
writer.Flush()
xmlData = stringWriter.GetStringBuilder().ToString()
End Using
End Using

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900