public final class ComplexContentOutputter extends Outputter implements Receiver, javax.xml.transform.Result
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.
pipelineConfiguration, systemId
Constructor and Description |
---|
ComplexContentOutputter(Receiver next)
Create a ComplexContentOutputter
|
Modifier and Type | Method and 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.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 output
|
void |
comment(UnicodeString comment,
Location locationId,
int properties)
Write a comment
|
void |
endDocument()
Notify the end of a document node
|
void |
endElement()
Output an element end tag.
|
Receiver |
getReceiver()
Get the next receiver in the processing pipeline
|
UniStringConsumer |
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,
UnicodeString 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
|
append, getConfiguration, getPipelineConfiguration, getSystemId
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
append, getPipelineConfiguration, handlesAppend
public ComplexContentOutputter(Receiver next)
next
- the next receiver in the pipelinepublic static ComplexContentOutputter makeComplexContentReceiver(Receiver receiver, ParseOptions options)
receiver
- the destination to which the constructed complex content will be writtenoptions
- options for validating the output stream; may be nullpublic void setPipelineConfiguration(PipelineConfiguration pipe)
Outputter
setPipelineConfiguration
in interface Receiver
setPipelineConfiguration
in class Outputter
pipe
- the pipeline configurationpublic void setSystemId(java.lang.String systemId)
Outputter
setSystemId
in interface javax.xml.transform.Result
setSystemId
in class Outputter
systemId
- the system ID (which is used as the base URI of the nodes
if there is no xml:base attribute)public void setHostLanguage(HostLanguage language)
language
- the host language, for example HostLanguage.XQUERY
public void setReceiver(Receiver receiver)
receiver
- the receiver to handle the next stage in the pipelinepublic Receiver getReceiver()
public void open() throws XPathException
open
in interface Receiver
open
in class Outputter
XPathException
- if an error occurspublic void startDocument(int properties) throws XPathException
startDocument
in interface Receiver
startDocument
in class Outputter
properties
- any special properties of the nodeXPathException
- if an error occurspublic void endDocument() throws XPathException
endDocument
in interface Receiver
endDocument
in class Outputter
XPathException
- if an error occurspublic void setUnparsedEntity(java.lang.String name, java.lang.String systemID, java.lang.String publicID) throws XPathException
setUnparsedEntity
in interface Receiver
setUnparsedEntity
in class Outputter
name
- The name of the unparsed entitysystemID
- The system identifier of the unparsed entitypublicID
- The public identifier of the unparsed entityXPathException
- if an error occurspublic void characters(UnicodeString s, Location locationId, int properties) throws XPathException
characters
in interface Receiver
characters
in class Outputter
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 nodeXPathException
- for any failurepublic void startElement(NodeName elemName, SchemaType typeCode, Location location, int properties) throws XPathException
startElement
in class Outputter
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.XPathException
- if an error occurspublic void namespace(java.lang.String prefix, java.lang.String namespaceUri, int properties) throws XPathException
namespace
in class Outputter
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:XPathException
- if an error occurspublic void namespaces(NamespaceBindingSet bindings, int properties) throws XPathException
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 setnamespaces
in class Outputter
bindings
- the set of namespace bindingsproperties
- any special properties. The property ReceiverOption.NAMESPACE_OK
means that no checking is needed.XPathException
- if any failure occurspublic void attribute(NodeName attName, SimpleType typeCode, java.lang.String value, Location locationId, int properties) throws XPathException
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.
attribute
in class Outputter
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 attributeXPathException
- if an error occurspublic void startElement(NodeName elemName, SchemaType type, AttributeMap attributes, NamespaceMap namespaces, Location location, int properties) throws XPathException
startContent()
, which means it cannot be followed
by further calls on Outputter.attribute(NodeName, SimpleType, String, 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.
startElement
in interface Receiver
startElement
in class Outputter
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 class ReceiverOption
XPathException
- if an error occurspublic void endElement() throws XPathException
endElement
in interface Receiver
endElement
in class Outputter
XPathException
- if an error occurspublic void comment(UnicodeString comment, Location locationId, int properties) throws XPathException
comment
in interface Receiver
comment
in class Outputter
comment
- The content of the commentlocationId
- provides information such as line number and system ID.properties
- Additional information about the comment.XPathException
- if an error occurspublic void processingInstruction(java.lang.String target, UnicodeString data, Location locationId, int properties) throws XPathException
processingInstruction
in interface Receiver
processingInstruction
in class Outputter
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.XPathException
- if an error occurspublic void append(Item item, Location locationId, int copyNamespaces) throws XPathException
append
in interface Receiver
append
in class Outputter
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 are ReceiverOption.ALL_NAMESPACES
}; the default (0) meansXPathException
- if an error occurspublic UniStringConsumer getStringReceiver(boolean asTextNode, Location loc)
getStringReceiver
in class Outputter
asTextNode
- set to true if the concatenated string values are to be treated
* as a text node item rather than a stringpublic void close() throws XPathException
close
in interface Receiver
close
in class Outputter
XPathException
- if an error occurspublic void startContent() throws XPathException
startContent
in class Outputter
XPathException
- if an error occurspublic boolean usesTypeAnnotations()
usesTypeAnnotations
in interface Receiver
usesTypeAnnotations
in class Outputter
Copyright (c) 2004-2022 Saxonica Limited. All rights reserved.