saxon java xpath exception :
Posted
by changed
on Stack Overflow
See other posts from Stack Overflow
or by changed
Published on 2010-04-20T15:50:57Z
Indexed on
2010/04/20
15:53 UTC
Read the original article
Hit count: 483
Hi I am trying to read XPath queries from a file and run it against a xml data file. I am doing it through Saxon Xpath processor. But i keep getting this error. Code i am using is from sample code provided with the library.
Error i am getting is :
Exception in thread "main" javax.xml.xpath.XPathExpressionException: Supplied node must be built using the same or a compatible Configuration
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:283)
at net.sf.saxon.xpath.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:375)
at edu.xml.XPathExample.go(XPathExample.java:81)
at edu.xml.XPathExample.main(XPathExample.java:42)
-
public void go(String filename) throws Exception {
XPathExpression findLine = null;
String readLine = null;
Object document = new XPathEvaluator().setSource(new StreamSource(new File(dataPath)));
System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON,
"net.sf.saxon.xpath.XPathFactoryImpl");
XPathFactory xpf = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);
XPath xpe = xpf.newXPath();
if (filename != null) {
this.queryPath = filename;
}
try {
fileReader = new BufferedReader(new FileReader(queryPath));
} catch (FileNotFoundException ex) {
System.out.println("File not found: " + ex.getMessage());
}
xpe.setXPathVariableResolver(this);
while (true) {
try {
readLine = fileReader.readLine();
} catch (IOException ex) {
System.out.println("Error while reading file: " + ex.getMessage());
}
if (readLine == null) {
break;
}
findLine = xpe.compile(readLine);
String resultString = findLine.evaluate(document);
System.out.println("<output>");
System.out.println("String Value => " + resultString);
System.out.println("</output>");
}
}
© Stack Overflow or respective owner