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
-
-
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 outputvoid
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 outputvoid
comment(java.lang.CharSequence comment, Location locationId, int properties)
Write a commentprotected 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 nodevoid
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 pipelineCharSequenceConsumer
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 ComplexContentOutputtervoid
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 processvoid
processingInstruction(java.lang.String target, java.lang.CharSequence data, Location locationId, int properties)
Write a processing instructionvoid
setHostLanguage(HostLanguage language)
Set the host languagevoid
setPipelineConfiguration(PipelineConfiguration pipe)
Set the pipeline configurationvoid
setReceiver(Receiver receiver)
Set the receiver (to handle the next stage in the pipeline) directlyvoid
setSystemId(java.lang.String systemId)
Set the System ID of the tree represented by this event streamvoid
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 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
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
-
-
-
-
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 writtenoptions
- 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 interfaceReceiver
- Overrides:
setPipelineConfiguration
in classOutputter
- 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 interfaceReceiver
- Specified by:
setSystemId
in interfacejavax.xml.transform.Result
- 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
public void setHostLanguage(HostLanguage language)
Set the host language- Parameters:
language
- the host language, for exampleHostLanguage.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 interfaceReceiver
- Overrides:
open
in classOutputter
- Throws:
XPathException
- if an error occurs
-
startDocument
public void startDocument(int properties) throws XPathException
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
public void endDocument() throws XPathException
Notify the end of a document node- Specified by:
endDocument
in interfaceReceiver
- Specified by:
endDocument
in classOutputter
- 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 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
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 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 namelocation
- the location of the element node (or the instruction that created it)properties
- any special properties of the nodetypeCode
- 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 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
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 usingnamespace(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 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, 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 classOutputter
- Parameters:
attName
- The name 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),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 invokesstartContent()
, which means it cannot be followed by further calls onattribute(NodeName, SimpleType, CharSequence, Location, int)
ornamespace(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
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
public void endElement() throws XPathException
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(java.lang.CharSequence 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(java.lang.String target, java.lang.CharSequence 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
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 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
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 classOutputter
- Parameters:
asTextNode
- set to true if the concatenated string values are to be treated as a text nodeloc
- 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 interfaceReceiver
- Overrides:
close
in classOutputter
- Throws:
XPathException
- if an error occurs
-
startContent
public void startContent() throws XPathException
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
-
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 thisComplexContentOutputter
by calling itsmethod
- Parameters:
array
- the array to be flattenedlocationId
- the location of the instruction triggering this operationcopyNamespaces
- 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 eventslocationId
- the location of the requesting instructioncopyNamespaces
- options for copying namespace nodes- Throws:
XPathException
-
getErrorCodeForDecomposingFunctionItems
protected java.lang.String getErrorCodeForDecomposingFunctionItems()
-
-