Project

Profile

Help

Xquery returning null

Added by Anonymous about 19 years ago

Legacy ID: #3126147 Legacy Poster: Evan Alter (hadees)

Okay so I am really lost, I had this working and I must have changed something that I can't remember but now it doesn't work Here is my code: protected void runTest(org.w3c.dom.Document doc, Reader query, String url, Element root){ try { JDOMResult out = new JDOMResult(); Configuration c = new Configuration(); StaticQueryContext qp = new StaticQueryContext(c); DynamicQueryContext dqc = new DynamicQueryContext(c); XQueryExpression xe = qp.compileQuery(query); dqc.setContextNode(new DocumentWrapper(doc, url, c)); if (!xqParameters.isEmpty()) { for (Iterator i1 = xqParameters.keySet().iterator(); i1.hasNext();) { String name = (String) i1.next(); Object value = xqParameters.get(name); dqc.setParameter(name, value); } } Properties props = new Properties(); props.setProperty(OutputKeys.METHOD, "xml"); props.setProperty(OutputKeys.INDENT, "yes"); Object stuff = xe.evaluateSingle(dqc); xe.run(dqc,out,props); Document result = out.getDocument(); root.addContent(result.detachRootElement()); } catch (XPathException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } what ends up happening is a org.jdom.IllegalAddException: Cannot add null object is thrown but the cause of this is that after xe.run(dqc,out,props) out doesn't have anything. I have tried all kinds of weird combos chaning what runs the query, even having it use evaluateSingle() instead of xe.run(dqc,out,props) Like I said before this code worked at one time and for the life of me I can't figure out what changed.


Replies (1)

RE: Xquery returning null - Added by Anonymous about 19 years ago

Legacy ID: #3130623 Legacy Poster: Michael Kay (mhkay)

JDOMResult is presumably the class org.jdom.transform.JDOMResult? I've never tried using that directly from Saxon, and my first reaction is that I'm surprised that it ever worked; except that I see it's defined as a subclass of SAXResult, so presumably JDOM is doing the work behind the scenes to convert the stream of SAX events into a JDOM document node. I suggest you start by replacing the JDOMResult with an ordinary SAXResult to check that Saxon is emitting the stream of SAX events correctly. (You could use a SAXResult wrapped around the ExampleContentHandler from the samples/java directory.) If the events are being produced OK, then the problem is in the JDOM code and I can't really help you with it. You haven't shown the query, but one possibility is that the results are not a well-formed XML document. Michael Kay

    (1-1/1)

    Please register to reply