Search in sources :

Example 1 with XQueryEvaluatorSAXHandler

use of org.sirix.saxon.evaluator.XQueryEvaluatorSAXHandler in project sirix by sirixdb.

the class TestNodeWrapperS9ApiXQuerySAXHandler method testWhereBooks.

@Test
public void testWhereBooks() throws Exception {
    final StringBuilder strBuilder = new StringBuilder();
    final ContentHandler contHandler = new XMLFilterImpl() {

        @Override
        public void startElement(final String uri, final String localName, final String qName, final Attributes atts) throws SAXException {
            strBuilder.append("<" + localName);
            for (int i = 0; i < atts.getLength(); i++) {
                strBuilder.append(" " + atts.getQName(i));
                strBuilder.append("=\"" + atts.getValue(i) + "\"");
            }
            strBuilder.append(">");
        }

        @Override
        public void endElement(String uri, String localName, String qName) throws SAXException {
            strBuilder.append("</" + localName + ">");
        }

        @Override
        public void characters(final char[] ch, final int start, final int length) throws SAXException {
            for (int i = start; i < start + length; i++) {
                strBuilder.append(ch[i]);
            }
        }
    };
    new XQueryEvaluatorSAXHandler("for $x in /bookstore/book where $x/price>30 return $x/title", mHolder.getSession(), contHandler).call();
    assertEquals(strBuilder.toString(), "<title lang=\"en\">XQuery Kick Start</title><title lang=\"en\">Learning XML</title>");
}
Also used : XQueryEvaluatorSAXHandler(org.sirix.saxon.evaluator.XQueryEvaluatorSAXHandler) XMLFilterImpl(org.xml.sax.helpers.XMLFilterImpl) Attributes(org.xml.sax.Attributes) ContentHandler(org.xml.sax.ContentHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)1 XQueryEvaluatorSAXHandler (org.sirix.saxon.evaluator.XQueryEvaluatorSAXHandler)1 Attributes (org.xml.sax.Attributes)1 ContentHandler (org.xml.sax.ContentHandler)1 XMLFilterImpl (org.xml.sax.helpers.XMLFilterImpl)1