Hello,

 

I am trying to resolve many xpath statements against a document. I have read the document into a SAXSource and am calling the method resolveXPath as below:

 

public ArrayList resolveXPath(String xpathStmt, SAXSource ss,XMLWrapperElement element ) throws Exception {

        ArrayList rtn = new ArrayList();

 

        XPathEvaluator xpe = new XPathEvaluator();

        if (element.getSchemaTargetNamespacePrefix() != null && element.getSchemaTargetNamespacePrefix().equals("") && element.getSchemaTargetNamespaceURI() != null) {

            ((IndependentContext)xpe.getStaticContext()).declareNamespace("", element.getSchemaTargetNamespaceURI());

        }else if (element.getSchemaTargetNamespacePrefix() != null && !element.getSchemaTargetNamespacePrefix().equals("") && element.getSchemaTargetNamespaceURI() != null) {

            ((IndependentContext)xpe.getStaticContext()).declareNamespace(element.getSchemaTargetNamespacePrefix(), element.getSchemaTargetNamespaceURI());

        }

        XPathExpression xExpr =  xpe.createExpression(xpathStmt);

        SequenceIterator rtns = xExpr.rawIterator(ss);

        Item xpathObj = rtns.next();

        while (xpathObj != null) {

            xpathObj = rtns.current();

            rtn.add(xpathObj.getStringValue());

            xpathObj = rtns.next();

        }

        return rtn;

    }

 

I get the following error. However, if I read the document everytime for an xpath statement, I don’t get the error, leading me to believe that the XPathExpression.rawIterator is corrupting the SAXSource. Am I making any mistake? How should I fix this?

 

 

 

Error

  SXXP0003: Error reported by XML parser: Premature end of file.

net.sf.saxon.trans.DynamicError: org.xml.sax.SAXParseException: Premature end of

 file.

        at net.sf.saxon.event.Sender.sendSAXSource(Sender.java:278)

        at net.sf.saxon.event.Sender.send(Sender.java:124)

        at net.sf.saxon.event.Sender.send(Sender.java:46)

        at net.sf.saxon.event.Builder.build(Builder.java:209)

        at net.sf.saxon.event.Builder.build(Builder.java:161)

        at net.sf.saxon.sxpath.XPathEvaluator.build(XPathEvaluator.java:92)

        at net.sf.saxon.sxpath.XPathExpression.rawIterator(XPathExpression.java:

135)