public class DOMBuilder
extends BuilderSupport
A helper class for creating a W3C DOM tree
| Constructor and description |
|---|
DOMBuilder(Document document)Creates a builder that appends newly created elements to the supplied document. |
DOMBuilder(DocumentBuilder documentBuilder)Creates a builder that lazily creates a backing document from the supplied document builder. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected void |
appendNamespaceAttributes(Element element, Map<Object, Object> attributes)Applies namespace declaration attributes from an xmlns map to the supplied element. |
|
protected Document |
createDocument()Creates the backing document used by subsequent builder callbacks. |
|
protected Object |
createNode(Object name)Builder lifecycle callback that creates an element for the supplied node name. |
|
protected Object |
createNode(Object name, Object value)Builder lifecycle callback that creates an element and adds text content to it. |
|
protected Object |
createNode(Object name, Map attributes, Object value)Builder lifecycle callback that creates an element, applies attributes and adds text content. |
|
protected Object |
createNode(Object name, Map attributes)Builder lifecycle callback that creates an element and applies the supplied attributes. |
|
public static DOMBuilder |
newInstance()Creates a non-validating, namespace-aware DOM builder. |
|
public static DOMBuilder |
newInstance(boolean validating, boolean namespaceAware)Creates a DOM builder using the requested parser settings. |
|
public static DOMBuilder |
newInstance(boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration)Creates a DOM builder using the requested parser settings, including whether DOCTYPE declarations are permitted in parsed documents. |
|
public static Document |
parse(Reader reader)Creates a DocumentBuilder and uses it to parse the XML text read from the given reader. |
|
public static Document |
parse(Reader reader, boolean validating, boolean namespaceAware)Creates a DocumentBuilder and uses it to parse the XML text read from the given reader, allowing parser validation and namespace awareness to be controlled. |
|
public static Document |
parse(Reader reader, boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration)Creates a DocumentBuilder and uses it to parse the XML text read from the given reader, allowing parser validation, namespace awareness and permission of DOCTYPE declarations to be controlled. |
|
public Document |
parseText(String text)A helper method to parse the given text as XML. |
|
protected void |
setParent(Object parent, Object child)Builder lifecycle callback that attaches a completed child node to its parent node. |
| Methods inherited from class | Name |
|---|---|
class BuilderSupport |
createNode, createNode, createNode, createNode, doInvokeMethod, getCurrent, getName, invokeMethod, invokeMethod, nodeCompleted, postNodeCompletion, setClosureDelegate, setCurrent, setParent |
class GroovyObjectSupport |
getMetaClass, setMetaClass |
Creates a builder that appends newly created elements to the supplied document.
document - the target document to populateCreates a builder that lazily creates a backing document from the supplied document builder.
documentBuilder - the document builder used when a new document is required Applies namespace declaration attributes from an xmlns map to the supplied element.
null value or an unsupported key typeelement - the element receiving namespace attributesattributes - the namespace attributes keyed by prefix or QNameCreates the backing document used by subsequent builder callbacks. Subclasses may override to supply a custom document implementation.
Builder lifecycle callback that creates an element for the supplied node name.
name - the node name, either a QName or plain element nameBuilder lifecycle callback that creates an element and adds text content to it.
name - the node name, either a QName or plain element namevalue - the text value to appendBuilder lifecycle callback that creates an element, applies attributes and adds text content.
name - the node name, either a QName or plain element nameattributes - the attributes to apply to the created elementvalue - the text value to appendBuilder lifecycle callback that creates an element and applies the supplied attributes.
name - the node name, either a QName or plain element nameattributes - the attributes to apply, including namespace declarationsCreates a non-validating, namespace-aware DOM builder.
Creates a DOM builder using the requested parser settings. The underlying parser does not allow DOCTYPE declarations.
validating - whether the parser should validate source documentsnamespaceAware - whether the parser should be namespace awareCreates a DOM builder using the requested parser settings, including whether DOCTYPE declarations are permitted in parsed documents.
validating - whether the parser should validate source documentsnamespaceAware - whether the parser should be namespace awareallowDocTypeDeclaration - whether the parser should allow DOCTYPE declarationsCreates a DocumentBuilder and uses it to parse the XML text read from the given reader. A non-validating, namespace aware parser which does not allow DOCTYPE declarations is used.
reader - the reader to read the XML text fromCreates a DocumentBuilder and uses it to parse the XML text read from the given reader, allowing parser validation and namespace awareness to be controlled. Documents are not allowed to contain DOCYTYPE declarations.
reader - the reader to read the XML text fromvalidating - whether to validate the XMLnamespaceAware - whether the parser should be namespace awareCreates a DocumentBuilder and uses it to parse the XML text read from the given reader, allowing parser validation, namespace awareness and permission of DOCTYPE declarations to be controlled.
reader - the reader to read the XML text fromvalidating - whether to validate the XMLnamespaceAware - whether the parser should be namespace awareallowDocTypeDeclaration - whether the parser should allow DOCTYPE declarationsA helper method to parse the given text as XML.
text - the XML text to parseCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.