/BusinessMotivations/" is not a valid XPath expression, so an XPathExpressionException is exactly what you should get.
 
/xmi:XMI/XMI.content[@template='design summary.dot']”  is a valid XPath expression only if you have declared the "xmi" namespace prefix.
 
If you need help with errors such as these, it always helps to quote the error message.
 
Michael Kay
http://www.saxonica.com/


From: saxon-help-bounces@lists.sourceforge.net [mailto:saxon-help-bounces@lists.sourceforge.net] On Behalf Of Raj, Shailesh
Sent: 21 November 2006 11:26
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] Xapth Query

It worked I explicitly loaded Saxon TransformerFactory.

I am facing another problem now. In the same code given below Xpath can be “/BusinessMotivations/”, “/xmi:XMI/XMI.content[@template='design summary.dot']” etc.

But with these Xpath it throws XPathExpressionException.

 

Any help on this.

 

Regards

Shailesh


From: Raj, Shailesh
Sent: Monday, November 20, 2006 9:38 AM
To: 'saxon-help@lists.sourceforge.net'
Subject: Xapth Query

 

Dear All,

I want to write one program which evaluates Xpath using SAX parser. For that I am using Xpath engine implemented by Saxon.

I want to value of Xpath with node name information not only node value. To get node name I am using transformer. This is following code.

XPathFactory xpf = XPathFactory.newInstance(NamespaceConstant.OBJECT_MODEL_SAXON);

        XPath xpe = xpf.newXPath();

        System.err.println("Loaded XPath Provider " + xpe.getClass().getName());

 

        InputSource is = new InputSource(new File(filename).toURL().toString());

        SAXSource ss = new SAXSource(is);

        NodeInfo doc = ((XPathEvaluator)xpe).setSource(ss);

 

        XPathExpression findLine = xpe.compile(xpath);

     

        TransformerFactory f = TransformerFactory.newInstance();

        Transformer t = f.newTransformer();

       

        NodeInfo node = (NodeInfo)findLine.evaluate(doc, XPathConstants.NODE);

        StringWriter sw = new StringWriter();

       

        t.transform(node, new StreamResult(sw));

       

        String result = sw.toString();

 

 

But this code is giving following exception

javax.xml.transform.TransformerException: Can't transform a Source of type net.sf.saxon.tinytree.TinyDocumentImpl

      at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:418)

 

 

Anybody can let me know what is wrong with code or approach?

Regards

Shailesh