[jdom-interest] JDOM and XPath confusion

Edelson, Justin Justin.Edelson at mtvn.com
Mon Aug 21 09:44:58 PDT 2006

Is the XML below a complete document or an element within some larger
document? If there's a parent element to the mets element, then I think
you should use
p'][@MDTYPE='MODS']/*[local-name()='xmlData']/*[local-name()='mods']" as
your Xpath. 

-----Original Message-----
From: jdom-interest-bounces at jdom.org
[mailto:jdom-interest-bounces at jdom.org] On Behalf Of Richard Jones
Sent: Monday, August 21, 2006 11:10 AM
To: jdom-interest at jdom.org
Subject: [jdom-interest] JDOM and XPath confusion

Hi Folks,

Apologies for the newbie question; I hope this list is the right place 
to post this.

I'm trying to use the JDOM implementation for XPath, and am consistently

getting no results from any of my queries, despite following a variety 
of different documentation pages all of which claim to work.  I must be 
doing something really obvious wrong, but I can't for the life of me see

what it is.

I have an XML document:

<mets xmlns="http://www.loc.gov/METS/">
   <dmdSec ID="ID0">
     <mdWrap MDTYPE="MODS">
         <mods xmlns="http://www.loc.gov/mods/v3" version="3.2">
		Activation of the light sensitive channels,
		TRP and TRPL, in Drosophila.
           <name type="personal">
               <roleTerm type="text">author</roleTerm>

And I'm trying to extract the section starting <mods> using an XPath 

So far, I have tried the following (the first one of which evaluates 
correctly using the XPath Explorer):



using code that looks like this:

String xpath=ConfigurationManager.getProperty("mods.xpath");
System.out.println("using xpath: " + xpath);
XPath x = XPath.newInstance(xpath);
x.addNamespace("mets", "http://www.loc.gov/METS/");
List mods = x.selectNodes(mets);
System.out.println("I counted: " + mods.size() + "results");
System.out.println("This is the mods data:" + mods.toString());

I have also tried using


to get the wrapper XML, and also replacing:

x.addNamespace("mets", "http://www.loc.gov/METS/");



where mets is the JDOM Element object that I am querying, representing 
the above XML.  I've also tried leaving this line out altogether.

Can anyone see what I'm doing wrong?  I always get the result:

using xpath: [whatever expression I'm trying]
I counted: 0 results
This is the mods data:[]

Any help would be very gratefully received; thanks in advance

All the best,

Richard Jones
Web and Database Technology Specialist
Imperial College London
t: +44 (0)20 759 41815
e: richard.d.jones at imperial.ac.uk
To control your jdom-interest membership:

More information about the jdom-interest mailing list