Xpath query

Help
2006-11-20
2013-06-04
  • Shailesh Raj

    Shailesh Raj - 2006-11-20

    Dear All,
    I want to use Xpath engine which uses SAX parser to qury XML. For that I am using Saxon.
    After evaluating Xpath query result of Xpath query should be displayed as XML (including node value as well as node name) so I am using transformation on result of Xpath.
    Here is 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();
    ---------------------------------------------------------------------------------------
    When I run this code I get 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)

    --------------------------------------------------------------------------------------

    Please let me know what is wrong with code/approach.
    Thanks
    Shailesh

     
    • Franck

      Franck - 2006-11-20

      TurckMMCache is no longer maintened.

      Please use eAccelerator, which is the officiel fork of TurckMMCache.

      http://eaccelerator.net/

      Bests Regards,
      Franck34

       

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks