Suppose I have an XML file -
<Cars>
<Year> 2021 </Year>
<Model>
<Name> Porsche 911 </Name>
<Year> 2020 </Year>
</Model>
<Model>
<Name> Porsche 911 </Name>
<Year> 2019 </Year>
</Model>
<Model>
<Name> Porsche Cayenne </Name>
<Year> 2019 </Year>
</Model>
</Cars>
Now I want to extract the Year 2021 which is not the Year of that particular model but the date when this XML was written (It is the outer one)
But to do that.. due to restraints on the path not being hardcoded, I was using //Year//text()
but it gives out the output as [2021,2020,2019,2019]
. I don't want that because if the order is changed, the index changes and that would create a problem.
Please help with a XPath command where I can exclude the inner Year tags and only use the outer one.