KenNECIVSIPS
Technical User
I am trying to return only child elements that match the specific criteria.
Here is my xml:
The following query gives me all of the vehicles of type 'Car':
//Vehicle[type='Car']
But what if I want this XML with all of the parent information? I want to be able to return the following:
Notice that the Boats are not in this XML.
How do I do this. I have tried ancestor, parent, etc. but I can;t figure it out.
Thanks!
Here is my xml:
Code:
<?xml version='1.0' encoding='utf-8' ?>
<Locations>
<Location name='A'>
<Vehicles>
<Vehicle vin='1'>
<type>Car</type>
<color>Red</color>
</Vehicle>
<Vehicle vin='2'>
<type>Car</type>
<color>Blue</color>
</Vehicle>
<Vehicle vin='3'>
<type>Boat</type>
<color>Red</color>
</Vehicle>
<Vehicle vin='4'>
<type>Boat</type>
<color>Green</color>
</Vehicle>
<Vehicle>
<type>Boat</type>
<color>Yellow</color>
</Vehicle>
</Vehicles>
</Location>
<Location name='B'>
<Vehicles>
<Vehicle vin='5'>
<type>Car</type>
<color>Orange</color>
</Vehicle>
</Vehicles>
</Location>
</Locations>
The following query gives me all of the vehicles of type 'Car':
//Vehicle[type='Car']
Code:
<Vehicle vin='1'>
<type>Car</type>
<color>Red</color>
</Vehicle>
<Vehicle vin='2'>
<type>Car</type>
<color>Blue</color>
</Vehicle>
<Vehicle vin='5'>
<type>Car</type>
<color>Orange</color>
</Vehicle>
But what if I want this XML with all of the parent information? I want to be able to return the following:
Code:
<?xml version='1.0' encoding='utf-8' ?>
<Locations>
<Location name='A'>
<Vehicles>
<Vehicle vin='1'>
<type>Car</type>
<color>Red</color>
</Vehicle>
<Vehicle vin='2'>
<type>Car</type>
<color>Blue</color>
</Vehicle>
</Vehicles>
</Location>
<Location name='B'>
<Vehicles>
<Vehicle vin='5'>
<type>Car</type>
<color>Orange</color>
</Vehicle>
</Vehicles>
</Location>
</Locations>
Notice that the Boats are not in this XML.
How do I do this. I have tried ancestor, parent, etc. but I can;t figure it out.
Thanks!