Class ComplexContentOutputter
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 -
Method Summary
Modifier and TypeMethodDescriptionvoid
Append an arbitrary item (node or atomic value) to the outputvoid
attribute
(NodeName attName, SimpleType typeCode, String value, Location locationId, int properties) Output an attribute value.void
characters
(UnicodeString s, Location locationId, int properties) Produce text content output.void
close()
Close the outputvoid
comment
(UnicodeString comment, Location locationId, int properties) Write a commentvoid
Notify the end of a document nodevoid
Output an element end tag.Get the next receiver in the processing pipelinegetStringReceiver
(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 ComplexContentOutputtervoid
namespace
(String prefix, NamespaceUri 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 processvoid
processingInstruction
(String target, UnicodeString data, Location locationId, int properties) Write a processing instructionvoid
setHostLanguage
(HostLanguage language) Set the host languagevoid
Set the pipeline configurationvoid
setReceiver
(Receiver receiver) Set the receiver (to handle the next stage in the pipeline) directlyvoid
setSystemId
(String systemId) Set the System ID of the tree represented by this event streamvoid
setUnparsedEntity
(String name, String systemID, String publicID) Notify an unparsed entity URI.void
Flush out a pending start tagvoid
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
Ask whether this Receiver (or the downstream pipeline) makes any use of the type annotations supplied on element and attribute eventsMethods inherited from class net.sf.saxon.event.Outputter
append, getConfiguration, getPipelineConfiguration, getSystemId, spreadStartElement
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 Details
-
ComplexContentOutputter
Create a ComplexContentOutputter- Parameters:
next
- the next receiver in the pipeline
-
-
Method Details
-
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 writtenoptions
- options for validating the output stream; may be null- Returns:
- the new ComplexContentOutputter at the head of the constructed pipeline
-
setPipelineConfiguration
Description copied from class:Outputter
Set the pipeline configuration- Specified by:
setPipelineConfiguration
in interfaceReceiver
- Overrides:
setPipelineConfiguration
in classOutputter
- Parameters:
pipe
- the pipeline configuration
-
setSystemId
Description copied from class:Outputter
Set the System ID of the tree represented by this event stream- Specified by:
setSystemId
in interfaceResult
- Overrides:
setSystemId
in classOutputter
- Parameters:
systemId
- the system ID (which is used as the base URI of the nodes if there is no xml:base attribute)
-
setHostLanguage
Set the host language- Parameters:
language
- the host language, for exampleHostLanguage.XQUERY
-
setReceiver
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
Get the next receiver in the processing pipeline- Returns:
- the receiver which this ComplexContentOutputter writes to
-
open
Start the output process- Specified by:
open
in interfaceReceiver
- Overrides:
open
in classOutputter
- Throws:
XPathException
- if an error occurs
-
startDocument
Start of a document node.- Specified by:
startDocument
in interfaceReceiver
- Specified by:
startDocument
in classOutputter
- Parameters:
properties
- any special properties of the node- Throws:
XPathException
- if an error occurs
-
endDocument
Notify the end of a document node- Specified by:
endDocument
in interfaceReceiver
- Specified by:
endDocument
in classOutputter
- Throws:
XPathException
- if an error occurs
-
setUnparsedEntity
Notify an unparsed entity URI.- Specified by:
setUnparsedEntity
in interfaceReceiver
- Overrides:
setUnparsedEntity
in classOutputter
- Parameters:
name
- The name of the unparsed entitysystemID
- The system identifier of the unparsed entitypublicID
- The public identifier of the unparsed entity- Throws:
XPathException
- if an error occurs
-
characters
Produce text content output.
Special characters are escaped using XML/HTML conventions if the output format requires it.- Specified by:
characters
in interfaceReceiver
- Specified by:
characters
in classOutputter
- Parameters:
s
- The String to be outputlocationId
- the location of the node in the source, or of the instruction that created itproperties
- 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 classOutputter
- Parameters:
elemName
- The element nametypeCode
- the type annotation of the element.location
- the location of the element node (or the instruction that created it)properties
- any special properties of the node- Throws:
XPathException
- if an error occurs
-
namespace
public void namespace(String prefix, NamespaceUri namespaceUri, int properties) throws XPathException Add a namespace node to the content being constructed.- Specified by:
namespace
in classOutputter
- Parameters:
prefix
- The namespace prefix; zero-length string for the default namespacenamespaceUri
- 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
Output a set of namespace bindings. This should have the same effect as outputting the namespace bindings individually usingOutputter.namespace(String, NamespaceUri, 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 classOutputter
- Parameters:
bindings
- the set of namespace bindingsproperties
- any special properties. The propertyReceiverOption.NAMESPACE_OK
means that no checking is needed.- Throws:
XPathException
- if any failure occurs
-
attribute
public void attribute(NodeName attName, SimpleType typeCode, String 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 classOutputter
- Parameters:
attName
- The name of the attributetypeCode
- The type annotation of the attributevalue
- The value of the attributelocationId
- the location of the node in the source, or of the instruction that created itproperties
- Bit fields containing properties of the attribute to be written @throws XPathException if there is no start tag to write to (created using writeStartTag),- 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 invokesstartContent()
, which means it cannot be followed by further calls onOutputter.attribute(NodeName, SimpleType, String, Location, int)
orOutputter.namespace(java.lang.String, net.sf.saxon.om.NamespaceUri, 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
includesReceiverOption.DISINHERIT_NAMESPACES
, namespaces declared on the parent element and not overridden are implicitly added to the namespace map.- Specified by:
startElement
in interfaceReceiver
- Overrides:
startElement
in classOutputter
- Parameters:
elemName
- the name of the element.type
- the type annotation of the element.attributes
- the attributes of this elementnamespaces
- the in-scope namespaces of this element: generally this is all the in-scope namespaces, without relying on inheriting namespaces from parent elementslocation
- an object providing information about the module, line, and column where the node originatedproperties
- bit-significant properties of the element node. If there are no relevant properties, zero is supplied. The definitions of the bits are in classReceiverOption
- Throws:
XPathException
- if an error occurs
-
endElement
Output an element end tag.- Specified by:
endElement
in interfaceReceiver
- Specified by:
endElement
in classOutputter
- Throws:
XPathException
- if an error occurs
-
comment
public void comment(UnicodeString comment, Location locationId, int properties) throws XPathException Write a comment- Specified by:
comment
in interfaceReceiver
- Specified by:
comment
in classOutputter
- Parameters:
comment
- The content of the commentlocationId
- 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(String target, UnicodeString data, Location locationId, int properties) throws XPathException Write a processing instruction- Specified by:
processingInstruction
in interfaceReceiver
- Specified by:
processingInstruction
in classOutputter
- Parameters:
target
- The PI name. This must be a legal name (it will not be checked).data
- The data portion of the processing instructionlocationId
- provides information such as line number and system ID.properties
- Additional information about the PI.- Throws:
XPathException
- if an error occurs
-
append
Append an arbitrary item (node or atomic value) to the output- Specified by:
append
in interfaceReceiver
- Overrides:
append
in classOutputter
- Parameters:
item
- the item to be appendedlocationId
- the location of the calling instruction, for diagnosticscopyNamespaces
- if the item is an element node, this indicates whether its namespaces need to be copied. Values areReceiverOption.ALL_NAMESPACES
}; the default (0) means- Throws:
XPathException
- if an error occurs
-
getStringReceiver
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 classOutputter
- Parameters:
asTextNode
- set to true if the concatenated string values are to be treated * as a text node item rather than a string- Returns:
- an object that accepts xs:string values via a sequence of append() calls
-
close
Close the output- Specified by:
close
in interfaceReceiver
- Overrides:
close
in classOutputter
- Throws:
XPathException
- if an error occurs
-
startContent
Flush out a pending start tag- Overrides:
startContent
in classOutputter
- 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 interfaceReceiver
- Overrides:
usesTypeAnnotations
in classOutputter
- 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
-