public static interface Push.Element extends Push.Container
Push.Container
representing an element node.
The permitted sequence of events for an element node is
(ATTRIBUTE | NAMESPACE)* (COMMENT | PI | TEXT | ELEMENT)* CLOSE?
.
The methods for events other than child elements return the element container to
while they are applied, so methods can be chained: for example
element("foo").attribute("bar", "1").text("baz").close()
generates the XML
content <foo bar="1">baz</foo>
Closing an element is optional; it is automatically closed when another event is applied to its parent container, or when the parent container is closed.
Modifier and Type | Method and Description |
---|---|
Push.Element |
attribute(QName name,
java.lang.String value)
Add an attribute to the current element, supplying its name as a QName.
|
Push.Element |
attribute(java.lang.String name,
java.lang.String value)
Add an attribute to the current element, supplying its name as a string.
|
Push.Element |
comment(java.lang.CharSequence value)
Add a comment node to the current element or document node.
|
Push.Element |
namespace(java.lang.String prefix,
java.lang.String uri)
Add an namespace binding to the current element.
|
Push.Element |
processingInstruction(java.lang.String name,
java.lang.CharSequence value)
Add a processing instruction node to the current element or document node.
|
Push.Element |
text(java.lang.CharSequence value)
Add text content to the current element node (or, in the case of a non-well-formed document,
as a child of the document node).
|
close, element, element, setDefaultNamespace
Push.Element attribute(QName name, java.lang.String value) throws SaxonApiException
The level of validation applied to the supplied names is implementation-defined.
This method call is allowed in state START_TAG
, and it leaves the state unchanged.
name
- The name of the attribute, as a QName (which may contain
prefix, namespace URI, and local name). The prefix and namespace URI
must either both be empty, or both be non-empty.
A namespace declaration binding the prefix to the namespace URI will be generated unless it is redundant. An exception is thrown if the binding is incompatible with other bindings already established for the same prefix.
value
- The value of the attribute. If the value is null, then no attribute is written.tag.element("a").attribute("x", "1").attribute("y", "2")
SaxonApiException
- if the specified constraints are violated, or if the implementation
detects any problemsPush.Element attribute(java.lang.String name, java.lang.String value) throws SaxonApiException
The level of validation applied to the supplied name is implementation-defined.
This method call is allowed in state START_TAG
, and it leaves the state unchanged.
name
- The name of the attribute, as a string. The attribute will be in no namespace.value
- The value of the attribute. If the value is null, then no attribute is written.tag.element("a").attribute("x", "1").attribute("y", "2")
SaxonApiException
- if the specified constraints are violated, or if the implementation
detects any problemsPush.Element namespace(java.lang.String prefix, java.lang.String uri) throws SaxonApiException
It is never necessary to use this call to establish bindings for prefixes used in
element or attribute names; it is needed only when there is a requirement to declare
a namespace for use in other contexts, for example in the value of an xsi:type
attribute.
This method is not used to declare a default namespace; that is done using
Push.Container.setDefaultNamespace(String)
.
The level of validation applied to the supplied names is implementation-defined.
This method call is allowed in state START_TAG
, and it leaves the state unchanged.
An exception is thrown if the binding is incompatible with other bindings already established
on the current element for the same prefix, including any binding established using
Push.Container.setDefaultNamespace(String)
prefix
- The namespace prefix. This must not be a zero-length string.uri
- The namespace URI. This must not be a zero-length string.tag.element("a").namespace("xs", XS_SCHEMA).attribute("type", "xs:string")
SaxonApiException
- if the specified constraints are violated, or if the implementation
detects any problemsPush.Element text(java.lang.CharSequence value) throws SaxonApiException
Push.Container
Multiple consecutive calls on text()
generate a single text node with concatenated
content: that is, text("one).text("two")
is equivalent to text("onetwo")
.
text
in interface Push.Container
value
- the content of the text node. Supplying a zero-length string or null is permitted,
but has no effect.tag.element("a").text("content").close()
SaxonApiException
- if the specified constraints are violated, or if the implementation
detects any problemsPush.Element comment(java.lang.CharSequence value) throws SaxonApiException
Push.Container
The method call is allowed in states START_TAG
, CONTENT
, and
NON_TEXT_CONTENT
, and it sets the state to CONTENT
.
comment
in interface Push.Container
value
- the content of the comment node. The value should not contain the string "--";
it is implementation-defined whether this causes an exception, or whether some
recovery action is taken such as replacing the string by "- -". If the value
is null, no comment node is written.tag.element("a").comment("optional").close()
SaxonApiException
- if the specified constraints are violated, or if the implementation
detects any problemsPush.Element processingInstruction(java.lang.String name, java.lang.CharSequence value) throws SaxonApiException
Push.Container
The method call is allowed in states START_TAG
, CONTENT
, and
NON_TEXT_CONTENT
, and it sets the state to CONTENT
.
processingInstruction
in interface Push.Container
name
- the name ("target") of the processing instruction. The level of validation applied
to the supplied name is implementation-defined. Must not be null.value
- the content ("data") of the processing instruction node.
The value should not contain the string "?>"
;
it is implementation-defined whether this causes an exception, or whether some
recovery action is taken such as replacing the string by "? >"
. If the value
is null, no processing instruction node is written.tag.element("a").processing-instruction("target", "data").close()
SaxonApiException
- if the specified constraints are violated, or if the implementation
detects any problemsCopyright (c) 2004-2022 Saxonica Limited. All rights reserved.