Friday, April 24, 2020

Fetching Unique XML Tags based on Values

Listing down the unique values of a tag in entire XML
Below is the raw information in the form of an XML

<?xml version="1.0" encoding="UTF-8"?>
<STATES>
<STATE>
<NAME>TELANGANA</NAME>
<REGION>SOUTH</REGION>
<CAPITAL>HYDERABAD</CAPITAL>
</STATE>
<STATE>
<NAME>TAMILNADU</NAME>
<REGION>SOUTH</REGION>
<CAPITAL>CHENNAI</CAPITAL>
</STATE>
<STATE>
<NAME>KARNATAKA</NAME>
<REGION>SOUTH</REGION>
<CAPITAL>BENGALURU</CAPITAL>
</STATE>
<STATE>
<NAME>KERALA</NAME>
<REGION>SOUTH</REGION>
<CAPITAL>TRIVANDRUM</CAPITAL>
</STATE>
<STATE>
<NAME>MAHARASHTRA</NAME>
<REGION>WEST</REGION>
<CAPITAL>MUMBAI</CAPITAL>
</STATE>
<STATE>
<NAME>TELANGANA</NAME>
<REGION>SOUTH</REGION>
<CAPITAL>HYDERABAD</CAPITAL>
</STATE>
<STATE>
<NAME>TAMILNADU</NAME>
<REGION>SOUTH</REGION>
<CAPITAL>CHENNAI</CAPITAL>
</STATE>
</STATES>

I want to get only the unique state names from the above information. (TELANGANA,TAMILNADU,KARNATAKA,KERALA,MAHARASHTRA)


//STATE/NAME[not(. = ../following-sibling::STATE/NAME)]

Credits : 
Padmapriya Iyengar (padmapriya.iyengar@gmail.com)