Project

Profile

Help

Saxon 8.7 to 8.9 - DynamicEr

Added by Anonymous about 17 years ago

Legacy ID: #4319820 Legacy Poster: James Neff (james-neff)

Greetings, My Java application worked fine (just slow) under Saxon 8.7 and I thought I'd try out 8.9 to see if it would speed up a bit. I'm receiving this error: net.sf.saxon.trans.DynamicError: Finding root of tree: the context item is undefined The XML document is: <enrollment_record><effective_date>20060501</effective_date></enrollment_record> The XPath is: substring(/enrollment_record/effective_date, 1, 4) Here is the piece from my Java applicaiton: System.setProperty("javax.xml.xpath.XPathFactory:"+NamespaceConstant.OBJECT_MODEL_SAXON,"net.sf.saxon.xpath.XPathFactoryImpl"); InputSource inputSource = new InputSource(new StringReader(inputDoc)); results = (String) xPath.evaluate(xPathExpression, inputSource, XPathConstants.STRING); This worked under Saxon 8.7, what am I doing wrong under 8.9? Thank you in advance, James


Replies (5)

Please register to reply

RE: Saxon 8.7 to 8.9 - DynamicEr - Added by Anonymous about 17 years ago

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

I've just looked at the code, and I'm afraid it's a glaring bug. The variants of the evaluate() method that take an InputSource simply don't work. (I guess these methods are not used that often because most people want to evaluate more than one expression, and an InputSource generally isn't reusable). As a workaround, please do DocumentInfo doc = ((net.sf.saxon.xpath.XPathEvaluator).xPath).setSource( new StreamSource(new StringReader(inputDoc)); results = (String) xPath.evaluate(xPathExpression, doc, XPathConstants.STRING); Sorry about the inconvenience. I'll put a patch in Subversion ASAP. Michael Kay http://www.saxonica.com/

RE: Saxon 8.7 to 8.9 - DynamicEr - Added by Anonymous about 17 years ago

Legacy ID: #4322830 Legacy Poster: James Neff (james-neff)

Thank you for getting back to me so quickly. I got your work-around to work. However it is still fairly expensive to do the evaluations even with the new version of Saxon. You hinted in your reply that there may be a better way to do this? Am I doing this wrong and what is a faster way ? Thanks again in advance, James

RE: Saxon 8.7 to 8.9 - DynamicEr - Added by Anonymous about 17 years ago

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

The obvious inefficiency in your code is that you seem to be parsing the source document and building a tree representation every time you execute a path expression. I haven't seen the whole application so my inferences may be wrong, but if you are doing this repeatedly then it's almost certainly better to build the source document once and reuse it. You can do this by DocumentInfo doc = config.buildDocument(Source source); then supply "doc" as the source object for evaluating XPath expressions.

RE: Saxon 8.7 to 8.9 - DynamicEr - Added by Anonymous about 17 years ago

Legacy ID: #4325347 Legacy Poster: James Neff (james-neff)

Yes, that sped it up tremendously. Thank you! Also, the XPath expressions I am using, I store them in a database but they are reused thousands of times throughout the instance of the application. They are stored in instance variables as strings within my Java application. Is there a better way to store them in memory (is there an XPath Expression Object?) that would make evaluate() run faster, or would that not make a difference? Thanks, James

RE: Saxon 8.7 to 8.9 - DynamicEr - Added by Anonymous about 17 years ago

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

Yes, both the JAXP XPath interface and the Saxon XPath interface offer the ability to compile an XPath expression stored as a string into an XPathExpression object. For an overview see http://www.saxonica.com/documentation/xpath-api/intro.html For the detail, see the Javadoc. Michael Kay http://www.saxonica.com/

    (1-5/5)

    Please register to reply