Package com.jamesmurty.utils
Class XMLBuilder
- java.lang.Object
-
- com.jamesmurty.utils.BaseXMLBuilder
-
- com.jamesmurty.utils.XMLBuilder
-
public final class XMLBuilder extends BaseXMLBuilder
XML Builder is a utility that creates simple XML documents using relatively sparse Java code. It is intended to allow for quick and painless creation of XML documents where you might otherwise be tempted to use concatenated strings, rather than face the tedium and verbosity of coding with JAXP (http://jaxp.dev.java.net/).Internally, XML Builder uses JAXP to build a standard W3C
Documentmodel (DOM) that you can easily export as a string, or access and manipulate further if you have special requirements.The XMLBuilder class serves as a wrapper of
Elementnodes, and provides a number of utility methods that make it simple to manipulate the underlying element and the document to which it belongs. In essence, this class performs dual roles: it represents a specific XML node, and also allows manipulation of the entire underlying XML document. The platform's defaultDocumentBuilderFactoryandDocumentBuilderclasses are used to build the document.- Author:
- James Murty
-
-
Field Summary
-
Fields inherited from class com.jamesmurty.utils.BaseXMLBuilder
failIfExternalEntityParsingCannotBeConfigured
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedXMLBuilder(Document xmlDocument)Construct a new builder object that wraps the given XML document.protectedXMLBuilder(Node myNode, Node parentNode)Construct a new builder object that wraps the given XML document and node.
-
Method Summary
Modifier and Type Method Description XMLBuildera(String name, String value)Synonym forBaseXMLBuilder.attribute(String, String).XMLBuilderattr(String name, String value)Synonym forBaseXMLBuilder.attribute(String, String).XMLBuilderattribute(String name, String value)Add a named attribute value to the element represented by this builder node, and return the node representing the element to which the attribute was added (not the new attribute node).XMLBuilderc(String comment)Synonym forBaseXMLBuilder.comment(String).XMLBuildercdata(byte[] data)Add a CDATA node with Base64-encoded byte data content to the element represented by this builder node, and return the node representing the element to which the data was added (not the new CDATA node).XMLBuildercdata(String data)Add a CDATA node with String content to the element represented by this builder node, and return the node representing the element to which the data was added (not the new CDATA node).XMLBuildercmnt(String comment)Synonym forBaseXMLBuilder.comment(String).XMLBuildercomment(String comment)Add a comment to the element represented by this builder node, and return the node representing the element to which the comment was added (not the new comment node).static XMLBuildercreate(String name)Construct a builder for new XML document.static XMLBuildercreate(String name, boolean enableExternalEntities, boolean isNamespaceAware)Construct a builder for new XML document.static XMLBuildercreate(String name, String namespaceURI)Construct a builder for new XML document with a default namespace.static XMLBuildercreate(String name, String namespaceURI, boolean enableExternalEntities, boolean isNamespaceAware)Construct a builder for new XML document with a default namespace.XMLBuilderd(byte[] data)Synonym forBaseXMLBuilder.cdata(byte[]).XMLBuilderd(String data)Synonym forBaseXMLBuilder.cdata(String).XMLBuilderdata(byte[] data)Synonym forBaseXMLBuilder.cdata(byte[]).XMLBuilderdata(String data)Synonym forBaseXMLBuilder.cdata(String).XMLBuilderdocument()BEWARE: The builder returned by this method represents a Document node, not an Element node as is usually the case, so attempts to use the attribute or namespace methods on this builder will likely fail.XMLBuildere(String name)Synonym forBaseXMLBuilder.element(String).XMLBuilderelem(String name)Synonym forBaseXMLBuilder.element(String).XMLBuilderelement(String name)Add a named XML element to the document as a child of this builder node, and return the builder node representing the new child.XMLBuilderelement(String name, String namespaceURI)Add a named and namespaced XML element to the document as a child of this builder node, and return the builder node representing the new child.XMLBuilderelementBefore(String name)Add a named XML element to the document as a sibling element that precedes the position of this builder node, and return the builder node representing the new child.XMLBuilderelementBefore(String name, String namespaceURI)Add a named and namespaced XML element to the document as a sibling element that precedes the position of this builder node, and return the builder node representing the new child.XMLBuilderi(String target, String data)Synonym forBaseXMLBuilder.instruction(String, String).XMLBuilderimportXMLBuilder(BaseXMLBuilder builder)Imports another XMLBuilder document into this document at the current position.XMLBuilderinsertInstruction(String target, String data)Insert an instruction before the element represented by this builder node, and return the node representing that same element (not the new instruction node).XMLBuilderinst(String target, String data)Synonym forBaseXMLBuilder.instruction(String, String).XMLBuilderinstruction(String target, String data)Add an instruction to the element represented by this builder node, and return the node representing the element to which the instruction was added (not the new instruction node).XMLBuildernamespace(String namespaceURI)Add an XML namespace attribute to this builder's element node without a prefix.XMLBuildernamespace(String prefix, String namespaceURI)Add an XML namespace attribute to this builder's element node.XMLBuilderns(String namespaceURI)Synonym forBaseXMLBuilder.namespace(String).XMLBuilderns(String prefix, String namespaceURI)Synonym forBaseXMLBuilder.namespace(String, String).static XMLBuilderparse(File xmlFile)Construct a builder from an existing XML document file.static XMLBuilderparse(File xmlFile, boolean enableExternalEntities, boolean isNamespaceAware)Construct a builder from an existing XML document file.static XMLBuilderparse(String xmlString)Construct a builder from an existing XML document string.static XMLBuilderparse(String xmlString, boolean enableExternalEntities, boolean isNamespaceAware)Construct a builder from an existing XML document string.static XMLBuilderparse(InputSource inputSource)Construct a builder from an existing XML document.static XMLBuilderparse(InputSource inputSource, boolean enableExternalEntities, boolean isNamespaceAware)Construct a builder from an existing XML document.XMLBuilderr(String name)Synonym forBaseXMLBuilder.reference(String).XMLBuilderref(String name)Synonym forBaseXMLBuilder.reference(String).XMLBuilderreference(String name)Add a reference to the element represented by this builder node, and return the node representing the element to which the reference was added (not the new reference node).XMLBuilderroot()XMLBuilderstripWhitespaceOnlyTextNodes()Find and delete from the underlying Document any text nodes that contain nothing but whitespace, such as newlines and tab or space characters used to indent or pretty-print an XML document.XMLBuildert(String value)Synonym forBaseXMLBuilder.text(String).XMLBuildertext(String value)Add a text value to the element represented by this builder node, and return the node representing the element to which the text was added (not the new text node).XMLBuildertext(String value, boolean replaceText)Add or replace the text value of an element represented by this builder node, and return the node representing the element to which the text was added (not the new text node).XMLBuilderup()Return the builder node representing the parent of the current node.XMLBuilderup(int steps)Return the builder node representing the nth ancestor element of this node, or the root node if n exceeds the document's depth.XMLBuilderxpathFind(String xpath)Find the first element in the builder's DOM matching the given XPath expression.XMLBuilderxpathFind(String xpath, NamespaceContext nsContext)Find the first element in the builder's DOM matching the given XPath expression, where the expression may include namespaces if aNamespaceContextis provided.-
Methods inherited from class com.jamesmurty.utils.BaseXMLBuilder
assertElementContainsNoOrWhitespaceOnlyTextNodes, asString, asString, attributeImpl, buildDocumentNamespaceContext, cdataImpl, cdataImpl, commentImpl, createDocumentImpl, elementAsString, elementAsString, elementBeforeImpl, elementBeforeImpl, elementImpl, enableOrDisableExternalEntityParsing, equals, getDocument, getElement, getPrefixFromQualifiedName, importXMLBuilderImpl, insertInstructionImpl, instructionImpl, lookupNamespaceURIImpl, namespaceImpl, namespaceImpl, parseDocumentImpl, referenceImpl, stripWhitespaceOnlyTextNodesImpl, textImpl, toWriter, toWriter, upImpl, xpathFindImpl, xpathQuery, xpathQuery
-
-
-
-
Constructor Detail
-
XMLBuilder
protected XMLBuilder(Document xmlDocument)
Construct a new builder object that wraps the given XML document. This constructor is for internal use only.- Parameters:
xmlDocument- an XML document that the builder will manage and manipulate.
-
XMLBuilder
protected XMLBuilder(Node myNode, Node parentNode)
Construct a new builder object that wraps the given XML document and node. This constructor is for internal use only.- Parameters:
myNode- the XML node that this builder node will wrap. This node may be part of the XML document, or it may be a new element that is to be added to the document.parentNode- If not null, the given myElement will be appended as child node of the parentNode node.
-
-
Method Detail
-
create
public static XMLBuilder create(String name, String namespaceURI, boolean enableExternalEntities, boolean isNamespaceAware) throws ParserConfigurationException, FactoryConfigurationError
Construct a builder for new XML document with a default namespace. The document will be created with the given root element, and the builder returned by this method will serve as the starting-point for any further document additions.- Parameters:
name- the name of the document's root element.namespaceURI- default namespace URI for document, ignored if null or empty.enableExternalEntities- enable external entities; beware of XML External Entity (XXE) injection.isNamespaceAware- enable or disable namespace awareness in the underlyingDocumentBuilderFactory- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
FactoryConfigurationError- xyzParserConfigurationException- xyz
-
create
public static XMLBuilder create(String name, boolean enableExternalEntities, boolean isNamespaceAware) throws ParserConfigurationException, FactoryConfigurationError
Construct a builder for new XML document. The document will be created with the given root element, and the builder returned by this method will serve as the starting-point for any further document additions.- Parameters:
name- the name of the document's root element.enableExternalEntities- enable external entities; beware of XML External Entity (XXE) injection.isNamespaceAware- enable or disable namespace awareness in the underlyingDocumentBuilderFactory- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
FactoryConfigurationError- xyzParserConfigurationException- xyz
-
create
public static XMLBuilder create(String name, String namespaceURI) throws ParserConfigurationException, FactoryConfigurationError
Construct a builder for new XML document with a default namespace. The document will be created with the given root element, and the builder returned by this method will serve as the starting-point for any further document additions.- Parameters:
name- the name of the document's root element.namespaceURI- default namespace URI for document, ignored if null or empty.- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
FactoryConfigurationError- xyzParserConfigurationException- xyz
-
create
public static XMLBuilder create(String name) throws ParserConfigurationException, FactoryConfigurationError
Construct a builder for new XML document. The document will be created with the given root element, and the builder returned by this method will serve as the starting-point for any further document additions.- Parameters:
name- the name of the document's root element.- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
FactoryConfigurationError- xyzParserConfigurationException- xyz
-
parse
public static XMLBuilder parse(InputSource inputSource, boolean enableExternalEntities, boolean isNamespaceAware) throws ParserConfigurationException, SAXException, IOException
Construct a builder from an existing XML document. The provided XML document will be parsed and an XMLBuilder object referencing the document's root element will be returned.- Parameters:
inputSource- an XML document input source that will be parsed into a DOM.enableExternalEntities- enable external entities; beware of XML External Entity (XXE) injection.isNamespaceAware- enable or disable namespace awareness in the underlyingDocumentBuilderFactory- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
ParserConfigurationException- xyzFactoryConfigurationError- xyzParserConfigurationException- xyzIOException- xyzSAXException- xyz
-
parse
public static XMLBuilder parse(String xmlString, boolean enableExternalEntities, boolean isNamespaceAware) throws ParserConfigurationException, SAXException, IOException
Construct a builder from an existing XML document string. The provided XML document will be parsed and an XMLBuilder object referencing the document's root element will be returned.- Parameters:
xmlString- an XML document string that will be parsed into a DOM.enableExternalEntities- enable external entities; beware of XML External Entity (XXE) injection.isNamespaceAware- enable or disable namespace awareness in the underlyingDocumentBuilderFactory- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
ParserConfigurationException- xyzFactoryConfigurationError- xyzParserConfigurationException- xyzIOException- xyzSAXException- xyz
-
parse
public static XMLBuilder parse(File xmlFile, boolean enableExternalEntities, boolean isNamespaceAware) throws ParserConfigurationException, SAXException, IOException
Construct a builder from an existing XML document file. The provided XML document will be parsed and an XMLBuilder object referencing the document's root element will be returned.- Parameters:
xmlFile- an XML document file that will be parsed into a DOM.enableExternalEntities- enable external entities; beware of XML External Entity (XXE) injection.isNamespaceAware- enable or disable namespace awareness in the underlyingDocumentBuilderFactory- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
ParserConfigurationException- xyzFactoryConfigurationError- xyzParserConfigurationException- xyzIOException- xyzSAXException- xyz
-
parse
public static XMLBuilder parse(InputSource inputSource) throws ParserConfigurationException, SAXException, IOException
Construct a builder from an existing XML document. The provided XML document will be parsed and an XMLBuilder object referencing the document's root element will be returned.- Parameters:
inputSource- an XML document input source that will be parsed into a DOM.- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
ParserConfigurationException- xyzFactoryConfigurationError- xyzParserConfigurationException- xyzIOException- xyzSAXException- xyz
-
parse
public static XMLBuilder parse(String xmlString) throws ParserConfigurationException, SAXException, IOException
Construct a builder from an existing XML document string. The provided XML document will be parsed and an XMLBuilder object referencing the document's root element will be returned.- Parameters:
xmlString- an XML document string that will be parsed into a DOM.- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
ParserConfigurationException- xyzFactoryConfigurationError- xyzParserConfigurationException- xyzIOException- xyzSAXException- xyz
-
parse
public static XMLBuilder parse(File xmlFile) throws ParserConfigurationException, SAXException, IOException
Construct a builder from an existing XML document file. The provided XML document will be parsed and an XMLBuilder object referencing the document's root element will be returned.- Parameters:
xmlFile- an XML document file that will be parsed into a DOM.- Returns:
- a builder node that can be used to add more nodes to the XML document.
- Throws:
ParserConfigurationException- xyzFactoryConfigurationError- xyzParserConfigurationException- xyzIOException- xyzSAXException- xyz
-
stripWhitespaceOnlyTextNodes
public XMLBuilder stripWhitespaceOnlyTextNodes() throws XPathExpressionException
Description copied from class:BaseXMLBuilderFind and delete from the underlying Document any text nodes that contain nothing but whitespace, such as newlines and tab or space characters used to indent or pretty-print an XML document. Uses approach I documented on StackOverflow: http://stackoverflow.com/a/979606/4970- Specified by:
stripWhitespaceOnlyTextNodesin classBaseXMLBuilder- Returns:
- a builder node at the same location as before the operation.
- Throws:
XPathExpressionException- xyz
-
importXMLBuilder
public XMLBuilder importXMLBuilder(BaseXMLBuilder builder)
Description copied from class:BaseXMLBuilderImports another XMLBuilder document into this document at the current position. The entire document provided is imported.- Specified by:
importXMLBuilderin classBaseXMLBuilder- Parameters:
builder- the XMLBuilder document to be imported.- Returns:
- a builder node at the same location as before the import, but now containing the entire document tree provided.
-
root
public XMLBuilder root()
- Specified by:
rootin classBaseXMLBuilder- Returns:
- the builder node representing the root element of the XML document.
-
xpathFind
public XMLBuilder xpathFind(String xpath, NamespaceContext nsContext) throws XPathExpressionException
Description copied from class:BaseXMLBuilderFind the first element in the builder's DOM matching the given XPath expression, where the expression may include namespaces if aNamespaceContextis provided.- Specified by:
xpathFindin classBaseXMLBuilder- Parameters:
xpath- An XPath expression that *must* resolve to an existing Element within the document object model.nsContext- a mapping of prefixes to namespace URIs that allows the XPath expression to use namespaces.- Returns:
- a builder node representing the first Element that matches the XPath expression.
- Throws:
XPathExpressionException- If the XPath is invalid, or if does not resolve to at least oneNode.ELEMENT_NODE.
-
xpathFind
public XMLBuilder xpathFind(String xpath) throws XPathExpressionException
Description copied from class:BaseXMLBuilderFind the first element in the builder's DOM matching the given XPath expression.- Specified by:
xpathFindin classBaseXMLBuilder- Parameters:
xpath- An XPath expression that *must* resolve to an existing Element within the document object model.- Returns:
- a builder node representing the first Element that matches the XPath expression.
- Throws:
XPathExpressionException- If the XPath is invalid, or if does not resolve to at least oneNode.ELEMENT_NODE.
-
element
public XMLBuilder element(String name)
Description copied from class:BaseXMLBuilderAdd a named XML element to the document as a child of this builder node, and return the builder node representing the new child. When adding an element to a namespaced document, the new node will be assigned a namespace matching it's qualified name prefix (if any) or the document's default namespace. NOTE: If the element has a prefix that does not match any known namespaces, the element will be created without any namespace.- Specified by:
elementin classBaseXMLBuilder- Parameters:
name- the name of the XML element.- Returns:
- a builder node representing the new child.
-
elem
public XMLBuilder elem(String name)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.element(String).- Specified by:
elemin classBaseXMLBuilder- Parameters:
name- the name of the XML element.- Returns:
- a builder node representing the new child.
-
e
public XMLBuilder e(String name)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.element(String).- Specified by:
ein classBaseXMLBuilder- Parameters:
name- the name of the XML element.- Returns:
- a builder node representing the new child.
-
element
public XMLBuilder element(String name, String namespaceURI)
Description copied from class:BaseXMLBuilderAdd a named and namespaced XML element to the document as a child of this builder node, and return the builder node representing the new child.- Specified by:
elementin classBaseXMLBuilder- Parameters:
name- the name of the XML element.namespaceURI- a namespace URI- Returns:
- a builder node representing the new child.
-
elementBefore
public XMLBuilder elementBefore(String name)
Description copied from class:BaseXMLBuilderAdd a named XML element to the document as a sibling element that precedes the position of this builder node, and return the builder node representing the new child. When adding an element to a namespaced document, the new node will be assigned a namespace matching it's qualified name prefix (if any) or the document's default namespace. NOTE: If the element has a prefix that does not match any known namespaces, the element will be created without any namespace.- Specified by:
elementBeforein classBaseXMLBuilder- Parameters:
name- the name of the XML element.- Returns:
- a builder node representing the new child.
-
elementBefore
public XMLBuilder elementBefore(String name, String namespaceURI)
Description copied from class:BaseXMLBuilderAdd a named and namespaced XML element to the document as a sibling element that precedes the position of this builder node, and return the builder node representing the new child.- Specified by:
elementBeforein classBaseXMLBuilder- Parameters:
name- the name of the XML element.namespaceURI- a namespace URI- Returns:
- a builder node representing the new child.
-
attribute
public XMLBuilder attribute(String name, String value)
Description copied from class:BaseXMLBuilderAdd a named attribute value to the element represented by this builder node, and return the node representing the element to which the attribute was added (not the new attribute node).- Specified by:
attributein classBaseXMLBuilder- Parameters:
name- the attribute's name.value- the attribute's value.- Returns:
- the builder node representing the element to which the attribute was added.
-
attr
public XMLBuilder attr(String name, String value)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.attribute(String, String).- Specified by:
attrin classBaseXMLBuilder- Parameters:
name- the attribute's name.value- the attribute's value.- Returns:
- the builder node representing the element to which the attribute was added.
-
a
public XMLBuilder a(String name, String value)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.attribute(String, String).- Specified by:
ain classBaseXMLBuilder- Parameters:
name- the attribute's name.value- the attribute's value.- Returns:
- the builder node representing the element to which the attribute was added.
-
text
public XMLBuilder text(String value, boolean replaceText)
Description copied from class:BaseXMLBuilderAdd or replace the text value of an element represented by this builder node, and return the node representing the element to which the text was added (not the new text node).- Specified by:
textin classBaseXMLBuilder- Parameters:
value- the text value to set or add to the element.replaceText- if True any existing text content of the node is replaced with the given text value, if the given value is appended to any existing text.- Returns:
- the builder node representing the element to which the text was added.
-
text
public XMLBuilder text(String value)
Description copied from class:BaseXMLBuilderAdd a text value to the element represented by this builder node, and return the node representing the element to which the text was added (not the new text node).- Specified by:
textin classBaseXMLBuilder- Parameters:
value- the text value to add to the element.- Returns:
- the builder node representing the element to which the text was added.
-
t
public XMLBuilder t(String value)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.text(String).- Specified by:
tin classBaseXMLBuilder- Parameters:
value- the text value to add to the element.- Returns:
- the builder node representing the element to which the text was added.
-
cdata
public XMLBuilder cdata(String data)
Description copied from class:BaseXMLBuilderAdd a CDATA node with String content to the element represented by this builder node, and return the node representing the element to which the data was added (not the new CDATA node).- Specified by:
cdatain classBaseXMLBuilder- Parameters:
data- the String value that will be added to a CDATA element.- Returns:
- the builder node representing the element to which the data was added.
-
data
public XMLBuilder data(String data)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.cdata(String).- Specified by:
datain classBaseXMLBuilder- Parameters:
data- the String value that will be added to a CDATA element.- Returns:
- the builder node representing the element to which the data was added.
-
d
public XMLBuilder d(String data)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.cdata(String).- Specified by:
din classBaseXMLBuilder- Parameters:
data- the String value that will be added to a CDATA element.- Returns:
- the builder node representing the element to which the data was added.
-
cdata
public XMLBuilder cdata(byte[] data)
Description copied from class:BaseXMLBuilderAdd a CDATA node with Base64-encoded byte data content to the element represented by this builder node, and return the node representing the element to which the data was added (not the new CDATA node).- Specified by:
cdatain classBaseXMLBuilder- Parameters:
data- the data value that will be Base64-encoded and added to a CDATA element.- Returns:
- the builder node representing the element to which the data was added.
-
data
public XMLBuilder data(byte[] data)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.cdata(byte[]).- Specified by:
datain classBaseXMLBuilder- Parameters:
data- the data value that will be Base64-encoded and added to a CDATA element.- Returns:
- the builder node representing the element to which the data was added.
-
d
public XMLBuilder d(byte[] data)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.cdata(byte[]).- Specified by:
din classBaseXMLBuilder- Parameters:
data- the data value that will be Base64-encoded and added to a CDATA element.- Returns:
- the builder node representing the element to which the data was added.
-
comment
public XMLBuilder comment(String comment)
Description copied from class:BaseXMLBuilderAdd a comment to the element represented by this builder node, and return the node representing the element to which the comment was added (not the new comment node).- Specified by:
commentin classBaseXMLBuilder- Parameters:
comment- the comment to add to the element.- Returns:
- the builder node representing the element to which the comment was added.
-
cmnt
public XMLBuilder cmnt(String comment)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.comment(String).- Specified by:
cmntin classBaseXMLBuilder- Parameters:
comment- the comment to add to the element.- Returns:
- the builder node representing the element to which the comment was added.
-
c
public XMLBuilder c(String comment)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.comment(String).- Specified by:
cin classBaseXMLBuilder- Parameters:
comment- the comment to add to the element.- Returns:
- the builder node representing the element to which the comment was added.
-
instruction
public XMLBuilder instruction(String target, String data)
Description copied from class:BaseXMLBuilderAdd an instruction to the element represented by this builder node, and return the node representing the element to which the instruction was added (not the new instruction node).- Specified by:
instructionin classBaseXMLBuilder- Parameters:
target- the target value for the instruction.data- the data value for the instruction- Returns:
- the builder node representing the element to which the instruction was added.
-
inst
public XMLBuilder inst(String target, String data)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.instruction(String, String).- Specified by:
instin classBaseXMLBuilder- Parameters:
target- the target value for the instruction.data- the data value for the instruction- Returns:
- the builder node representing the element to which the instruction was added.
-
i
public XMLBuilder i(String target, String data)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.instruction(String, String).- Specified by:
iin classBaseXMLBuilder- Parameters:
target- the target value for the instruction.data- the data value for the instruction- Returns:
- the builder node representing the element to which the instruction was added.
-
insertInstruction
public XMLBuilder insertInstruction(String target, String data)
Description copied from class:BaseXMLBuilderInsert an instruction before the element represented by this builder node, and return the node representing that same element (not the new instruction node).- Specified by:
insertInstructionin classBaseXMLBuilder- Parameters:
target- the target value for the instruction.data- the data value for the instruction- Returns:
- the builder node representing the element before which the instruction was inserted.
-
reference
public XMLBuilder reference(String name)
Description copied from class:BaseXMLBuilderAdd a reference to the element represented by this builder node, and return the node representing the element to which the reference was added (not the new reference node).- Specified by:
referencein classBaseXMLBuilder- Parameters:
name- the name value for the reference.- Returns:
- the builder node representing the element to which the reference was added.
-
ref
public XMLBuilder ref(String name)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.reference(String).- Specified by:
refin classBaseXMLBuilder- Parameters:
name- the name value for the reference.- Returns:
- the builder node representing the element to which the reference was added.
-
r
public XMLBuilder r(String name)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.reference(String).- Specified by:
rin classBaseXMLBuilder- Parameters:
name- the name value for the reference.- Returns:
- the builder node representing the element to which the reference was added.
-
namespace
public XMLBuilder namespace(String prefix, String namespaceURI)
Description copied from class:BaseXMLBuilderAdd an XML namespace attribute to this builder's element node.- Specified by:
namespacein classBaseXMLBuilder- Parameters:
prefix- a prefix for the namespace URI within the document, may be null or empty in which case a default "xmlns" attribute is created.namespaceURI- a namespace uri- Returns:
- the builder node representing the element to which the attribute was added.
-
ns
public XMLBuilder ns(String prefix, String namespaceURI)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.namespace(String, String).- Specified by:
nsin classBaseXMLBuilder- Parameters:
prefix- a prefix for the namespace URI within the document, may be null or empty in which case a default xmlns attribute is created.namespaceURI- a namespace uri- Returns:
- the builder node representing the element to which the attribute was added.
-
namespace
public XMLBuilder namespace(String namespaceURI)
Description copied from class:BaseXMLBuilderAdd an XML namespace attribute to this builder's element node without a prefix.- Specified by:
namespacein classBaseXMLBuilder- Parameters:
namespaceURI- a namespace uri- Returns:
- the builder node representing the element to which the attribute was added.
-
ns
public XMLBuilder ns(String namespaceURI)
Description copied from class:BaseXMLBuilderSynonym forBaseXMLBuilder.namespace(String).- Specified by:
nsin classBaseXMLBuilder- Parameters:
namespaceURI- a namespace uri- Returns:
- the builder node representing the element to which the attribute was added.
-
up
public XMLBuilder up(int steps)
Description copied from class:BaseXMLBuilderReturn the builder node representing the nth ancestor element of this node, or the root node if n exceeds the document's depth.- Specified by:
upin classBaseXMLBuilder- Parameters:
steps- the number of parent elements to step over while navigating up the chain of node ancestors. A steps value of 1 will find a node's parent, 2 will find its grandparent etc.- Returns:
- the nth ancestor of this node, or the root node if this is reached before the nth parent is found.
-
up
public XMLBuilder up()
Description copied from class:BaseXMLBuilderReturn the builder node representing the parent of the current node.- Specified by:
upin classBaseXMLBuilder- Returns:
- the parent of this node, or the root node if this method is called on the root node.
-
document
public XMLBuilder document()
Description copied from class:BaseXMLBuilderBEWARE: The builder returned by this method represents a Document node, not an Element node as is usually the case, so attempts to use the attribute or namespace methods on this builder will likely fail.- Specified by:
documentin classBaseXMLBuilder- Returns:
- the builder node representing the root XML document.
-
-