public class SaplingElement extends SaplingNode
Like all sapling nodes, a SaplingElement is immutable. All operations such as adding children
or attributes deliver a new element node. A sapling node generally exists only transiently during tree
construction; to make use of the constructed tree, it will usually be converted to a regular tree when
construction is complete, using toXdmNode(Processor) or toNodeInfo(Configuration).
| Constructor and Description |
|---|
SaplingElement(QName name)
Create an empty element, with a name supplied as a QName.
|
SaplingElement(java.lang.String name)
Create an empty element, in no namespace
|
| Modifier and Type | Method and Description |
|---|---|
int |
getNodeKind()
Get the kind of node (document, element, text, comment, or processing instruction)
|
protected void |
sendTo(Receiver receiver)
Send a sequence of events representing this node to a supplied Receiver
|
NodeInfo |
toNodeInfo(Configuration config)
Convert the sapling element to a regular element node, returning the
NodeInfo object
representing the parentless element node at the root of the resulting tree |
XdmNode |
toXdmNode(Processor processor)
Convert the sapling element to a regular element node, returning the
XdmNode object
representing the parentless element node at the root of the resulting tree |
SaplingElement |
withAttr(QName name,
java.lang.String value)
Add or replace an attribute of the element node, returning a new element node with a modified
set of attributes
|
SaplingElement |
withAttr(java.lang.String name,
java.lang.String value)
Add or replace an attribute of the element node, returning a new element node with a modified
set of attributes
|
SaplingElement |
withChild(SaplingNode... children)
Add a number of child nodes to a document node, returning a new document node
with additional children beyond those already present.
|
SaplingElement |
withNamespace(java.lang.String prefix,
java.lang.String uri)
Add a namespace binding for a prefix/URI pair.
|
SaplingElement |
withText(java.lang.String value)
Add a text node as a child to this element, returning a new sapling element node.
|
public SaplingElement(java.lang.String name)
name - the name of the element. This should take the form of an NCName, but the
current implementation does not check this.public SaplingElement(QName name)
name - the name of the element, as a QName. If the prefix of the QName is non-empty,
then the URI part must also be non-empty.java.lang.IllegalArgumentException - if the name contains a prefix but no URIpublic int getNodeKind()
SaplingNodegetNodeKind in class SaplingNodeType.ELEMENT for an element node.public SaplingElement withChild(SaplingNode... children)
Note: because adding a child always creates a new parent element, it is impossible to create cycles by adding a node to itself, directly or indirectly.
children - The nodes to be added as children.
The supplied nodes are added in order after any existing children.java.lang.IllegalArgumentException - if any of the nodes supplied as an argument is
a document node.public SaplingElement withText(java.lang.String value)
e.withText("value") is equavalent to
e.withChild(text("value"))value - the string value of a new text node, which will be added as a child
to this element after any existing childrenpublic SaplingElement withAttr(java.lang.String name, java.lang.String value)
name - the name of the attribute to be added or replaced; this represents the local part of
a no-namespace QName. The name must be in the form of an NCName, but the current implementation
does not check this.value - the (new) value of the attributepublic SaplingElement withAttr(QName name, java.lang.String value)
name - the name of the attribute to be added or replaced, as a QNamevalue - the (new) value of the attributejava.lang.IllegalArgumentException - if the prefix of the attribute name is empty and the URI is not, or
if the URI is empty and the prefix is notjava.lang.IllegalStateException - if the prefix/uri binding is incompatible with the existing prefix/uri
bindings on the elementpublic SaplingElement withNamespace(java.lang.String prefix, java.lang.String uri)
prefix - the namespace prefix. This must either be a zero length string, or it must take the
form of an NCName, but this constraint is not currently enforced.uri - the namespace URI. If this is the empty string, then (a) if the prefix is empty, the
namespace binding is ignored; (b) otherwise, an exception is raised (namespace undeclarations
are not permitted).java.lang.IllegalArgumentException - if the URI is empty and the prefix is notjava.lang.IllegalStateException - if the element already has a namespace binding for this prefix, with
a different URI.protected void sendTo(Receiver receiver) throws XPathException
SaplingNodesendTo in class SaplingNodereceiver - the receiver to which the events are to be sentXPathException - if the receiver throws an exceptionpublic NodeInfo toNodeInfo(Configuration config) throws XPathException
NodeInfo object
representing the parentless element node at the root of the resulting treeconfig - the Saxon ConfigurationXPathException - if construction fails; this could happen if constraints have been violatedpublic XdmNode toXdmNode(Processor processor) throws SaxonApiException
XdmNode object
representing the parentless element node at the root of the resulting treeprocessor - the s9api Processor object that is to own the resulting treeSaxonApiException - if construction fails; this could happen if constraints have been violatedCopyright (c) 2004-2021 Saxonica Limited. All rights reserved.