Package net.sf.saxon.event

## Class ComplexContentOutputter

- java.lang.Object
- - net.sf.saxon.event.Outputter
  - - net.sf.saxon.event.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.

- - ### Field Summary

    - ### Fields inherited from class net.sf.saxon.event.Outputter

      `pipelineConfiguration, systemId`

    - ### Fields inherited from interface javax.xml.transform.Result

      `PI_DISABLE_OUTPUT_ESCAPING, PI_ENABLE_OUTPUT_ESCAPING`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ComplexContentOutputter​(Receiver next)` | Create a ComplexContentOutputter

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `append​(Item item, Location locationId, int copyNamespaces)` | Append an arbitrary item (node or atomic value) to the output
    `void` | `attribute​(NodeName attName, SimpleType typeCode, java.lang.CharSequence value, Location locationId, int properties)` | Output an attribute value.
    `void` | `characters​(java.lang.CharSequence s, Location locationId, int properties)` | Produce text content output.
    `void` | `close()` | Close the output
    `void` | `comment​(java.lang.CharSequence comment, Location locationId, int properties)` | Write a comment
    `protected void` | `decompose​(Item item, Location locationId, int copyNamespaces)` | Helper method for subclasses to invoke if required: decompose an item into a sequence of node events.
    `void` | `endDocument()` | Notify the end of a document node
    `void` | `endElement()` | Output an element end tag.
    `protected void` | `flatten​(ArrayItem array, Location locationId, int copyNamespaces)` | Helper method for subclasses to invoke if required: flatten an array.
    `protected java.lang.String` | `getErrorCodeForDecomposingFunctionItems()` |
    `Receiver` | `getReceiver()` | Get the next receiver in the processing pipeline
    `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.
    `static ComplexContentOutputter` | `makeComplexContentReceiver​(Receiver receiver, ParseOptions options)` | Static factory method to create an push pipeline containing a ComplexContentOutputter
    `void` | `namespace​(java.lang.String prefix, java.lang.String namespaceUri, int properties)` | Add a namespace node to the content being constructed.
    `void` | `namespaces​(NamespaceBindingSet bindings, int properties)` | Output a set of namespace bindings.
    `void` | `open()` | Start the output process
    `void` | `processingInstruction​(java.lang.String target, java.lang.CharSequence data, Location locationId, int properties)` | Write a processing instruction
    `void` | `setHostLanguage​(HostLanguage language)` | Set the host language
    `void` | `setPipelineConfiguration​(PipelineConfiguration pipe)` | Set the pipeline configuration
    `void` | `setReceiver​(Receiver receiver)` | Set the receiver (to handle the next stage in the pipeline) directly
    `void` | `setSystemId​(java.lang.String systemId)` | Set the System ID of the tree represented by this event stream
    `void` | `setUnparsedEntity​(java.lang.String name, java.lang.String systemID, java.lang.String publicID)` | Notify an unparsed entity URI.
    `void` | `startContent()` | Flush out a pending start tag
    `void` | `startDocument​(int properties)` | Start of a document node.
    `void` | `startElement​(NodeName elemName, SchemaType type, AttributeMap attributes, NamespaceMap namespaces, Location location, int properties)` | Notify the start of an element.
    `void` | `startElement​(NodeName elemName, SchemaType typeCode, Location location, int properties)` | Output an element start tag.
    `boolean` | `usesTypeAnnotations()` | Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations supplied on element and attribute events

    - ### Methods inherited from class net.sf.saxon.event.Outputter

      `append, getConfiguration, getPipelineConfiguration, getSystemId`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface net.sf.saxon.event.Receiver

      `append, getPipelineConfiguration, handlesAppend`

    - ### Methods inherited from interface javax.xml.transform.Result

      `getSystemId`

- - ### 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

    - #### setPipelineConfiguration

          public void setPipelineConfiguration​(PipelineConfiguration pipe)

      Description copied from class: `Outputter`
      Set the pipeline configuration
      Specified by:
        `setPipelineConfiguration` in interface `Receiver`
      Overrides:
        `setPipelineConfiguration` in class `Outputter`
      Parameters:
        `pipe` - the pipeline configuration

    - #### 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

    - #### open

          public void open()
                    throws XPathException

      Start the output process
      Specified by:
        `open` in interface `Receiver`
      Overrides:
        `open` in class `Outputter`
      Throws:
        `XPathException` - if an error occurs

    - #### startDocument

          public void startDocument​(int properties)
                             throws XPathException

      Start of a document node.
      Specified by:
        `startDocument` in interface `Receiver`
      Specified by:
        `startDocument` in class `Outputter`
      Parameters:
        `properties` - any special properties of the node
      Throws:
        `XPathException` - if an error occurs

    - #### endDocument

          public void endDocument()
                           throws XPathException

      Notify the end of a document node
      Specified by:
        `endDocument` in interface `Receiver`
      Specified by:
        `endDocument` in class `Outputter`
      Throws:
        `XPathException` - if an error occurs

    - #### 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

    - #### endElement

          public void endElement()
                          throws XPathException

      Output an element end tag.
      Specified by:
        `endElement` in interface `Receiver`
      Specified by:
        `endElement` in class `Outputter`
      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

    - #### close

          public void close()
                     throws XPathException

      Close the output
      Specified by:
        `close` in interface `Receiver`
      Overrides:
        `close` in class `Outputter`
      Throws:
        `XPathException` - if an error occurs

    - #### startContent

          public void startContent()
                            throws XPathException

      Flush out a pending start tag
      Overrides:
        `startContent` in class `Outputter`
      Throws:
        `XPathException` - if an error occurs

    - #### 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()