Class DOMBuilder

  • public final class DOMBuilder
    extends Object
    Document builder class. This class provides an intuitive interface for incrementally building DOM documents.
    • Constructor Detail

      • DOMBuilder

        public DOMBuilder​(String name)
                   throws ParserConfigurationException
        Creates a builder for a new DOM document. A new DOM document is instantiated and initialized to contain a root element with the given name. The root element is set as the current element of this builder.
        name - name of the root element
        ParserConfigurationException - if a document cannot be created
    • Method Detail

      • write

        public void write​(OutputStream xml)
                   throws IOException
        Writes the document built by this builder into the given output stream. This method is normally invoked only when the document is fully built.
        xml - XML output stream
        IOException - if the document could not be written
      • startElement

        public void startElement​(String name)
        Creates a new element with the given name as the child of the current element and makes the created element current. The endElement method needs to be called to return back to the original element.
        name - name of the new element
      • endElement

        public void endElement()
        Makes the parent element current. This method should be invoked after a child element created with the startElement method has been fully built.
      • setAttribute

        public void setAttribute​(String name,
                                 String value)
        Sets the named attribute of the current element.
        name - attribute name
        value - attribute value
      • setAttribute

        public void setAttribute​(String name,
                                 boolean value)
        Sets the named boolean attribute of the current element.
        name - attribute name
        value - boolean attribute value
      • addContent

        public void addContent​(String content)
        Adds the given string as text content to the current element.
        content - text content
      • addContentElement

        public void addContentElement​(String name,
                                      String content)
        Adds a new child element with the given name and text content. The created element will contain no attributes and no child elements of its own.
        name - child element name
        content - child element content