This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes XML and Related Technologies and the fly likes Getting distinct Values from XML using XPath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Getting distinct Values from XML using XPath" Watch "Getting distinct Values from XML using XPath" New topic
Author

Getting distinct Values from XML using XPath

Udit Manektala
Ranch Hand

Joined: Sep 17, 2006
Posts: 30
So I need to retrieve distinct values for the Source Element in this XML.
I identified 2 ways:



1. A function called distinct-values. Gave an exception. Here's how i tried it:

2. I tried a method i took from
this website
link
Here;s how I tried to implement it:


The problem with the second method is that i need to look for the preceding sibling of the parent and not the preceding sibling of the SOURCE Element. And I cant find a function for finding the parent element.
Udit Manektala
Ranch Hand

Joined: Sep 17, 2006
Posts: 30
fixed it:

List lList1 = inputXML.selectNodes("/RESPONSE/RECORD[not( SOURCE/text()=preceding-sibling::RECORD/SOURCE/text())]/SOURCE/text() ");

Anyone know a better way ?

But still can't figure out what the Object Type of the thing is thats stored in the List.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Getting distinct Values from XML using XPath