All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.saxon.evpull.EventIteratorToReceiver Maven / Gradle / Ivy

Go to download

Provides a basic XSLT 2.0 and XQuery 1.0 processor (W3C Recommendations, January 2007). Command line interfaces and implementations of several Java APIs (DOM, XPath, s9api) are also included.

The newest version!
package net.sf.saxon.evpull;

import net.sf.saxon.event.ReceiverOptions;
import net.sf.saxon.event.SequenceReceiver;
import net.sf.saxon.om.*;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.type.Type;

import java.util.Iterator;

/**
 * Class to read pull events from an EventIterator and write them to a Receiver
 */
public class EventIteratorToReceiver {

    /**
     * Private constructor: this class holds static methods only
     */

    private EventIteratorToReceiver() {}

    /**
     * Read the data obtained from an EventIterator and write the same data to a SequenceReceiver
     * @param in the input EventIterator
     * @param out the output Receiver
     * @throws XPathException
     */

    public static void copy(EventIterator in, SequenceReceiver out) throws XPathException {
        in = EventStackIterator.flatten(in);
        int level = 0;
        out.open();
        while (true) {
            PullEvent event = in.next();
            if (event == null) {
                break;
            }
            if (event instanceof Orphan && ((Orphan)event).getNodeKind() == Type.TEXT) {
                out.characters(((Orphan)event).getStringValueCS(), 0, 0);
            } else if (event instanceof DocumentInfo && level > 0) {
                AxisIterator kids = ((DocumentInfo)event).iterateAxis(Axis.CHILD);
                while (true) {
                    NodeInfo node = (NodeInfo)kids.next();
                    if (node == null) {
                        break;
                    }
                    out.append(node, 0, 0);
                }
            } else if (event instanceof Item) {
                out.append((Item)event, 0, NodeInfo.ALL_NAMESPACES);
            } else if (event instanceof StartElementEvent) {
                StartElementEvent see = (StartElementEvent)event;
                level++;
                out.startElement(see.getNameCode(), see.getTypeCode(), 0, ReceiverOptions.NAMESPACE_OK);
                int[] localNamespaces = see.getLocalNamespaces();
                for (int n=0; n




© 2015 - 2025 Weber Informatics LLC | Privacy Policy