Java Mailing List Archive

http://www.junlu.com/

Google
Google
Mailing List
Home
Forum Home
JBoss - Java Application Server
Tomcat - JSP/Servlet container
Struts - A MVC web framework
iText - An open source PDF Java Library
JDOM - JDOM XML Parser
J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition
JSP - A mailing list about Java Server Pages specification and reference
J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog
Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology
Struts & Hibernate
Subjects
JSP editor plugin for eclipse ?
org apache jasper JasperException: Unable to compile class for JSP
Tomcat: Connection reset by peer: socket write error
Cannot retrieve definition for form bean null
Struts Tiles Tutorial (free Struts training)
Where do I download Tomcat 4 0 6?
Data Access Object (DAO) pattern, example DAO 's
Where to download Tomcat v 4 1 24 from?
Tomcat 5 0 16 Requested resource not available
Servlet : Session invalidate
Oracle Connection Pooling in 3 2 2
Servlet action is currently unavailable
Tomcat/Struts Unicode Encoding/Decoding problems
Running a Simple JMS Example
Tomcat and webapplication specific java library path
Mapping in workers2 properties
org apache jasper JasperException
problem with html:text bean throwing exception
Cannot find message resources under key org apache struts action
   MESSAGE
Cannot find message resources under key org apache struts action MESSAGE
invalid direct reference problem with solution
Tool for jsp debug Try Sysdeo Eclipse Plugin
Tomcat 5 Cannot load JDBC driver class 'null ' SQL state: null
weblogic ejbc
java properties file
Jboss 3 2 3 Coyote Can 't re
Tomcat 5, Apache2 and mod jk2 integration problem
JBoss example problem new to J2EE
Value attribute of <html:checkbox
url string for connecting jboss to oracle
javax servlet ServletException: BeanUtils populate
5 0 18: Windows XP Pro vs Windows 2000
HTTP Status 404 The requested resource is not available
 
JDOM and XPath confusion

JDOM and XPath confusion

2006-08-21       - By Richard Jones

 Back
Reply:     1     2     3  

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">
      <xmlData>
        <mods xmlns="http://www.loc.gov/mods/v3" version="3.2">
   <genre>Journal</genre>
   <titleInfo>
     <title>
    Activation of the light sensitive channels,
    TRP and TRPL, in Drosophila.
            </title>
          </titleInfo>
          <name type="personal">
     <role>
              <roleTerm type="text">author</roleTerm>
     </role>
     <namePart>xxxx</namePart>
     <description>111111</description>
     <description>aaaaaa</description>
   </name>
  </mods>
      </xmlData>
    </mdWrap>
  </dmdSec>
</mets>

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

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

/*[local-name()='mets']/*[local-name()='dmdSec']/*[local-name()='mdWrap'][
@(protected)='MODS']/*[local-name()='xmlData']/*[local-name()='mods']

/mets/dmdSec/mdWrap[@(protected)='MODS']/xmlData/mods

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

/mets:mets/mets:dmdSec/mets:mdWrap[@(protected)='MODS']/mets:xmlData

to get the wrapper XML, and also replacing:

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

with

x.addNamespace(mets.getNamespace());

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
-- ----
Richard Jones
Web and Database Technology Specialist
Imperial College London
t: +44 (0)20 759 41815
e: richard.d.jones@(protected)
__ ____ ____ ____ ____ ____ ____ ____ ____ ____
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)

©2008 junlu.com - Jax Systems, LLC, U.S.A.