Project

Profile

Help

Problem with FilterIterator

Added by Anonymous almost 18 years ago

Legacy ID: #3821645 Legacy Poster: Jeroen Bulters (jeroenbulters)

I am trying to write an XPath extension function and I get the following error: java.lang.ClassCastException: net.sf.saxon.tinytree.TinyAttributeImpl at net.sf.saxon.expr.GeneralComparison.effectiveBooleanValue(GeneralComparison.java:454) at net.sf.saxon.expr.FilterIterator$NonNumeric.matches(FilterIterator.java:161) at net.sf.saxon.expr.FilterIterator.getNextMatchingItem(FilterIterator.java:64) at net.sf.saxon.expr.FilterIterator.next(FilterIterator.java:44) at net.sf.saxon.value.SequenceExtent.<init>(SequenceExtent.java:105) at net.sf.saxon.functions.Closure.iterate(Closure.java:129) at net.sf.saxon.expr.PathExpression.iterate(PathExpression.java:767) at net.sf.saxon.expr.PathExpression.iterate(PathExpression.java:767) at net.sf.saxon.sort.DocumentSorter.iterate(DocumentSorter.java:73) at net.sf.saxon.expr.Atomizer.iterate(Atomizer.java:96) at net.sf.saxon.expr.ComputedExpression.process(ComputedExpression.java:600) at net.sf.saxon.expr.ForExpression.process(ForExpression.java:540) at net.sf.saxon.query.XQueryExpression.run(XQueryExpression.java:312) at net.sf.saxon.Query.doQuery(Query.java:449) at net.sf.saxon.Query.main(Query.java:81) Fatal error during transformation: net.sf.saxon.tinytree.TinyAttributeImpl This is the code executed: NodeInfo localnode = (NodeInfo)argument[0].evaluateItem(c); System.out.println("Document root: " + localnode.getDocumentRoot()); System.out.println("LocalNode: " + localnode); System.out.println("LocalIter: " + c.getCurrentIterator()); StandaloneContext sc = new StandaloneContext(localnode.getDocumentRoot()); String path = (String)argument[1].evaluateAsString(c); Expression pathexpr = ExpressionTool.make(path, sc, 0, -1, 0); System.out.println("Path: " + path); System.out.println("PathExpr: " + pathexpr); pathexpr.display(10, System.out, c.getConfiguration()); XPathContextMajor newctx = new XPathContextMajor(localnode, c.getConfiguration()); newctx.openStackFrame(c.getStackFrame().getStackFrameMap()); System.out.println("ContextItem: " + ((NodeInfo)newctx.getContextItem()).getDisplayName()); System.out.println("ContextSize: " + newctx.getLast()); SequenceIterator result = pathexpr.iterate(newctx); System.out.println("Evaluated: " + result); The error occurs when calling the pathexpr.iterator(<XPathContext>) method (obvious) . Does anyone knows what I'm doing wrong?


Replies (3)

Please register to reply

RE: Problem with FilterIterator - Added by Anonymous almost 18 years ago

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

You're using some very low-level interfaces here, so you need to be prepared to do some low-level debugging as well! I think the basic omission is that you have failed to run the typeCheck() method on the expression. This phase is mandatory, because it takes care of adding checks and conversions. In this particular case I think the failure arises because a node used in a comparison hasn't been atomized; it's the typeCheck phase that adds the atomizer to the expression tree. There's also an optimize() phase which in principle is optional, but I wouldn't guarantee that as Saxon always calls it. If your expression uses variables or variable references then you also need to call allocateSlots(). Use the source code of saxon:evaluate() to guide you. Alternatively, consider using a higher-level API such as the JAXP API which was explicitly designed as an external software interface.

RE: Problem with FilterIterator - Added by Anonymous almost 18 years ago

Legacy ID: #3821921 Legacy Poster: Jeroen Bulters (jeroenbulters)

I don't think a high-level API is the solution. I'm implementing a Transitive Closure function which is going to be benchmarked against traditional XPath methods of determining the closure of an expression (and a Node(Set)). Thanks for the pointers.

RE: Problem with FilterIterator - Added by Anonymous almost 18 years ago

Legacy ID: #3821927 Legacy Poster: Jeroen Bulters (jeroenbulters)

Thanks, I think I've got it all solved now. Adding the typeCheck(<ctx>, Type.ITEM_TYPE) worked out fine.. Now hope it passess all the TestCases ;-)

    (1-3/3)

    Please register to reply