Package xbird.xquery.dm.ser

Examples of xbird.xquery.dm.ser.Serializer


        XQueryProcessor proc = new XQueryProcessor();
        InputStream input = new ByteArrayInputStream(query.getBytes("UTF-8"));
        XQueryModule module = proc.parse(input);
        StringWriter writer = new StringWriter(8192);
        SAXWriter saxwr = new SAXWriter(writer);
        Serializer ser = new SAXSerializer(saxwr, writer);
        //ser.setInterveBlanks(false);
        proc.execute(module, ser);
        return writer.toString();
    }
View Full Code Here


        // prepare SAX result handler
        Writer writer = new NoopWriter();
        SAXWriter saxHandler = new SAXWriter(writer, "UTF-8"); // SAXWriter implements ContentHandler
        saxHandler.setPrettyPrint(true); // enabled formatting
        saxHandler.setXMLDeclaration(true); // insert XML declaration to output
        Serializer ser = new SAXSerializer(saxHandler);
        ser.emit(result); // emit SAX events to SAX handler

        for(Item item : result) {// Note that every Sequence instances implement Iterable.
            // get string value
            String stringValue = item.stringValue();
            // get type
            Type itemType = item.getType();
            if(TypeUtil.subtypeOf(itemType, NodeType.ELEMENT)) {
                // the Item is element               
            } else if(TypeUtil.instanceOf(item, NodeType.TEXT)) {
                // another variant
            }

            // print string value
            System.out.println(item); // item.toString() invokes item.stringValue()

            // Item is subclass of Sequence, thus it can also be converted to SAX events.
            ser.emit(item);
        }

        // The above 'for each' is equivalent to the following expression.
        IFocus focus = result.iterator(); // IFocus extends Iterable
        while(result.next(focus)) {
View Full Code Here

                        try {
                            XQueryModule mod = proc.parse(query, baseUri);
                            Sequence result = proc.execute(mod);
                            SAXWriter saxwriter = new SAXWriter(res_sw, SAXWriter.DEFAULT_ENCODING);
                            saxwriter.setXMLDeclaration(false);
                            Serializer ser = new SAXSerializer(saxwriter, res_sw);
                            ser.emit(result);
                        } catch (Throwable ex) {
                            final int errors = expectedErrors.getLength();
                            if(errors == 0) {
                                final Node expectedOutputs = (Node) xpath.evaluate("./*[local-name()='output-file'][last()]", testCase, XPathConstants.NODE);
                                assert (expectedOutputs != null);
View Full Code Here

                    try {
                        XQueryModule mod = proc.parse(query, baseUri);
                        Sequence result = proc.execute(mod);
                        SAXWriter saxwriter = new SAXWriter(res_sw, SAXWriter.DEFAULT_ENCODING);
                        saxwriter.setXMLDeclaration(false);
                        Serializer ser = new SAXSerializer(saxwriter, res_sw);
                        ser.emit(result);
                    } catch (Throwable ex) {
                        final int errors = expectedErrors.getLength();
                        if(errors == 0) {
                            final Node expectedOutputs = (Node) xpath.evaluate("./*[local-name()='output-file'][last()]", testCase, XPathConstants.NODE);
                            assert (expectedOutputs != null);
View Full Code Here

        // parse
        XQueryModule mod = processor.parse(queryStr, new File(queryFilePath).toURI());
        // execute              
        FastMultiByteArrayOutputStream out = new FastMultiByteArrayOutputStream();
        SAXWriter writer = new SAXWriter(out, "UTF-8");
        final Serializer ser = new SAXSerializer(writer);
        Sequence<? extends Item> result = processor.execute(mod);
        ser.emit(result);
        writer.flush();

        System.err.println(sw);
        return out.toString();
    }
View Full Code Here

        String query = IOUtils.toString(new FileInputStream(fileName));
        QueryRequest request = new QueryRequest(query, ReturnType.ASYNC_REMOTE_SEQUENCE);
        Sequence<Item> resultSeq = (Sequence<Item>) engine.execute(request);
        Writer writer = new NoopWriter();
        SAXWriter saxwr = new SAXWriter(writer, "UTF-8");
        Serializer ser = new SAXSerializer(saxwr, writer);
        ser.emit(resultSeq);
    }
View Full Code Here

        // parse
        XQueryModule mod = processor.parse(queryStr, new File(queryFilePath).toURI());
        // execute
        FastMultiByteArrayOutputStream out = new FastMultiByteArrayOutputStream();
        SAXWriter writer = new SAXWriter(out, "UTF-8");
        final Serializer ser = new SAXSerializer(writer);
        Sequence<? extends Item> result = processor.execute(mod);
        ser.emit(result);
        //processor.execute(mod, ser);
        writer.flush();

        System.err.println(sw);
        return out.toString();
View Full Code Here

        queryFile = XMARK_HOME + '/' + queryFile;
        final XQueryProcessor processor = new XQueryProcessor();       
        XQueryModule mod = processor.parse(new FileInputStream(queryFile), new File(queryFile).toURI());
        Sequence result = processor.execute(mod);
        StringWriter res_sw = new StringWriter();
        final Serializer ser = new SAXSerializer(new SAXWriter(res_sw), res_sw);       
        ser.emit(result);
        String swresult = sw.toString();
        long used = SystemUtils.getHeapUsedMemory();
        stdbuf.append(", used(before GC): " + StringUtils.displayBytesSize(used));
        if(RUN_ONLY) {
            res_sw.close();
View Full Code Here

            reportError("Execution failed: " + queryPath, e, out);
            return;
        }
        // serialize       
        SAXWriter writer = new SAXWriter(out);
        Serializer ser = new SAXSerializer(writer);
        try {
            ser.emit(result);
        } catch (XQueryException e) {
            reportError("Serialization failed: " + queryPath, e, out);
            return;
        }
    }
View Full Code Here

                writer.write("<root>\n");
            } catch (IOException e) {
                throw new IllegalStateException(e);
            }
        }
        Serializer ser = new SAXSerializer(saxwr, writer);
        proc.execute(module, ser);
        if(_wrap) {
            try {
                writer.write("\n</root>\n");
            } catch (IOException e) {
View Full Code Here

TOP

Related Classes of xbird.xquery.dm.ser.Serializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.