[jdom-interest] Problem running JDOM app using XPath
AH
ahives at hotmail.com
Mon Jun 23 15:05:03 PDT 2003
Yes...I am using JDK 1.4.1_01, Xerces 2.4.0, Xalan 2.5.1, JDOM b9, and no IDE (TextPad)...I am indifferent to using IDE's :)...my classpath variables are set properly and its strange that I continue to get the same error message despite knowing that the XPath expression is correct...here is error appears when I use the getMessage method in the body of the catch statement...
Invalid XPath expression: "//resources/dms[@name='MySQL']/data_source[@name='Login']/url": wrapped exception
It's crazily strange that I can use every other JDOM/DOM API functionalities beside XPath which tells me that JDOM is properly setup...this is getting on my nerves...please help...thanks...
--------------------------------------------------------------------------------
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("weather.xml"));
try {
XPath xpath = XPath.newInstance(path);
Element node = (Element)xpath.selectSingleNode(doc);
System.out.println("URL:\t" + node.getTextNormalize());
}
catch(JDOMException excpt) {
System.out.println(excpt.getMessage());
// excpt.printStackTrace();
}
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>
AH
----- Original Message -----
From: Zufferey, Michael
To: AH
Sent: Monday, June 23, 2003 2:13 AM
Subject: AW: [jdom-interest] Problem running JDOM app using XPath
Hello!
Strange that it doesn`t work! The program work well with me! May be you have not all the libraries correctly installed!
I use JBuilder 6 Entreprise Edition, JAVA 1.4.1_02, Xerces_2.3.0, Xalan_2.5.D1 and JDOM-b9-rc2.
Anyway, If I don't modify the string path I obtain a java.lang.NullPointerException.
Which IDE do you use? Can you give me some details?
You can also try to use a IDE if you don't yet use one! Eclipse and NetBeans are free! And JBuilder personal is for free too!
Best wishes,
Michael
-----Ursprüngliche Nachricht-----
Von: AH [mailto:ahives at hotmail.com]
Gesendet: Sonntag, 22. Juni 2003 22:47
An: Zufferey, Michael; JDOM Interest
Betreff: Re: [jdom-interest] Problem running JDOM app using XPath
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/20030623/108684f3/attachment.htm
More information about the jdom-interest
mailing list