[jdom-interest] Problem running JDOM app using XPath

AH ahives at hotmail.com
Sun Jun 22 13:46:42 PDT 2003


Thanks for the help...I made the change you suggested and I get the following error message...


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:18)
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:18)
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:18)
Press any key to continue . . .

Could it be that something is not installed properly...if so what could it be...I am clueless on this issue...The reason why I changed the string from //resources/dms[@name='MySQL']/data_source[@name='Login']/url to resources/dms[@name='MySQL']/data_source[@name='Login']/url is because I got the same error so I thought the expression was wrong...Please help...Thanks...


ALBERT


  ----- Original Message ----- 
  From: Zufferey, Michael 
  To: AH 
  Sent: Sunday, June 22, 2003 12:50 PM
  Subject: AW: [jdom-interest] Problem running JDOM app using XPath


  Hello!



  Your program and the "config.xml" file are good!



  The problem is the string path! The XPATH expression is incorrect! As it is, it will not work!



  Replace your original path with this one:



  String path = "/resources/dms[@name='MySQL']/data_source[@name='Login']/url";



  Or with this if you prefer (check your necessities before):



  String path = "//resources/dms[@name='MySQL']/data_source[@name='Login']/url";



  And you will obtain as result:



  URL:     jdbc:mysql://localhost/login



  Best wishes,



  Michael



  -----Ursprüngliche Nachricht-----
  Von: AH [mailto:ahives at hotmail.com] 
  Gesendet: Samstag, 21. Juni 2003 21:01
  An: JDOM Interest
  Betreff: [jdom-interest] Problem running JDOM app using XPath



  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/20030622/47a53f9e/attachment.htm


More information about the jdom-interest mailing list