i'm trying this example from here
it's a simple example i just try to execute a an xquery query on an xml document (books.xml).
I keep having this error that say that XML document structures must start and end within the same entity.
run: Error on line 33 column 8 of books.xml: SXXP0003: Error reported by XML parser: XML document structures must start and end within the same entity. javax.xml.xquery.XQException: org.xml.sax.SAXParseException; systemId: file:/C:/Users/Ahmed/Documents/NetBeansProjects/JavaXquery/books.xml; lineNumber: 33; columnNumber: 8; XML document structures must start and end within the same entity. at com.saxonica.xqj.SaxonXQPreparedExpression.executeQuery(SaxonXQPreparedExpression.java:101) at javaxquery.Main.execute(Main.java:40) at javaxquery.Main.main(Main.java:21) Caused by: net.sf.saxon.trans.XPathException: org.xml.sax.SAXParseException; systemId: file:/C:/Users/Ahmed/Documents/NetBeansProjects/JavaXquery/books.xml; lineNumber: 33; columnNumber: 8; XML document structures must start and end within the same entity.. i check over and over my xml file and it's valid
this the xml file books.xml
<?xml version="1.0" encoding="UTF-8"?> <books> <book category="JAVA"> <title lang="en">Learn Java in 24 Hours</title> <author>Robert</author> <year>2005</year> <price>30.00</price> </book> <book category="DOTNET"> <title lang="en">Learn .Net in 24 hours</title> <author>Peter</author> <year>2011</year> <price>70.50</price> </book> <book category="XML"> <title lang="en">Learn XQuery in 24 hours</title> <author>Robert</author> <author>Peter</author> <year>2013</year> <price>50.00</price> </book> <book category="XML"> <title lang="en">Learn XPath in 24 hours</title> <author>Jay Ban</author> <year>2010</year> <price>16.50</price> </book> </books> And this is my code java
package javaxquery; import java.io.FileNotFoundException; import javax.xml.xquery.XQConnection; import javax.xml.xquery.XQDataSource; import javax.xml.xquery.XQException; import javax.xml.xquery.XQPreparedExpression; import javax.xml.xquery.XQResultSequence; import com.saxonica.xqj.SaxonXQDataSource; public class Main { public static void main(String[] args){ try { execute(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (XQException e) { e.printStackTrace(); } } private static void execute() throws FileNotFoundException, XQException{ XQDataSource ds = new SaxonXQDataSource(); XQConnection conn = ds.getConnection(); String s = "for $x in doc(\"books.xml\")/books/book where $x/price>30 return $x/title" ; XQPreparedExpression exp = conn.prepareExpression(s) ; XQResultSequence result = exp.executeQuery(); while (result.next()) { System.out.println(result.getItemAsString(null)); } } }
No comments:
Post a Comment