Class ComplexContentOutputter

  • All Implemented Interfaces:
    javax.xml.transform.Result, Receiver

    public final class ComplexContentOutputter
    extends Outputter
    implements Receiver, javax.xml.transform.Result
    This class is used for generating complex content, that is, the content of an element or document node. It enforces the rules on the order of events within complex content (attributes and namespaces must come first), and it implements part of the namespace fixup rules, in particular, it ensures that there is a namespace node for the namespace used in the element name and in each attribute name.

    The same ComplexContentOutputter may be used for generating an entire XML document; it is not necessary to create a new outputter for each element node.

    From Saxon 9.9, the ComplexContentOutputter does not combine top-level events. Unless nested within a startDocument/endDocument or startElement/endElement pair, items such as atomic values, text nodes, attribute nodes, maps and arrays are passed through unchanged to the output. It is typically the responsibility of the Destination object to decide how to combine top-level events (whether to build a single document, whether to insert item separators, etc).

    From Saxon 10.0, the handling of namespaces changes. Unlike other receivers, the ComplexContentOutputter can receive individual namespace events as part of the complex content of an element node. The class is now fully responsible for namespace fixup and for namespace inheritance. The mechanism for namespace inheritance is changed; we are now maintaining all the in-scope namespaces for an element rather than a set of deltas, so namespace inheritance (rather than disinheritance) now requires concrete action.

    • Constructor Detail

      • ComplexContentOutputter

        public ComplexContentOutputter​(Receiver next)
        Create a ComplexContentOutputter
        Parameters:
        next - the next receiver in the pipeline
    • Method Detail

      • makeComplexContentReceiver

        public static ComplexContentOutputter makeComplexContentReceiver​(Receiver receiver,
                                                                         ParseOptions options)
        Static factory method to create an push pipeline containing a ComplexContentOutputter
        Parameters:
        receiver - the destination to which the constructed complex content will be written
        options - options for validating the output stream; may be null
        Returns:
        the new ComplexContentOutputter at the head of the constructed pipeline
      • setSystemId

        public void setSystemId​(java.lang.String systemId)
        Description copied from class: Outputter
        Set the System ID of the tree represented by this event stream
        Specified by:
        setSystemId in interface Receiver
        Specified by:
        setSystemId in interface javax.xml.transform.Result
        Overrides:
        setSystemId in class Outputter
        Parameters:
        systemId - the system ID (which is used as the base URI of the nodes if there is no xml:base attribute)
      • setHostLanguage

        public void setHostLanguage​(HostLanguage language)
        Set the host language
        Parameters:
        language - the host language, for example HostLanguage.XQUERY
      • setReceiver

        public void setReceiver​(Receiver receiver)
        Set the receiver (to handle the next stage in the pipeline) directly
        Parameters:
        receiver - the receiver to handle the next stage in the pipeline
      • getReceiver

        public Receiver getReceiver()
        Get the next receiver in the processing pipeline
        Returns:
        the receiver which this ComplexContentOutputter writes to
      • setUnparsedEntity

        public void setUnparsedEntity​(java.lang.String name,
                                      java.lang.String systemID,
                                      java.lang.String publicID)
                               throws XPathException
        Notify an unparsed entity URI.
        Specified by:
        setUnparsedEntity in interface Receiver
        Overrides:
        setUnparsedEntity in class Outputter
        Parameters:
        name - The name of the unparsed entity
        systemID - The system identifier of the unparsed entity
        publicID - The public identifier of the unparsed entity
        Throws:
        XPathException - if an error occurs
      • characters

        public void characters​(java.lang.CharSequence s,
                               Location locationId,
                               int properties)
                        throws XPathException
        Produce text content output.
        Special characters are escaped using XML/HTML conventions if the output format requires it.
        Specified by:
        characters in interface Receiver
        Specified by:
        characters in class Outputter
        Parameters:
        s - The String to be output
        locationId - the location of the node in the source, or of the instruction that created it
        properties - any special properties of the node
        Throws:
        XPathException - for any failure
      • startElement

        public void startElement​(NodeName elemName,
                                 SchemaType typeCode,
                                 Location location,
                                 int properties)
                          throws XPathException
        Output an element start tag.
        The actual output of the tag is deferred until all attributes have been output using attribute().
        Specified by:
        startElement in class Outputter
        Parameters:
        elemName - The element name
        location - the location of the element node (or the instruction that created it)
        properties - any special properties of the node
        typeCode - the type annotation of the element.
        Throws:
        XPathException - if an error occurs
      • namespace

        public void namespace​(java.lang.String prefix,
                              java.lang.String namespaceUri,
                              int properties)
                       throws XPathException
        Add a namespace node to the content being constructed.
        Specified by:
        namespace in class Outputter
        Parameters:
        prefix - The namespace prefix; zero-length string for the default namespace
        namespaceUri - The namespace URI. In some cases a zero-length string may be used to indicate a namespace undeclaration.
        properties - The REJECT_DUPLICATES property: if set, the namespace declaration will be rejected if it conflicts with a previous declaration of the same prefix. If the property is not set, the namespace declaration will be ignored if it conflicts with a previous declaration. This reflects the fact that when copying a tree, namespaces for child elements are emitted before the namespaces of their parent element. Unfortunately this conflicts with the XSLT rule for complex content construction, where the recovery action in the event of conflicts is to take the namespace that comes last. XSLT therefore doesn't recover from this error:
        Throws:
        XPathException - if an error occurs
      • namespaces

        public void namespaces​(NamespaceBindingSet bindings,
                               int properties)
                        throws XPathException
        Output a set of namespace bindings. This should have the same effect as outputting the namespace bindings individually using namespace(String, String, int), but it may be more efficient. It is used only when copying an element node together with all its namespaces, so less checking is needed that the namespaces form a consistent and complete set
        Overrides:
        namespaces in class Outputter
        Parameters:
        bindings - the set of namespace bindings
        properties - any special properties. The property ReceiverOption.NAMESPACE_OK means that no checking is needed.
        Throws:
        XPathException - if any failure occurs
      • attribute

        public void attribute​(NodeName attName,
                              SimpleType typeCode,
                              java.lang.CharSequence value,
                              Location locationId,
                              int properties)
                       throws XPathException
        Output an attribute value.

        This is added to a list of pending attributes for the current start tag, overwriting any previous attribute with the same name. But in XQuery, duplicate attributes are reported as an error.

        This method must NOT be used to output namespace declarations.

        Specified by:
        attribute in class Outputter
        Parameters:
        attName - The name of the attribute
        value - The value of the attribute
        locationId - the location of the node in the source, or of the instruction that created it
        properties - Bit fields containing properties of the attribute to be written @throws XPathException if there is no start tag to write to (created using writeStartTag),
        typeCode - The type annotation of the attribute
        Throws:
        XPathException - if an error occurs
      • startElement

        public void startElement​(NodeName elemName,
                                 SchemaType type,
                                 AttributeMap attributes,
                                 NamespaceMap namespaces,
                                 Location location,
                                 int properties)
                          throws XPathException
        Notify the start of an element. This version of the method supplies all attributes and namespaces and implicitly invokes startContent(), which means it cannot be followed by further calls on attribute(NodeName, SimpleType, CharSequence, Location, int) or namespace(java.lang.String, java.lang.String, int) to define further attributes and namespaces.

        This version of the method does not perform namespace fixup for prefixes used in the element name or attribute names; it is assumed that these prefixes are declared within the namespace map, and that there are no conflicts. The method does, however, perform namespace inheritance: that is, unless properties includes ReceiverOption.DISINHERIT_NAMESPACES, namespaces declared on the parent element and not overridden are implicitly added to the namespace map.

        Specified by:
        startElement in interface Receiver
        Overrides:
        startElement in class Outputter
        Parameters:
        elemName - the name of the element.
        type - the type annotation of the element.
        attributes - the attributes of this element
        namespaces - the in-scope namespaces of this element: generally this is all the in-scope namespaces, without relying on inheriting namespaces from parent elements
        location - an object providing information about the module, line, and column where the node originated
        properties - bit-significant properties of the element node. If there are no relevant properties, zero is supplied. The definitions of the bits are in class ReceiverOption
        Throws:
        XPathException - if an error occurs
      • comment

        public void comment​(java.lang.CharSequence comment,
                            Location locationId,
                            int properties)
                     throws XPathException
        Write a comment
        Specified by:
        comment in interface Receiver
        Specified by:
        comment in class Outputter
        Parameters:
        comment - The content of the comment
        locationId - provides information such as line number and system ID.
        properties - Additional information about the comment.
        Throws:
        XPathException - if an error occurs
      • processingInstruction

        public void processingInstruction​(java.lang.String target,
                                          java.lang.CharSequence data,
                                          Location locationId,
                                          int properties)
                                   throws XPathException
        Write a processing instruction
        Specified by:
        processingInstruction in interface Receiver
        Specified by:
        processingInstruction in class Outputter
        Parameters:
        target - The PI name. This must be a legal name (it will not be checked).
        data - The data portion of the processing instruction
        locationId - provides information such as line number and system ID.
        properties - Additional information about the PI.
        Throws:
        XPathException - if an error occurs
      • append

        public void append​(Item item,
                           Location locationId,
                           int copyNamespaces)
                    throws XPathException
        Append an arbitrary item (node or atomic value) to the output
        Specified by:
        append in interface Receiver
        Overrides:
        append in class Outputter
        Parameters:
        item - the item to be appended
        locationId - the location of the calling instruction, for diagnostics
        copyNamespaces - if the item is an element node, this indicates whether its namespaces need to be copied. Values are ReceiverOption.ALL_NAMESPACES}; the default (0) means
        Throws:
        XPathException - if an error occurs
      • getStringReceiver

        public CharSequenceConsumer getStringReceiver​(boolean asTextNode,
                                                      Location loc)
        Get a string-value consumer object that allows an item of type xs:string to be appended one fragment at a time. This potentially allows operations that output large strings to avoid building the entire string in memory. This version of the method, if called at an inner level, outputs the string as a sequence of characters() events, with logic to include space separation where appropriate
        Overrides:
        getStringReceiver in class Outputter
        Parameters:
        asTextNode - set to true if the concatenated string values are to be treated as a text node
        loc - the location of the instruction that generates the content
        Returns:
        an object that accepts xs:string values via a sequence of append() calls
      • usesTypeAnnotations

        public boolean usesTypeAnnotations()
        Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations supplied on element and attribute events
        Specified by:
        usesTypeAnnotations in interface Receiver
        Overrides:
        usesTypeAnnotations in class Outputter
        Returns:
        true if the Receiver makes any use of this information. If false, the caller may supply untyped nodes instead of supplying the type annotation
      • flatten

        protected void flatten​(ArrayItem array,
                               Location locationId,
                               int copyNamespaces)
                        throws XPathException
        Helper method for subclasses to invoke if required: flatten an array. The effect is that each item in each member of the array is appended to this ComplexContentOutputter by calling its method
        Parameters:
        array - the array to be flattened
        locationId - the location of the instruction triggering this operation
        copyNamespaces - options for copying namespace nodes
        Throws:
        XPathException - if anything goes wrong
      • decompose

        protected void decompose​(Item item,
                                 Location locationId,
                                 int copyNamespaces)
                          throws XPathException
        Helper method for subclasses to invoke if required: decompose an item into a sequence of node events. Note that when this is used, methods such as characters(), comment(), startElement(), and processingInstruction() are responsible for setting previousAtomic to false.
        Parameters:
        item - the item to be decomposed into a sequence of events
        locationId - the location of the requesting instruction
        copyNamespaces - options for copying namespace nodes
        Throws:
        XPathException
      • getErrorCodeForDecomposingFunctionItems

        protected java.lang.String getErrorCodeForDecomposingFunctionItems()