Project

Profile

Help

SAXPath in SAXON API available ?

Added by Anonymous almost 15 years ago

Legacy ID: #7434219 Legacy Poster: Andre (andre007)

Hello, I want to build a XPath Wizard for creating xpath expressions and parsing xpath expression for better visualizing. My target is to parse XPath 2.0 expressions, too. Jaxen SAXPath has only XPath 1.0 support. ->>Does anybody know if Saxon offers XPath parsing events ?? Thx, Regards, Andre, Berlin


Replies (9)

Please register to reply

RE: SAXPath in SAXON API available ? - Added by Anonymous almost 15 years ago

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

You can parse XPath 2.0 expressions using Saxon - I would recommend using the s9api interface net.sf.saxon.s9api.XPathCompiler - though lower-level constructs are also available. If you want to examine the compiled form of the expression, I would recommend using the explain() interface on the class Expression, which essentially gives you an XML representation of the expression tree.

RE: SAXPath in SAXON API available ? - Added by Anonymous almost 15 years ago

Legacy ID: #7436019 Legacy Poster: Andre (andre007)

I think the problem is the execution plan optimsation : /a/b[true][false] .. would not explain the true predicate, but we need that. Currently I make some tries with PsychoPath Xpath parser.. May a Saxon parsing API would be a nice thing.. regards , Andre

RE: SAXPath in SAXON API available ? - Added by Anonymous almost 15 years ago

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

If you dive in at a slightly lower level, it should be possible to call explain() before calling optimize(), giving something closer to the expression as originally written. However, some basic optimizations (for example, replacing the function call true() by the constant value true) are done at a very early stage. You haven't really explained what you are trying to achieve, so it's hard to give you advice.

RE: SAXPath in SAXON API available ? - Added by Anonymous almost 15 years ago

Legacy ID: #7436130 Legacy Poster: Andre (andre007)

thx for your good advises ! I think exculde optimize() could be a appropriate way . The main target is to develop an XPath Wizard where I can fully define XPath 2.0 expressions via GUI by mouse, saving that expression and edit visually that expression later in that gui again. For re-editing that expression Xpath 2.0 parsing with events/expressionXML is requiered. pse see that minimal xpath 1.0 wizard: http://www.windwardreports.com/mktg/Videos/XPath%20Wizard/XPath%20Wizard.html That is only a subset of xpath 1.0. We want to provide a wizard with complete xpath 2.0 Syntax. But the winward sollution is much to minimal. -> We will correct this. Thank you Michael for that everytime best support ! I think we have clarified all here. Regards, Andre, Berlin ps: If you remember. I've contact you directly for multithreaded directory scanning within Saxon. You said we are working on that. Is the a new state and is there a plan for Saxon-B ?) rgs!

RE: SAXPath in SAXON API available ? - Added by Anonymous almost 15 years ago

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

>I've contact you directly for multithreaded directory scanning within Saxon. You'll have to remind me of the question. Please start a new thread!

RE: SAXPath in SAXON API available ? - Added by Anonymous almost 15 years ago

Legacy ID: #7436592 Legacy Poster: Andre (andre007)

Ive problem getting an implementation of Expression : java.lang.ClassCastException: net.sf.saxon.xpath.XPathExpressionImpl cannot be cast to net.sf.saxon.expr.Expression .. using the net.sf.saxon.xpath.XPathFactoryImpl it would be nice when you can offer a little advise how to get an impl of Expression by a string xpath.. my current way is: System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON, "net.sf.saxon.xpath.XPathFactoryImpl"); ByteArrayOutputStream op = new ByteArrayOutputStream(); javax.xml.xpath.XPath xpathEvaluator = net.sf.saxon.xpath.XPathFactoryImpl.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON).newXPath(); net.sf.saxon.expr.Expression expr = (net.sf.saxon.expr.Expression)((net.sf.saxon.xpath.XPathEvaluator)xpathEvaluator).compile("/a/b[c > 1]"); expr.explain(op); Tracer.debug("parsed:"+op.toString());

RE: SAXPath in SAXON API available ? - Added by Anonymous almost 15 years ago

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

net.sf.saxon.xpath.XPathExpressionImpl is a wrapper around Saxon's Expression object to make it satisfy the JAXP interface. You can get the underlying net.sf.saxon.expr.Expression by calling the method getInternalExpression().

RE: SAXPath in SAXON API available ? - Added by Anonymous almost 15 years ago

Legacy ID: #7438058 Legacy Poster: Andre (andre007)

Thanks : System.setProperty("javax.xml.xpath.XPathFactory:" + NamespaceConstant.OBJECT_MODEL_SAXON, "net.sf.saxon.xpath.XPathFactoryImpl"); ByteArrayOutputStream op = new ByteArrayOutputStream(); javax.xml.xpath.XPath xpathEvaluator = net.sf.saxon.xpath.XPathFactoryImpl.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON).newXPath(); net.sf.saxon.expr.Expression expr = ((net.sf.saxon.xpath.XPathExpressionImpl)((net.sf.saxon.xpath.XPathEvaluator)xpathEvaluator).compile("/a/b[true][false]")).getInternalExpression(); expr.explain(op); Tracer.debug("parsed:"+op.toString()); will produce an unoptimized execution plan : <path> <path> <root/> <axis name="child" nodeTest="element(a, xs:anyType)"/> </path> <filterExpression> <filterExpression> <axis name="child" nodeTest="element(b, xs:anyType)"/> <axis name="child" nodeTest="element(true, xs:anyType)"/> </filterExpression> <axis name="child" nodeTest="element(false, xs:anyType)"/> </filterExpression> </path>

RE: SAXPath in SAXON API available ? - Added by Anonymous almost 15 years ago

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

It might be worth testing what happens when you replace [true][false] with [true()][false()]

    (1-9/9)

    Please register to reply