Class DOMDocument

java.lang.Object
io.sf.carte.doc.dom.DOMDocument
All Implemented Interfaces:
DOMNode, NonDocumentTypeChildNode, ParentNode, CSSDocument, CSSNode, Serializable, Document, Node, DocumentStyle
Direct Known Subclasses:
HTMLDocument

public abstract class DOMDocument extends Object implements CSSDocument

Implementation of a DOM Document.

See Also:
  • Constructor Details

    • DOMDocument

      public DOMDocument(DocumentType documentType)
  • Method Details

    • getCompatMode

      public String getCompatMode()
      Get the compatibility mode (compatMode) attribute.
      Specified by:
      getCompatMode in interface CSSDocument
      Returns:
      the string "BackCompat" if document’s mode is QUIRKS, otherwise "CSS1Compat".
    • getComplianceMode

      public CSSDocument.ComplianceMode getComplianceMode()
      Get the compliance mode of this document.

      The styling in this document operate under a compliance mode. Two modes are supported: STRICT and QUIRKS.

      QUIRKS and STRICT differ in the matching of class and ID selectors, and the default user agent sheet is slightly different.

      Specified by:
      getComplianceMode in interface CSSDocument
      Returns:
      the compliance mode.
    • getDocumentElement

      public DOMElement getDocumentElement()
      Get the child node which is the document element of this document.
      Specified by:
      getDocumentElement in interface CSSDocument
      Specified by:
      getDocumentElement in interface Document
      Returns:
      the document element.
    • getDoctype

      public DocumentType getDoctype()
      Specified by:
      getDoctype in interface Document
    • getNodeName

      public String getNodeName()
      Specified by:
      getNodeName in interface Node
    • getOwnerDocument

      public DOMDocument getOwnerDocument()
      Get the DOMDocument object related to this node (for all nodes except DocumentType, it is the document that created it), which is also the object that should be used to create new nodes for the document.
      Specified by:
      getOwnerDocument in interface CSSNode
      Specified by:
      getOwnerDocument in interface DOMNode
      Specified by:
      getOwnerDocument in interface Node
      Returns:
      the DOMDocument object corresponding to this node. When this node is a DOMDocument or a DocumentType which was not added to any DOMDocument yet, this is null.
    • getParentNode

      public DOMNode getParentNode()
      Specified by:
      getParentNode in interface DOMNode
      Specified by:
      getParentNode in interface Node
    • isVisitedURI

      public boolean isVisitedURI(String href)
      Has this URI been visited by the agent ?
      Specified by:
      isVisitedURI in interface CSSDocument
      Parameters:
      href - the URI.
      Returns:
      true if visited, false if not visited or the agent does not support history.
    • cloneNode

      public DOMDocument cloneNode(boolean deep)
      Specified by:
      cloneNode in interface Node
    • getImplementation

      public abstract CSSDOMImplementation getImplementation()
      Get the DOM implementation that created this document.
      Specified by:
      getImplementation in interface Document
      Returns:
      the DOM implementation that created this document.
    • getStyleSheetFactory

      protected abstract CSSDOMImplementation getStyleSheetFactory()
    • createElement

      public DOMElement createElement(String tagName) throws DOMException
      Creates an element of the type specified, with a null namespace URI.

      The tagName is transformed to lower case.

      No default attributes are created.

      Specified by:
      createElement in interface CSSDocument
      Specified by:
      createElement in interface Document
      Parameters:
      tagName - the tag name of the element to create.
      Returns:
      the new DOMElement.
      Throws:
      DOMException - INVALID_CHARACTER_ERR if the name is not an XML valid name.
    • createElementNS

      public DOMElement createElementNS(String namespaceURI, String qualifiedName) throws DOMException
      Creates an element with the given qualified name and namespace URI.

      If namespaceURI is null or the empty string, the qualifiedName is transformed to lower case.

      No default attributes are created.

      Specified by:
      createElementNS in interface CSSDocument
      Specified by:
      createElementNS in interface Document
      Parameters:
      namespaceURI - the namespace URI of the element to create.
      qualifiedName - the qualified name of the element to create. The namespace prefix, if any, is extracted from this name.
      Returns:
      the new DOMElement.
      Throws:
      DOMException - INVALID_CHARACTER_ERR if the name is not an XML valid name.
      NAMESPACE_ERR: if the qualifiedName is a malformed qualified name, if the qualifiedName has a prefix and the namespaceURI is null, or if the qualifiedName has a prefix that is "xml" and the namespaceURI is different from "http://www.w3.org/XML/1998/namespace" , or if the qualifiedName or its prefix is "xmlns" and the namespaceURI is different from "http://www.w3.org/2000/xmlns/", or if the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the qualifiedName nor its prefix is "xmlns".
    • createDocumentFragment

      public DocumentFragment createDocumentFragment()
      Specified by:
      createDocumentFragment in interface Document
    • createTextNode

      public Text createTextNode(String data)
      Specified by:
      createTextNode in interface Document
    • createComment

      public Comment createComment(String data)
      Specified by:
      createComment in interface Document
    • createCDATASection

      public CDATASection createCDATASection(String data) throws DOMException
      Specified by:
      createCDATASection in interface Document
      Throws:
      DOMException
    • createProcessingInstruction

      public ProcessingInstruction createProcessingInstruction(String target, String data) throws DOMException
      Specified by:
      createProcessingInstruction in interface Document
      Throws:
      DOMException
    • createEntityReference

      public EntityReference createEntityReference(String name) throws DOMException
      Specified by:
      createEntityReference in interface Document
      Throws:
      DOMException
    • createAttribute

      public Attr createAttribute(String name) throws DOMException
      Specified by:
      createAttribute in interface Document
      Throws:
      DOMException
    • createAttributeNS

      public Attr createAttributeNS(String namespaceURI, String qualifiedName) throws DOMException
      Specified by:
      createAttributeNS in interface Document
      Throws:
      DOMException
    • createNodeIterator

      public NodeIterator createNodeIterator(Node rootNode, int whatToShow, NodeFilter filter)
      Create a NodeIterator object with the given root node, whatToShow bitmask, and filter callback.

      Example:

       NodeIterator it = document.createNodeIterator(document.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null);
       

      Based on the createNodeIterator() method in DOM Level 4.

      The returned object can be cast to NodeIterator, but the behaviour is not exactly what that interface documents (see this library's NodeIterator interface description for more details). If you need compatibility with the W3C-specified behaviour, never use a NodeFilter that returns NodeFilter.FILTER_SKIP_NODE_CHILD (that is, W3C's NodeFilter.FILTER_REJECT).

      Parameters:
      rootNode - the root node.
      whatToShow - a bitmask specifying what types of nodes to show.
      filter - an optional filter callback, see NodeFilter.
      Returns:
      the node iterator.
    • createTreeWalker

      public TreeWalker createTreeWalker(Node rootNode, int whatToShow, NodeFilter filter)
      Create a TreeWalker object with the given root node, whatToShow bitmask, and filter callback.

      Example:

       TreeWalker tw = document.createTreeWalker(document.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null);
       

      Based on the createTreeWalker() method in DOM Level 4.

      Beware that this library's NodeFilter uses names different to W3C's for the filter values: NodeFilter.FILTER_SKIP_NODE_CHILD instead of W3C's NodeFilter.FILTER_REJECT), and NodeFilter.FILTER_SKIP_NODE instead of NodeFilter.FILTER_SKIP. But the defined numeric values are the same, so they can be used interchangeably in the TreeWalker.

      Parameters:
      rootNode - the root node.
      whatToShow - a bitmask specifying what types of nodes to show.
      filter - an optional filter callback, see NodeFilter.
      Returns:
      the tree walker.
    • getElementsByClassName

      public ElementList getElementsByClassName(String names)
      Gives a live NodeList containing all child elements which have all of the given class names under this reference element.
      Specified by:
      getElementsByClassName in interface ParentNode
      Parameters:
      names - the names of the classes, separated by whitespace.
      Returns:
      the live NodeList containing all child elements which have all of the given class names under this reference element.
    • lookupPrefix

      public String lookupPrefix(String namespaceURI)
      Specified by:
      lookupPrefix in interface Node
    • getElementById

      public DOMElement getElementById(String elementId)
      Returns the Element that has an ID attribute with the given value.

      If no such element exists, this returns null. If more than one element has an ID attribute with that value, what is returned is undefined.

      This implementation uses 'id' as the ID attribute, case insensitively in QUIRKS mode.

      Specified by:
      getElementById in interface CSSDocument
      Specified by:
      getElementById in interface Document
      Parameters:
      elementId - The unique id value for an element.
      Returns:
      The matching element or null if there is none.
    • getInputEncoding

      public String getInputEncoding()
      Give the encoding used when the document was parsed, if known.
      Specified by:
      getInputEncoding in interface Document
      Returns:
      null.
    • getXmlEncoding

      @Deprecated public String getXmlEncoding()
      Deprecated.
      Now deprecated, this method gave the encoding specified at the XML declaration.
      Specified by:
      getXmlEncoding in interface Document
      Returns:
      null.
    • getXmlStandalone

      @Deprecated public boolean getXmlStandalone()
      Deprecated.
      Get whether this document is standalone as specified at the XML declaration.
      Specified by:
      getXmlStandalone in interface Document
      Returns:
      null.
    • setXmlStandalone

      @Deprecated public void setXmlStandalone(boolean xmlStandalone) throws DOMException
      Deprecated.
      Set whether this document is standalone as specified at the XML declaration.

      Calling this method has no effect.

      Specified by:
      setXmlStandalone in interface Document
      Parameters:
      xmlStandalone - argument is ignored.
      Throws:
      DOMException
    • getXmlVersion

      @Deprecated public String getXmlVersion()
      Deprecated.
      Get the version for the "XML" feature.
      Specified by:
      getXmlVersion in interface Document
      Returns:
      null.
    • setXmlVersion

      @Deprecated public void setXmlVersion(String xmlVersion) throws DOMException
      Deprecated.
      Set the version for the "XML" feature.
      Specified by:
      setXmlVersion in interface Document
      Parameters:
      xmlVersion - this parameter is ignored.
      Throws:
      DOMException
    • getStrictErrorChecking

      public boolean getStrictErrorChecking()
      Specified by:
      getStrictErrorChecking in interface Document
    • setStrictErrorChecking

      public void setStrictErrorChecking(boolean strictErrorChecking)
      Specified by:
      setStrictErrorChecking in interface Document
    • getDocumentURI

      public String getDocumentURI()
      Gets the location of this document.
      Specified by:
      getDocumentURI in interface Document
      Returns:
      the location of this document, or null if not set.
    • setDocumentURI

      public void setDocumentURI(String documentURI)
      Sets the location of this document.

      For security reasons, if you want to retrieve linked style sheets from local URLs (like file:), you need to set the documentURI to a local scheme (file: or jar:) as well.

      No lexical checking is performed when setting this attribute; this could result in a null value returned when using getBaseURI().

      Specified by:
      setDocumentURI in interface Document
      Parameters:
      documentURI - the document URI.
    • importNode

      public Node importNode(Node importedNode, boolean deep) throws DOMException
      Specified by:
      importNode in interface Document
      Throws:
      DOMException
    • adoptNode

      public Node adoptNode(Node source) throws DOMException
      Specified by:
      adoptNode in interface Document
      Throws:
      DOMException
    • insertBefore

      public DOMNode insertBefore(Node newChild, Node refChild) throws DOMException
      Inserts the node newChild right before node refChild in the child node list.
      • If refChild is null, newChild is appended at the end of the child list.
      • If the newChild is already in the tree, it is first removed.
      • Inserting a node before itself has no effect.
      Specified by:
      insertBefore in interface DOMNode
      Specified by:
      insertBefore in interface Node
      Parameters:
      newChild - the node to put at the child node list, before refChild. If it is a DocumentFragment object, the entire contents of the document fragment are inserted into the child list of this node.
      refChild - the node before which newChild must be inserted.
      Returns:
      the inserted node.
      Throws:
      DOMException - HIERARCHY_REQUEST_ERR: raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to append a second DocumentType or Element node.
      WRONG_DOCUMENT_ERR: if newChild was created from a different document than the one that created this node.
      NOT_FOUND_ERR: if refChild is not a child of this node.
      NOT_SUPPORTED_ERR: if this implementation does not support children of the type of newChild at this node.
    • replaceChild

      public DOMNode replaceChild(Node newChild, Node oldChild) throws DOMException
      Replaces the node oldChild with newChild. If the newChild is already in the tree, it is first removed.

      Replacing a node with itself has no effect.

      Specified by:
      replaceChild in interface DOMNode
      Specified by:
      replaceChild in interface Node
      Parameters:
      newChild - the node to put at the child node list, in place of oldChild. If it is a DocumentFragment object, the entire contents of the document fragment are inserted into the child list of this node.
      oldChild - the node being replaced.
      Returns:
      the replaced (old) node.
      Throws:
      DOMException - HIERARCHY_REQUEST_ERR: raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to append a second DocumentType or Element node.
      WRONG_DOCUMENT_ERR: if newChild was created from a different document than the one that created this node.
      NOT_FOUND_ERR: if oldChild is not a child of this node.
      NOT_SUPPORTED_ERR: if this implementation does not support children of the type of newChild at this node.
    • renameNode

      @Deprecated public Node renameNode(Node n, String namespaceURI, String qualifiedName) throws DOMException
      Deprecated.
      Specified by:
      renameNode in interface Document
      Throws:
      DOMException
    • getDomConfig

      public DOMConfiguration getDomConfig()

      Only the normalize-characters and comments parameters are configurable and can be toggled. Other parameters can only be set to defaults (or cannot be set at all, like split-cdata-sections because the implementation does not allow split CDATA), and well-formed is just ignored (malformed characters are not allowed in this implementation).

      Also supports the proprietary:

      css-whitespace-processing
      Defaults to true and enables CSS-like whitespace processing, much safer than just removing element content whitespace.
      use-computed-styles
      If true -defaults to false-, uses computed styles to determine the value of the white-space CSS property when handling css-whitespace-processing.
      Specified by:
      getDomConfig in interface Document
    • normalizeDocument

      public void normalizeDocument()
      Normalizes the document element, if there is one.
      Specified by:
      normalizeDocument in interface Document
    • lookupNamespaceURI

      public String lookupNamespaceURI(String prefix)
      Specified by:
      lookupNamespaceURI in interface Node
    • isDefaultNamespace

      public boolean isDefaultNamespace(String namespaceURI)
      Specified by:
      isDefaultNamespace in interface Node
    • registerProperty

      public void registerProperty(CSSPropertyDefinition definition)
      Description copied from interface: CSSDocument
      Registers the definition of a custom property.
      Specified by:
      registerProperty in interface CSSDocument
      Parameters:
      definition - the definition.
      See Also:
    • getStyleSheets

      public StyleSheetList getStyleSheets()
      A list containing all the style sheets explicitly linked into or embedded in a document. For HTML documents, this includes external style sheets, included via the HTML LINK element, and inline STYLE elements. In XML, this includes external style sheets, included via style sheet processing instructions (see [XML StyleSheet]).
      Specified by:
      getStyleSheets in interface CSSDocument
      Specified by:
      getStyleSheets in interface DocumentStyle
    • getStyleSheet

      public DocumentCSSStyleSheet getStyleSheet()
      Gets the merged style sheet that applies to this document, resulting from the merge of the document's default style sheet, the document linked or embedded style sheets, and the non-important part of the user style sheet. Does not include overriden styles nor the 'important' part of the user-defined style sheet.

      The style sheet is lazily built.

      Specified by:
      getStyleSheet in interface CSSDocument
      Returns:
      the merged style sheet that applies to this document.
    • getStyleSheetSets

      public DOMStringList getStyleSheetSets()
      Gets the list of available alternate styles.
      Specified by:
      getStyleSheetSets in interface CSSDocument
      Returns:
      the list of available alternate style titles.
    • getSelectedStyleSheetSet

      public String getSelectedStyleSheetSet()
      Gets the title of the currently selected style sheet set.
      Specified by:
      getSelectedStyleSheetSet in interface CSSDocument
      Returns:
      the title of the currently selected style sheet, the empty string if none is selected, or null if there are style sheets from different style sheet sets that have their style sheet disabled flag unset.
    • setSelectedStyleSheetSet

      public void setSelectedStyleSheetSet(String name)
      Selects a style sheet set, disabling the other non-persistent sheet sets. If the name is the empty string, all non-persistent sheets will be disabled. Otherwise, if the name does not match any of the sets, does nothing.
      Specified by:
      setSelectedStyleSheetSet in interface CSSDocument
      Parameters:
      name - the case-sensitive name of the set to select.
    • getLastStyleSheetSet

      public String getLastStyleSheetSet()
      Gets the style sheet set that was last selected.
      Specified by:
      getLastStyleSheetSet in interface CSSDocument
      Returns:
      the last selected style sheet set, or null if none.
    • enableStyleSheetsForSet

      public void enableStyleSheetsForSet(String name)
      Enables a style sheet set. If the name does not match any of the sets, does nothing.
      Specified by:
      enableStyleSheetsForSet in interface CSSDocument
      Parameters:
      name - the case-sensitive name of the set to enable.
    • getStyleDatabase

      public StyleDatabase getStyleDatabase()
      Gets the style database currently used to apply specific styles to this document.
      Specified by:
      getStyleDatabase in interface CSSDocument
      Returns:
      the style database, or null if no style database has been selected.
    • getTargetMedium

      public String getTargetMedium()
      This document's current target medium name.
      Specified by:
      getTargetMedium in interface CSSDocument
      Returns:
      the target medium name of this document.
    • setTargetMedium

      public void setTargetMedium(String medium) throws CSSMediaException
      Set the medium that will be used to compute the styles of this document.
      Specified by:
      setTargetMedium in interface CSSDocument
      Parameters:
      medium - the name of the target medium, like 'screen' or 'print'.
      Throws:
      CSSMediaException - if the document is unable to target the given medium.
    • getCanvas

      public CSSCanvas getCanvas()
      Gets the document's canvas for the current target medium.
      Specified by:
      getCanvas in interface CSSDocument
      Returns:
      the canvas, or null if no target medium has been set, or the DeviceFactory does not support canvas for the target medium.
    • rebuildCascade

      public void rebuildCascade()
      Description copied from interface: CSSDocument
      Forces the cascade to be rebuilt the next time that a computed style is obtained.

      This method should be called after you modify the styles in a way that is not detected by the library (like modifying a value).

      Specified by:
      rebuildCascade in interface CSSDocument
    • getErrorHandler

      public ErrorHandler getErrorHandler()
      Description copied from interface: CSSDocument
      Gets the document-level error handler.
      Specified by:
      getErrorHandler in interface CSSDocument
      Returns:
      the error handler.
    • hasStyleIssues

      public boolean hasStyleIssues()
      Has any of the linked or embedded style sheets any error or warning ?
      Specified by:
      hasStyleIssues in interface CSSDocument
      Returns:
      true if any of the linked or embedded style sheets has any SAC or rule error or warning, false otherwise.
    • onMetaAdded

      public void onMetaAdded(String name, String attribute)
      Notify the document about the addition of a META element that may affect the inner workings of this document.

      This method avoids having to rescan META elements for each style-related operation.

      Parameters:
      name - the META name.
      attribute - the attribute.
    • onMetaRemoved

      public void onMetaRemoved(String name, String attribute)
      Notify the document about the removal of a META element that may affect the inner workings of this document.

      This method avoids having to rescan META elements for each style-related operation.

      Parameters:
      name - the META name.
      attribute - the attribute.
    • getBaseURL

      public URL getBaseURL()
      Gets the base URL of this Document.

      If the Document's head element has a base child element, the base URI is computed using the value of the href attribute of the base element.

      Specified by:
      getBaseURL in interface CSSDocument
      Returns:
      the base URL, or null if no base URL could be found.
    • getBaseURI

      public String getBaseURI()
      Gets the absolute base URI of this node.
      Specified by:
      getBaseURI in interface Node
      Returns:
      the absolute base URI of this node, or null if an absolute URI could not be obtained.
    • getURL

      public URL getURL(String uri) throws MalformedURLException
      Gets an URL for the given URI, taking into account the Base URL if appropriate.
      Specified by:
      getURL in interface CSSDocument
      Parameters:
      uri - the uri.
      Returns:
      the absolute URL.
      Throws:
      MalformedURLException - if the uri was wrong.
    • isSafeOrigin

      public boolean isSafeOrigin(URL linkedURL)
      Is the provided URL a safe origin to load certain external resources?
      Specified by:
      isSafeOrigin in interface CSSDocument
      Parameters:
      linkedURL - the URL of the external resource.
      Returns:
      true if is a safe origin, false otherwise.
    • isAuthorizedOrigin

      public boolean isAuthorizedOrigin(URL url)
      Determine whether the retrieval of the given URL is authorized.

      If the URL's protocol is not http nor https and document's base URL's scheme is neither file nor jar, it is denied.

      Developers may want to override this implementation to enforce different restrictions.

      Specified by:
      isAuthorizedOrigin in interface CSSDocument
      Parameters:
      url - the URL to check.
      Returns:
      true if allowed.
    • getReferrerPolicy

      public String getReferrerPolicy()
      Get the referrer policy obtained through the 'Referrer-Policy' header or a meta element.
      Specified by:
      getReferrerPolicy in interface CSSDocument
      Returns:
      the referrer policy, or the empty string if none was specified.
    • setReferrerPolicyHeader

      protected void setReferrerPolicyHeader(String policy)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • openStream

      public InputStream openStream(String uri) throws IOException
      Opens an InputStream for the given URI, taking into account the Base URL if needed.
      Parameters:
      uri - the uri to open a connection.
      Returns:
      the InputStream.
      Throws:
      IOException - if the uri was wrong, or the stream could not be opened.
    • getChildren

      public ElementList getChildren()
      Gets the live ElementList containing all nodes of type Element that are children of this Element.
      Specified by:
      getChildren in interface ParentNode
      Returns:
      the ElementList containing all nodes of type Element that are children of this Element.
    • querySelector

      public DOMElement querySelector(String selectors)
      Returns the first element that is a descendant of this node and matches the given selector list.
      Parameters:
      selectors - a comma-separated list of selectors.
      Returns:
      the first element matching the selectors.
    • querySelectorAll

      public ElementList querySelectorAll(String selectors)
      Gets a static list of the elements that match any of the specified group of selectors.

      Unlike methods like ParentNode.getElementsByTagName(String) or ParentNode.getElementsByClassName(String), this is not a live list but a static one, representing the state of the document when the method was called. If no elements match, the list will be empty.

      Specified by:
      querySelectorAll in interface ParentNode
      Parameters:
      selectors - a comma-separated list of selectors.
      Returns:
      an ElementList with the elements that match any of the specified group of selectors.
    • iterator

      public Iterator<DOMNode> iterator()
      Creates a new iterator over the child nodes.
      Specified by:
      iterator in interface ParentNode
      Returns:
      an iterator over the child nodes.
    • descendingIterator

      public Iterator<DOMNode> descendingIterator()
      Creates a new iterator descending over the child nodes, starting from the last child node.
      Specified by:
      descendingIterator in interface ParentNode
      Returns:
      an iterator descending over the child nodes.
    • iterator

      public Iterator<DOMNode> iterator(BitSet whatToShow)
      Creates a new iterator over the child nodes.

      It only iterates over types set in the whatToShow bit field.

      Example:

            BitSet mask = new BitSet(32);
            mask.set(Node.ELEMENT_NODE);
            Iterator<Node> it = node.iterator(mask);
       
      Specified by:
      iterator in interface ParentNode
      Parameters:
      whatToShow - a bit set.
      Returns:
      an iterator over the child nodes.
    • elementIterator

      public Iterator<DOMElement> elementIterator()
      Creates a new iterator over the child elements.
      Specified by:
      elementIterator in interface ParentNode
      Returns:
      an iterator over the child elements.
    • elementIterator

      public Iterator<DOMElement> elementIterator(String tagname)
      Creates a new iterator over the child elements of the given tagname.
      Specified by:
      elementIterator in interface ParentNode
      Parameters:
      tagname - The tag name of the child elements to match on.
      Returns:
      an iterator over the child elements.
    • elementIteratorNS

      public Iterator<DOMElement> elementIteratorNS(String namespaceURI, String localName)
      Creates a new iterator over the child elements of the given namespaceURI and localName.
      Specified by:
      elementIteratorNS in interface ParentNode
      Parameters:
      namespaceURI - the namespace URI of the elements to match on.
      localName - The local name of the elements to match on.
      Returns:
      an iterator over the child elements.
    • iterator

      public Iterator<DOMNode> iterator(int whatToShow, NodeFilter filter)
      Creates a new iterator over the child nodes.

      It only iterates over types set in the whatToShow mask that satisfy the custom NodeFilter.

      Example:

       Iterator<Node> it = node.iterator(NodeFilter.SHOW_ELEMENT, null);
       
      Specified by:
      iterator in interface ParentNode
      Parameters:
      whatToShow - the bit field mask to apply to the node types, see NodeFilter. Do not confuse this argument with the short argument of the ParentNode.typeIterator(short) method.
      filter - the filter to use in the iteration. if null, only the whatToShow mask filter is applied.
      Returns:
      an iterator over the child nodes.
    • typeIterator

      public Iterator<DOMNode> typeIterator(short typeToShow)
      Creates a new iterator over the child nodes.

      Do not confuse the typeToShow argument with the int argument of the ParentNode.iterator(int, NodeFilter) method, which is a bit field.

      Specified by:
      typeIterator in interface ParentNode
      Parameters:
      typeToShow - the node type to show (from Node.getNodeType()).
      Returns:
      an iterator over the child nodes.
    • iterator

      public Iterator<DOMNode> iterator(NodeFilter filter)
      Creates a new iterator over the child nodes.

      It only iterates over nodes accepted by the filter.

      Specified by:
      iterator in interface ParentNode
      Parameters:
      filter - a filter, see NodeFilter.
      Returns:
      an iterator over the child nodes.
    • listIterator

      public NodeListIterator listIterator()
      Creates a new list iterator over the child nodes.
      Specified by:
      listIterator in interface ParentNode
      Returns:
      a list iterator over the child nodes.
    • getElementsByTagNameNS

      public ElementList getElementsByTagNameNS(String namespaceURI, String localName)
      Gives an ElementList of all the elements descending from this context node that have the given local name and namespace URI, in document order.

      The list is a live collection, and changes to the document made after calling this method are reflected in the ElementList.

      The most efficient way to browse the returned list is to iterate it.

      Specified by:
      getElementsByTagNameNS in interface ParentNode
      Parameters:
      namespaceURI - the namespace URI of the elements to match on. The special value "*" matches all namespaces.
      localName - The local name of the elements to match on. The special value "*" matches all local names.
      Returns:
      the ElementList object containing all the matched elements.
    • getElementsByTagName

      public ElementList getElementsByTagName(String name)
      Gives an ElementList of all the elements descending from this context node that have the given tag name, in document order.

      The list is a live collection, and changes to the document made after calling this method are reflected in the ElementList.

      The most efficient way to browse the returned list is to iterate it.

      Specified by:
      getElementsByTagName in interface ParentNode
      Parameters:
      name - The tag name of the elements to match on. The special value "*" matches all tag names.
      Returns:
      the ElementList object containing all the matched elements.
    • getFirstElementChild

      public DOMElement getFirstElementChild()
      Gets the Element that is the first child of this ParentNode.
      Returns:
      the Element that is the first child of this ParentNode, or null if there is none.
    • getLastElementChild

      public DOMElement getLastElementChild()
      Gets the DOMElement that is the last child of this ParentNode.
      Returns:
      the DOMElement that is the last child of this ParentNode, or null if there is none.
    • getChildElementCount

      public int getChildElementCount()
      Gets the number of child nodes of type Element that this parent node has.
      Returns:
      the number of child nodes of type Element that this ParentNode has.
    • hasChildNodes

      public boolean hasChildNodes()
      Description copied from interface: DOMNode
      Does this node have any child nodes ?
      Specified by:
      hasChildNodes in interface DOMNode
      Specified by:
      hasChildNodes in interface Node
      Returns:
      true if this node has child nodes, false otherwise.
    • getPreviousElementSibling

      public DOMElement getPreviousElementSibling()
      Description copied from interface: NonDocumentTypeChildNode
      Gets the first preceding sibling that is an element.
      Specified by:
      getPreviousElementSibling in interface NonDocumentTypeChildNode
      Returns:
      the first preceding sibling that is an element, and null otherwise.
    • getNextElementSibling

      public DOMElement getNextElementSibling()
      Description copied from interface: NonDocumentTypeChildNode
      Gets the first following sibling that is an element.
      Specified by:
      getNextElementSibling in interface NonDocumentTypeChildNode
      Returns:
      the first following sibling that is an element, and null otherwise.
    • prependChild

      public DOMNode prependChild(Node newChild) throws DOMException
      Throws:
      DOMException
    • getNodeValue

      public String getNodeValue() throws DOMException
      Specified by:
      getNodeValue in interface Node
      Throws:
      DOMException
    • setNodeValue

      public void setNodeValue(String nodeValue) throws DOMException
      Specified by:
      setNodeValue in interface Node
      Throws:
      DOMException
    • getNodeType

      public short getNodeType()
      Specified by:
      getNodeType in interface Node
    • getLocalName

      public String getLocalName()
      Gives the local part of the qualified name of this node. For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE, this is always null.
      Specified by:
      getLocalName in interface Node
      Returns:
      the local part of the qualified name of this node, or null if this node is not an ELEMENT_NODE nor an ATTRIBUTE_NODE.
    • getAttributes

      public NamedNodeMap getAttributes()
      Specified by:
      getAttributes in interface Node
    • hasAttributes

      public boolean hasAttributes()
      Specified by:
      hasAttributes in interface Node
    • getChildNodes

      public DOMNodeList getChildNodes()
      Description copied from interface: DOMNode
      Get the children of this node.
      Specified by:
      getChildNodes in interface DOMNode
      Specified by:
      getChildNodes in interface Node
      Returns:
      a DOMNodeList with the children of this node. If there are no children, an empty list is returned.
    • getFirstChild

      public DOMNode getFirstChild()
      Description copied from interface: DOMNode
      Get the first child of this node.
      Specified by:
      getFirstChild in interface DOMNode
      Specified by:
      getFirstChild in interface Node
      Returns:
      the first child of this node, null if has no child nodes.
    • getLastChild

      public DOMNode getLastChild()
      Description copied from interface: DOMNode
      Get the last child of this node.
      Specified by:
      getLastChild in interface DOMNode
      Specified by:
      getLastChild in interface Node
      Returns:
      the last child of this node, null if has no child nodes.
    • getPreviousSibling

      public DOMNode getPreviousSibling()
      Description copied from interface: DOMNode
      Get the node immediately preceding this node in its parent's child list.
      Specified by:
      getPreviousSibling in interface DOMNode
      Specified by:
      getPreviousSibling in interface Node
      Returns:
      the node immediately preceding this node in the child list, or null if none.
    • getNextSibling

      public DOMNode getNextSibling()
      Description copied from interface: DOMNode
      Get the node immediately following this node in its parent's child list.
      Specified by:
      getNextSibling in interface DOMNode
      Specified by:
      getNextSibling in interface Node
      Returns:
      the node immediately following this node in the child list, or null if none.
    • appendChild

      public DOMNode appendChild(Node newChild) throws DOMException
      Description copied from interface: DOMNode
      Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.
      Specified by:
      appendChild in interface DOMNode
      Specified by:
      appendChild in interface Node
      Parameters:
      newChild - the node to append. If it is a DocumentFragment object, the entire contents of the document fragment are moved into the child list of this node.
      Returns:
      the appended node.
      Throws:
      DOMException - HIERARCHY_REQUEST_ERR: raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to append is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to append a second DocumentType or Element node.
      WRONG_DOCUMENT_ERR: if newChild was created from a different document than the one that created this node.
      NOT_SUPPORTED_ERR: if this implementation does not support children of the type of newChild at this node.
    • removeChild

      public DOMNode removeChild(Node oldChild) throws DOMException
      Description copied from interface: DOMNode
      Removes the node oldChild from the children of this node.
      Specified by:
      removeChild in interface DOMNode
      Specified by:
      removeChild in interface Node
      Parameters:
      oldChild - the node to remove.
      Returns:
      the removed node.
      Throws:
      DOMException - NOT_FOUND_ERR: if oldChild is not a child of this node.
    • removeAllChild

      public void removeAllChild()
      Description copied from interface: DOMNode
      Removes all the children from this node, if any.
      Specified by:
      removeAllChild in interface DOMNode
    • setUserData

      public Object setUserData(String key, Object data, UserDataHandler handler)
      Specified by:
      setUserData in interface Node
    • getUserData

      public Object getUserData(String key)
      Specified by:
      getUserData in interface Node
    • normalize

      public void normalize()
      Specified by:
      normalize in interface Node
    • getFeature

      @Deprecated public Object getFeature(String feature, String version)
      Deprecated.
      This method is deprecated and not supported.
      Specified by:
      getFeature in interface Node
      Parameters:
      feature - ignored.
      version - ignored.
      Returns:
      null.
    • isSupported

      @Deprecated public boolean isSupported(String feature, String version)
      Deprecated.
      This method is not supported.
      Specified by:
      isSupported in interface Node
      Parameters:
      feature - ignored.
      version - ignored.
      Returns:
      Always true.
    • compareDocumentPosition

      public short compareDocumentPosition(Node other) throws DOMException
      Specified by:
      compareDocumentPosition in interface Node
      Throws:
      DOMException
    • getTextContent

      public String getTextContent() throws DOMException
      Specified by:
      getTextContent in interface Node
      Throws:
      DOMException
    • setTextContent

      public void setTextContent(String textContent) throws DOMException
      Specified by:
      setTextContent in interface Node
      Throws:
      DOMException
    • getNamespaceURI

      public String getNamespaceURI()
      Specified by:
      getNamespaceURI in interface Node
    • getPrefix

      public String getPrefix()
      Specified by:
      getPrefix in interface Node
    • setPrefix

      public void setPrefix(String prefix) throws DOMException
      Specified by:
      setPrefix in interface Node
      Throws:
      DOMException
    • isEqualNode

      public boolean isEqualNode(Node arg)
      Specified by:
      isEqualNode in interface Node
    • isSameNode

      public boolean isSameNode(Node other)
      Specified by:
      isSameNode in interface Node
    • contains

      public boolean contains(Node node)
      Test if node is an inclusive descendant of this node.
      Parameters:
      node - the node to test.
      Returns:
      true if node is an inclusive descendant of this node, false otherwise (including node being null).