VB.NET: Extract element and attribute using ChildNode method......[Resolved]
Say I have these Xml tag:
Code:
<hi help=”example”>
<how>
<to>do</to>
<or>
<give suggestion=”on” doing=”it”/>
</or>
<thank>bye</thank>
</how>
<how>
…
</how>
</hi>
I want to use the childNode method to do for example:
Code:
Dim xdoc As XmlDocument
Dim nodelist As XmlNodeList
Dim node As XmlNode
Dim to, thank, suggestion, doing As String
xdoc = New XmlDocument
xdoc.LoadXml("example.xml")
nodelist = xdoc.SelectNodes("/hi/how")
For Each node In nodelist
to = node.ChildNodes.Item(0).InnerText
thank = node.ChildNodes.Item(2).InnerText
listbox.Items.Add( to & thank)
Dim giveNode As XmlNode = node.ChildNodes.Item(1).ChildNodes.Item(0)
suggestion = giveNode.Attributes(0).Value
doing = giveNode.Attributes(1).Value
listbox.Items.Add( suggestion & doing)
Next
I can use the above code to get the content of to, thank, suggestion and doing...but how to get back the same content if i change the Xml tag to:
Code:
<hi help=”example”>
<how to=”do”>
<give suggestion=”on” doing=”it”/>
<thank>bye</thank>
</how>
<how>
…
</how>
</hi>
Thanks
Re: VB.NET: Extract element and attribute using ChildNode method
I manage to extract only the "to" and "thank" tag with the following code:
Code:
to = node.Attributes.GetNamedItem("to").Value
thank = node.ChildNodes.Item(1).InnerText
Can anybody help me to get the suggestion and doing attributes...
Thanks
Re: VB.NET: Extract element and attribute using ChildNode method
At last, i solve it using:
Code:
suggestion= node.ChildNodes.Item(0).Attributes.GetNamedItem("suggestion").Value
doing = node.ChildNodes.Item(0).Attributes.GetNamedItem("doing").Value
:) :) :) :) :)