Package groovy.xml

Class DOMBuilder

  • All Implemented Interfaces:
    groovy.lang.GroovyObject

    public class DOMBuilder
    extends groovy.util.BuilderSupport
    A helper class for creating a W3C DOM tree
    • Constructor Detail

      • DOMBuilder

        public DOMBuilder​(Document document)
    • Method Detail

      • parse

        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 - the reader to read the XML text from
        Returns:
        the root node of the parsed tree of Nodes
        Throws:
        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)
      • parse

        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 - the reader to read the XML text from
        validating - whether to validate the XML
        namespaceAware - whether the parser should be namespace aware
        Returns:
        the root node of the parsed tree of Nodes
        Throws:
        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.
      • parse

        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 - the reader to read the XML text from
        validating - whether to validate the XML
        namespaceAware - whether the parser should be namespace aware
        allowDocTypeDeclaration - whether the parser should allow DOCTYPE declarations
        Returns:
        the root node of the parsed tree of Nodes
        Throws:
        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.
      • setParent

        protected void setParent​(Object parent,
                                 Object child)
        Specified by:
        setParent in class groovy.util.BuilderSupport
      • createNode

        protected Object createNode​(Object name)
        Specified by:
        createNode in class groovy.util.BuilderSupport
      • createDocument

        protected Document createDocument()
      • createNode

        protected Object createNode​(Object name,
                                    Object value)
        Specified by:
        createNode in class groovy.util.BuilderSupport
      • createNode

        protected Object createNode​(Object name,
                                    Map attributes,
                                    Object value)
        Specified by:
        createNode in class groovy.util.BuilderSupport
      • createNode

        protected Object createNode​(Object name,
                                    Map attributes)
        Specified by:
        createNode in class groovy.util.BuilderSupport
      • appendNamespaceAttributes

        protected void appendNamespaceAttributes​(Element element,
                                                 Map<Object,​Object> attributes)