[jdom-interest] Problem running JDOM app using XPath

AH ahives at hotmail.com
Sat Jun 21 12:00:50 PDT 2003


Hello everybody...I am using JDOM's XPath facility for the first time and
have followed all the rules on written proper XPath expressions...I have
also followed the rules in the program logic to set up XPath using JDOM but
there seems to be a major problem...Not just with my program but I get
pretty much the same error message when I try to run the sample programs
that come with Jaxen for the JDOM API...I don't know were I am going wrong
here...please help...I have provided a short program and xml file for
testing purposes...could it be that I need to install something else...I
have the latest version of Jaxen and JDOM installed...My JDOM and Jaxen APIs
are recognized by the JVM...don't understand it...thanks in advance for any
help...


Java source

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.JDOMException;
import org.jdom.input.SAXBuilder;
import java.io.File;
import org.jdom.xpath.XPath;


public class TestXPath
{
 public static void main(String [] args) throws Exception
 {
  String path =
"resources/dms[@name='MySQL']/data_source[@name='Login']/url";

  SAXBuilder sax_obj = new SAXBuilder();
  Document doc = sax_obj.build(new File("config.xml"));
  XPath xpath = XPath.newInstance(path);
  Element node = (Element)XPath.selectSingleNode(doc.getRootElement(),
path);

  System.out.println("URL:\t" + node.getTextNormalize());
 }
}



XML source

<?xml version="1.0" encoding="UTF-8"?>
<resources>
 <dms name="MySQL" driver="com.mysql.jdbc.Driver">
  <data_source name="Login" type="database">
   <url>jdbc:mysql://localhost/login</url>
  </data_source>
  <data_source name="Authentication" type="database">
   <url>jdbc:mysql://localhost/authentication</url>
  </data_source>
  <data_source name="Key" type="database">
   <url>jdbc:mysql://localhost/user_key</url>
  </data_source>
  <data_source name="ID" type="database">
   <url>jdbc:mysql://localhost/id</url>
  </data_source>
 </dms>
</resources>

I get the following error message when the above program is ran against the above xml file...

Exception in thread "main" org.jdom.JDOMException: Invalid XPath expression: "resources/dms[@name='MySQL']/data_source[@
name='Login']/url": wrapped exception
        at org.jdom.xpath.JaxenXPath.setXPath(JaxenXPath.java:288)
        at org.jdom.xpath.JaxenXPath.<init>(JaxenXPath.java:101)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
        at org.jdom.xpath.XPath.newInstance(XPath.java:136)
        at TestXPath.main(TestXPath.java:17)
Caused by: org.jaxen.JaxenException: wrapped exception
        at org.jaxen.BaseXPath.<init>(BaseXPath.java:142)
        at org.jaxen.BaseXPath.<init>(BaseXPath.java:157)
        at org.jaxen.jdom.JDOMXPath.<init>(JDOMXPath.java:103)
        at org.jdom.xpath.JaxenXPath.setXPath(JaxenXPath.java:284)
        ... 7 more
Caused by: org.jaxen.JaxenException: wrapped exception
        at org.jaxen.BaseXPath.<init>(BaseXPath.java:142)
        at org.jaxen.BaseXPath.<init>(BaseXPath.java:157)
        at org.jaxen.jdom.JDOMXPath.<init>(JDOMXPath.java:103)
        at org.jdom.xpath.JaxenXPath.setXPath(JaxenXPath.java:284)
        at org.jdom.xpath.JaxenXPath.<init>(JaxenXPath.java:101)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
        at org.jdom.xpath.XPath.newInstance(XPath.java:136)
        at TestXPath.main(TestXPath.java:17)
Caused by: org.jaxen.JaxenException: wrapped exception
        at org.jaxen.BaseXPath.<init>(BaseXPath.java:142)
        at org.jaxen.BaseXPath.<init>(BaseXPath.java:157)
        at org.jaxen.jdom.JDOMXPath.<init>(JDOMXPath.java:103)
        at org.jdom.xpath.JaxenXPath.setXPath(JaxenXPath.java:284)
        at org.jdom.xpath.JaxenXPath.<init>(JaxenXPath.java:101)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
        at org.jdom.xpath.XPath.newInstance(XPath.java:136)
        at TestXPath.main(TestXPath.java:17)
Press any key to continue . . .


Can anybody help...I am thinking that there is a problem with Jaxen but dont know enough about the API to figure out what...please help...


AH


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20030621/2d6b9be8/attachment.htm


More information about the jdom-interest mailing list