Below is a condensed version of a XML file provided by a different business unit. What I need to get the value of is DriverInputSetGoodStudent.
This is how I am approaching this:
//session/data/policy/line/child::vehicle[position()=1]
That gets me the first vehicle in the XML, so then I will know the ID of the driver of that vehicle based on the GoverningDriverIdInfo/ItemId. Then I need to match that ID with the id property of the driver node. Then get the value of the DriverInputSetGoodStudent node.
<session>
<data>
<policy>
<line>
<driver id="d4A5D51CEC4C14D3C9754A59AE09EFF9B" deleted="0" description="OH Edge, Teresa / 321654654">
<DriverTrainingInd>N</DriverTrainingInd>
<DriverInputGoodStudent>N</DriverInputGoodStudent>
<DriverInputSetDriverTraining>0</DriverInputSetDriverTraining>
<DriverInputSetGoodStudent>0</DriverInputSetGoodStudent>
<DriverInputAccidentPreventionTrainingDate>2011-05-05</DriverInputAccidentPreventionTrainingDate>
<AccidentPreventionCourse>0</AccidentPreventionCourse>
<AccidentPreventionCoursePreviousValue>0</AccidentPreventionCoursePreviousValue>
<DriverTrainingPrevValue>0</DriverTrainingPrevValue>
<DriverOutputGoodStudent>No</DriverOutputGoodStudent>
</driver>
<vehicle id="v1CFDF4006D7C41D8B8C8A510E4C5C2E1" deleted="0" description="TYTA CAMRY BASE/LE/SE/XLE, 2010, 4T1BF3EK3AU522985">
<VehicleInputPrimaryDriver>d4A5D51CEC4C14D3C9754A59AE09EFF9B</VehicleInputPrimaryDriver>
<GoverningDriverIdInfo>
<ItemIdList>d4A5D51CEC4C14D3C9754A59AE09EFF9B</ItemIdList>
<ItemId>d4A5D51CEC4C14D3C9754A59AE09EFF9B</ItemId>
</GoverningDriverIdInfo>
<PrimaryDriverID>d4A5D51CEC4C14D3C9754A59AE09EFF9B</PrimaryDriverID>
<VehicleGoodStudent>No</VehicleGoodStudent>
<VehicleDriverTraining>No</VehicleDriverTraining>
</vehicle>
<line>
<policy>
<data>
<session>
I see that the code didn’t paste in the quite correctly, there is an “end session” tag that isn’t appearing in the code block. Thanks in advance for your help.
If you have the id somewhere :
You can simply use it to find the desired node :
Update answer :
Output :
Where 0 is the value of your desired node. No variables used. I thought it was clear how to combine the two variables which were used only for proving a concept.