Top Description Fields Constructors Methods
groovy.xml

public Class DOMBuilder

extends BuilderSupport
Class Inheritance
Imports
groovy.namespace.QName, groovy.util.BuilderSupport, org.w3c.dom.Document, .Element, .Node, org.xml.sax.InputSource, .SAXException, javax.xml.XMLConstants, javax.xml.parsers.DocumentBuilder, .DocumentBuilderFactory, .ParserConfigurationException, java.io.IOException, .Reader, .StringReader, java.util.Map

A helper class for creating a W3C DOM tree

Field Summary

Modifier and TypeField and Description
pack-priv Document
pack-priv DocumentBuilder

Constructor Summary

AccessConstructor and Description
public
DOMBuilder(Document document)

public
DOMBuilder(DocumentBuilder documentBuilder)

Method Summary

Modifier and TypeMethod and Description
protected void
protected Document
protected Object
protected Object
protected Object
createNode(Object name, Map<K, V> attributes, Object value)

Implements abstract groovy.util.BuilderSupport.createNode.

protected Object
createNode(Object name, Map<K, V> attributes)

Implements abstract groovy.util.BuilderSupport.createNode.

public static DOMBuilder
public static DOMBuilder
newInstance(boolean validating, boolean namespaceAware)

public static Document

Returns:

the root node of the parsed tree of Nodes
parse
(Reader
the reader to read the XML text from
reader
)

Creates a DocumentBuilder and uses it to parse the XML text read from the given reader.

public static Document

Returns:

the root node of the parsed tree of Nodes
parse
(Reader
the reader to read the XML text from
reader
,
boolean
whether to validate the XML
validating
,
boolean
whether the parser should be namespace aware
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

Returns:

the root node of the parsed tree of Nodes
parse
(Reader
the reader to read the XML text from
reader
,
boolean
whether to validate the XML
validating
,
boolean
whether the parser should be namespace aware
namespaceAware
,
boolean
whether the parser should allow DOCTYPE declarations
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

Returns:

the root node of the parsed tree of Nodes
parseText
(String
the XML text to parse
text
)

A helper method to parse the given text as XML.

protected void
setParent(Object parent, Object child)

Implements abstract groovy.util.BuilderSupport.setParent.

private static void
setQuietly(DocumentBuilderFactory factory, String feature, boolean value)

private static void
setStringNS(Element element, Object key, Object value)

Inherited from groovy.util.BuilderSupport:
doInvokeMethodgetCurrentgetNameinvokeMethodinvokeMethodnodeCompletedpostNodeCompletionsetClosureDelegatesetCurrent

Field Detail

documentback to summary
pack-priv Document document
documentBuilderback to summary
pack-priv DocumentBuilder documentBuilder

Constructor Detail

DOMBuilderback to summary
public DOMBuilder(Document document)
DOMBuilderback to summary
public DOMBuilder(DocumentBuilder documentBuilder)

Method Detail

appendNamespaceAttributesback to summary
protected void appendNamespaceAttributes(Element element, Map<Object, Object> attributes)
createDocumentback to summary
protected Document createDocument()
createNodeback to summary
protected Object createNode(Object name)

Implements abstract groovy.util.BuilderSupport.createNode.

createNodeback to summary
protected Object createNode(Object name, Object value)

Implements abstract groovy.util.BuilderSupport.createNode.

createNodeback to summary
protected Object createNode(Object name, Map<K, V> attributes, Object value)

Implements abstract groovy.util.BuilderSupport.createNode.

createNodeback to summary
protected Object createNode(Object name, Map<K, V> attributes)

Implements abstract groovy.util.BuilderSupport.createNode.

newInstanceback to summary
public static DOMBuilder newInstance() throws ParserConfigurationException
newInstanceback to summary
public static DOMBuilder newInstance(boolean validating, boolean namespaceAware) throws ParserConfigurationException
parseback to summary
public static Document parse(Reader reader) throws SAXException, IOException, ParserConfigurationException

Creates 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.

Parameters
reader:Reader

the reader to read the XML text from

Returns:Document

the root node of the parsed tree of Nodes

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
IOException:
An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
ParserConfigurationException:
if a DocumentBuilder cannot be created which satisfies the configuration requested.
See Also
parse(Reader, boolean, boolean)
parseback to summary
public static Document parse(Reader reader, boolean validating, boolean namespaceAware) throws SAXException, IOException, ParserConfigurationException

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. Documents are not allowed to contain DOCYTYPE declarations.

Parameters
reader:Reader

the reader to read the XML text from

validating:boolean

whether to validate the XML

namespaceAware:boolean

whether the parser should be namespace aware

Returns:Document

the root node of the parsed tree of Nodes

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
IOException:
An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
ParserConfigurationException:
if a DocumentBuilder cannot be created which satisfies the configuration requested.
parseback to summary
public static Document parse(Reader reader, boolean validating, boolean namespaceAware, boolean allowDocTypeDeclaration) throws SAXException, IOException, ParserConfigurationException

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.

Parameters
reader:Reader

the reader to read the XML text from

validating:boolean

whether to validate the XML

namespaceAware:boolean

whether the parser should be namespace aware

allowDocTypeDeclaration:boolean

whether the parser should allow DOCTYPE declarations

Returns:Document

the root node of the parsed tree of Nodes

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
IOException:
An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
ParserConfigurationException:
if a DocumentBuilder cannot be created which satisfies the configuration requested.
parseTextback to summary
public Document parseText(String text) throws SAXException, IOException, ParserConfigurationException

A helper method to parse the given text as XML.

Parameters
text:String

the XML text to parse

Returns:Document

the root node of the parsed tree of Nodes

Exceptions
SAXException:
Any SAX exception, possibly wrapping another exception.
IOException:
An IO exception from the parser, possibly from a byte stream or character stream supplied by the application.
ParserConfigurationException:
if a DocumentBuilder cannot be created which satisfies the configuration requested.
See Also
parse(Reader)
setParentback to summary
protected void setParent(Object parent, Object child)

Implements abstract groovy.util.BuilderSupport.setParent.

setQuietlyback to summary
private static void setQuietly(DocumentBuilderFactory factory, String feature, boolean value)
setStringNSback to summary
private static void setStringNS(Element element, Object key, Object value)