How to get selected node in a XML with childnodes and childnodes' childnodes?
-
Hi,everyone!I have a XML, its structure was like below: <Height> <Standard>4721 <PN>1.6 <A DN="250">300</A> <A DN="350">400</A> <A DN="450">500</A> <A DN="550">600</A> </PN> <PN>2.5 <A DN="250">300</A> <A DN="350">400</A> <A DN="450">500</A> <A DN="550">600</A> </PN> </Standard> </Height> I want to get the selected node's text,for example,when PN = 1.6,DN = 250,the selected node's text was 300;PN=2.5,DN=350,the text should be 400.I tried use "for each node in childnodes",but it returned "1.6 300400500600".How could get the node I wanted? I think that should be first selected "PN",and then get each childnode in . But I don't know how to do this :sigh: PLZ give me some help,thx!
-
Hi,everyone!I have a XML, its structure was like below: <Height> <Standard>4721 <PN>1.6 <A DN="250">300</A> <A DN="350">400</A> <A DN="450">500</A> <A DN="550">600</A> </PN> <PN>2.5 <A DN="250">300</A> <A DN="350">400</A> <A DN="450">500</A> <A DN="550">600</A> </PN> </Standard> </Height> I want to get the selected node's text,for example,when PN = 1.6,DN = 250,the selected node's text was 300;PN=2.5,DN=350,the text should be 400.I tried use "for each node in childnodes",but it returned "1.6 300400500600".How could get the node I wanted? I think that should be first selected "PN",and then get each childnode in . But I don't know how to do this :sigh: PLZ give me some help,thx!
System.Xml has a method SelectSingleNode, which requires an xPath expression in order to work. Your method should look somewhat like the following:
Sub GetSelected(string _PN, string_ DN)
' Put some code here to read your XML document into a XMLDocument variable,
' called XDoc for instance.XmlNode _XN = XDoc.SelectSingleNode("/Height/Standard/" + _PN + "/A")
End Sub
(yes, I'm not a hero in vb, 5 pts if you guess my 'dialect'). Hope this steers you in the right direction!
"My personality is not represented by my hometown."
-
System.Xml has a method SelectSingleNode, which requires an xPath expression in order to work. Your method should look somewhat like the following:
Sub GetSelected(string _PN, string_ DN)
' Put some code here to read your XML document into a XMLDocument variable,
' called XDoc for instance.XmlNode _XN = XDoc.SelectSingleNode("/Height/Standard/" + _PN + "/A")
End Sub
(yes, I'm not a hero in vb, 5 pts if you guess my 'dialect'). Hope this steers you in the right direction!
"My personality is not represented by my hometown."
Hello,Eaverae! Your suggestion is helpful for me to get more details about the method "SelectedSingleNode".Thank you! I have got my solution like below:
For Each node1 In list1
Dim val As String
val = node1.Attributes("PN").Value
If val = TextBox1.Text Then
Dim list2 As XmlNodeList = node1.SelectNodes("Height")
Dim node2 As XmlNode
For Each node2 In list2
Dim val2 As String
val2 = node2.Attributes("DN").Value
If val2 = TextBox2.Text Then
TextBox3.Text = node2.InnerText
End If
Next
End If
NextWhat's more, I have change the XML element
<PN>
to
<PN PN="1.6">
:)