Problems with XML

tom_tom

New member
Joined
May 4, 2006
Messages
1
Programming Experience
Beginner
Hello guru,

I'm newbie in programming so I can't find a solution to a very simple question :)

Here's XML file:

<?xml version="1.0" encoding="UTF-8"?>
<family>
<name_1 gender="Male">
<firstname>Tom</firstname>
<lastname>Smith</lastname>
<optionsid>first</optionsid>
</name_1>
<name_1 gender="Female">
<firstname>John</firstname>
<lastname>Smith</lastname>
<optionsid>second</optionsid>
</name_1>
<name_1 gender="Male">
<firstname>Trevor</firstname>
<lastname>Smith</lastname>
<optionsid>first</optionsid>
</name_1>
<Options id="first">
<duration>30</duration>
<car>Volvo</car>
</Options>
<Options id="second">
<duration>50</duration>
<car>Rover</car>
</Options>
</family>


My task is to find value in particular node (example: to find node where first name is "John") then get other value from this node (example: get optionsid value (it will be "second")). Then I will do a search for a node with a particular optionsid ("second") and get values from this node (duraton, car)

There's a code to find a node

Dim new_path As System.Xml.XmlNode = m_xmld_2.SelectSingleNode("//firstname[.='John']")

...but what else to do ?


Hope for help

Thanks in advance
 
after you get the new_path node, navigate to the parent...
VB.NET:
dim parent_node as system.xml.xmlelement = new_path.parentNode
then select the optionsid node from there
VB.NET:
dim optionsid_node as system.xml.xmlelement = parent_node.selectSingleNode("optionsid")
then pull the innertext out
VB.NET:
dim sOptionsID as string = optionsid_node.innerText
then use that string to find the corresponding Options node
VB.NET:
dim node_options as system.xml.xmlelement = m_xmld_2.selectSingleNode("//Options[@id='" & sOptionsID & "']")
 
Back
Top