Package com.pd4ml.dom

Class Element

    • Method Detail

      • getTagName

        public java.lang.String getTagName()
        The tag name, lower case (e.g. div, pd4ml:page.break).
      • getAttribute

        public java.lang.String getAttribute​(java.lang.String name)
        The attribute value, or null if the element does not have the attribute.
      • hasAttribute

        public boolean hasAttribute​(java.lang.String name)
      • setAttribute

        public void setAttribute​(java.lang.String name,
                                 java.lang.String value)
        Sets an attribute (the name is made lower case). A null value is an empty one.
      • removeAttribute

        public void removeAttribute​(java.lang.String name)
      • getAttributes

        public java.util.Map<java.lang.String,​java.lang.String> getAttributes()
        The attributes in document order (a read-only snapshot).
      • getId

        public java.lang.String getId()
        The id attribute, or an empty string.
      • setId

        public void setId​(java.lang.String id)
      • getClassName

        public java.lang.String getClassName()
        The class attribute, or an empty string.
      • setClassName

        public void setClassName​(java.lang.String className)
      • getClassList

        public java.util.Set<java.lang.String> getClassList()
        The class names (a read-only snapshot).
      • hasClass

        public boolean hasClass​(java.lang.String name)
      • addClass

        public void addClass​(java.lang.String name)
      • removeClass

        public void removeClass​(java.lang.String name)
      • toggleClass

        public boolean toggleClass​(java.lang.String name)
        Adds the class if the element does not have it, removes it otherwise. @return true if added
      • getChildren

        public java.util.List<Element> getChildren()
        The child elements (a snapshot).
      • getFirstElementChild

        public Element getFirstElementChild()
      • getLastElementChild

        public Element getLastElementChild()
      • getNextElementSibling

        public Element getNextElementSibling()
      • getPreviousElementSibling

        public Element getPreviousElementSibling()
      • getElementsByTagName

        public java.util.List<Element> getElementsByTagName​(java.lang.String name)
        The descendant elements with the tag name, in document order (*: all).
      • getElementsByClassName

        public java.util.List<Element> getElementsByClassName​(java.lang.String names)
        The descendant elements that have all the (space separated) class names, in document order.
      • querySelector

        public Element querySelector​(java.lang.String selectors)
        The first descendant element that matches the CSS selector (list), or null.
        Throws:
        java.lang.IllegalArgumentException - if the selector is not valid
      • querySelectorAll

        public java.util.List<Element> querySelectorAll​(java.lang.String selectors)
        The descendant elements that match the CSS selector (list), in document order.
        Throws:
        java.lang.IllegalArgumentException - if the selector is not valid
      • matches

        public boolean matches​(java.lang.String selectors)
        True if this element matches the CSS selector (list).
        Throws:
        java.lang.IllegalArgumentException - if the selector is not valid
      • closest

        public Element closest​(java.lang.String selectors)
        This element or its nearest ancestor that matches the CSS selector (list), or null.
        Throws:
        java.lang.IllegalArgumentException - if the selector is not valid
      • getInnerHTML

        public java.lang.String getInnerHTML()
        The HTML of the element's content.
      • setInnerHTML

        public void setInnerHTML​(java.lang.String html)
        Replaces the element's content with the HTML, parsed as the browser's innerHTML parses it: as the content of an element of this tag (table rows in a <tr>, options in a <select>). The text content of <script>, <style>, <textarea> and <title> is set as is.
      • getOuterHTML

        public java.lang.String getOuterHTML()
        The HTML of the element itself.
      • setOuterHTML

        public void setOuterHTML​(java.lang.String html)
        Replaces the element (in its parent) with the nodes the HTML parses into, as the content of the parent. This element is then detached.
        Throws:
        java.lang.IllegalStateException - if the element has no parent element
      • setTextContent

        public void setTextContent​(java.lang.String text)
        Description copied from class: Node
        Replaces the content of this node with the text: an element's children are replaced by one text node (none for an empty text); a text or comment gets the text as its data.
        Overrides:
        setTextContent in class Node