Class Document


  • public final class Document
    extends Node
    The root node of a DOM.
    • Constructor Detail

      • Document

        public Document​(MarkupModel model,
                        java.lang.String encoding)
        Same as Document(model, encoding, null).
        Parameters:
        model - a MarkupModel.
      • Document

        public Document​(MarkupModel model,
                        java.lang.String encoding,
                        java.lang.String mimeType)
        Creates a document instance with a given markup model, encoding and MIME type.
        Parameters:
        model - a MarkupModel.
        encoding - the encoding.
        mimeType - the MIME type.
        Since:
        5.4
    • Method Detail

      • find

        public Element find​(java.lang.String path)
        Finds an element based on a path of element names.
        Parameters:
        path - slash separated series of element names
        Returns:
        the matching element, or null if not found
        See Also:
        Element.find(String)
      • newRootElement

        public Element newRootElement​(java.lang.String name)
        Creates the root element for this document, replacing any previous root element.
      • newRootElement

        public Element newRootElement​(java.lang.String namespace,
                                      java.lang.String name)
        Creates a new root element within a namespace.
        Parameters:
        namespace - URI of namespace containing the element
        name - name of element with namespace
        Returns:
        the root element
      • toMarkup

        public void toMarkup​(Document document,
                             java.io.PrintWriter writer,
                             java.util.Map<java.lang.String,​java.lang.String> namespaceURIToPrefix)
      • getElementById

        public Element getElementById​(java.lang.String id)
        Tries to find an element in this document whose id is specified.
        Parameters:
        id - the value of the id attribute of the element being looked for
        Returns:
        the element if found. null if not found.
      • dtd

        public void dtd​(java.lang.String name,
                        java.lang.String publicId,
                        java.lang.String systemId)
        Sets the DTD for the document, overriding any prior DTD.
        Parameters:
        name - non-blank name of document type (i.e., "html")
        publicId - optional
        systemId - optional
      • comment

        public Document comment​(java.lang.String text)
        Adds the comment and returns this document for further construction.
        Since:
        5.1.0.0
      • raw

        public Document raw​(java.lang.String text)
        Adds the raw text and returns this document for further construction.
        Since:
        5.1.0.0
      • cdata

        public CData cdata​(java.lang.String content)
        Adds and returns a new CDATA node.
        Parameters:
        content - the content to be rendered by the node
        Returns:
        the newly created node
      • getMimeType

        public java.lang.String getMimeType()
        Returns the MIME type of this document.
        Returns:
        the MIME type.
        Since:
        5.4