public class HTMLElement
ImplementsIterable<Element>
The HTMLElement class defines a single HTML element with its attributes and children.
Due to its hierarchial nature, this class can be used for a single “leaf” Element, for more complex elements (with child elements), and up to describing the entire document.
Fields
Constructors
protected HTMLElement() | Constructs and HTMLElement without specifying a name. |
public HTMLElement(String tagName) | Constructor for HTMLElement. |
public HTMLElement(String tagName, boolean isTextElement) | Constructor for HTMLElement. |
Methods
public int setAttribute(String attribute, String value) | Adds the specified attribute and value to this Element if it is supported for the Element and has a valid value. |
public void setAttributeById(int attrId, String value) | Allows setting an attribute with an attribute id |
public void removeAttributeById(int attrId) | Removes the specified attribute |
public String getSupportedAttributesList() | Returns a list of supported attributes for this tag. |
public String getTagName() | Returns this HTMLElement’s tag name |
public int getTagId() | Returns this HTMLElement’s ID |
protected void setTagId(int tagId) | Sets this HTMLElement’s ID |
public HTMLElement getFirstChildByTagId(int tagId) | Returns an HTMLElement’s child by a tag ID (One of the TAG_* constants) |
public String getAttributeById(int id) | Returns an HTMLElement’s attribute by the attribute’s ID (One of the ATTR_* constants) |
public String toString() | {Returns a printable string representing this element} |
public String getAttributeName(Integer attrKey) | Returns the attribute name of the requested attribute |
public String getAttribute(String name) | Returns the attribute value by its name (or null if it wasn’t defined for this element) |
public String toString(String spacing) | A recursive method for creating a printout of a full tag with its entire hierarchy. |
public void removeChildAt(int index) | {Removes the child at the given index} |
public Vector getDescendantsByTagId(int tagId, int depth) | Returns all descendants with the specified tag id |
public Vector getDescendantsByTagId(int tagId) | Returns all descendants with the specified tag id |
Inherited fields
Inherited methods
From Element
isTextElement, setTextElement, setTagName, getAttributes, setAttribute, addChild, getParent, setParent, getNumChildren, getChildren, setChildren, getChildAt, getFirstChildByTagName, getElementById, getDescendantsByTagNameAndAttribute, getDescendantsByTagName, getDescendantsByTagName, getChildrenByTagName, getTextDescendants, getTextDescendants, getTextChildren, contains, removeAttribute, removeAttribute, getAttributeAsInt, getChildIndex, insertChildAt, replaceChild, getText, setText, hasTextChild, isEmpty, iterator
Field details
TAG_CSS_ILLEGAL_SELECTOR
public static final int TAG_CSS_ILLEGAL_SELECTOR = -3///////////////////////////////
TAG_CSS_SELECTOR
public static final int TAG_CSS_SELECTOR = -2TAG_UNSUPPORTED
public static final int TAG_UNSUPPORTED = -1TAG_BODY
public static final int TAG_BODY = 0TAG_HEAD
public static final int TAG_HEAD = 1TAG_HTML
public static final int TAG_HTML = 2TAG_TITLE
public static final int TAG_TITLE = 3TAG_ABBR
public static final int TAG_ABBR = 4TAG_ACRONYM
public static final int TAG_ACRONYM = 5TAG_ADDRESS
public static final int TAG_ADDRESS = 6TAG_BLOCKQUOTE
public static final int TAG_BLOCKQUOTE = 7TAG_BR
public static final int TAG_BR = 8TAG_CITE
public static final int TAG_CITE = 9TAG_CODE
public static final int TAG_CODE = 10TAG_DFN
public static final int TAG_DFN = 11TAG_DIV
public static final int TAG_DIV = 12TAG_EM
public static final int TAG_EM = 13TAG_H1
public static final int TAG_H1 = 14TAG_H2
public static final int TAG_H2 = 15TAG_H3
public static final int TAG_H3 = 16TAG_H4
public static final int TAG_H4 = 17TAG_H5
public static final int TAG_H5 = 18TAG_H6
public static final int TAG_H6 = 19TAG_KBD
public static final int TAG_KBD = 20TAG_P
public static final int TAG_P = 21TAG_PRE
public static final int TAG_PRE = 22TAG_Q
public static final int TAG_Q = 23TAG_SAMP
public static final int TAG_SAMP = 24TAG_SPAN
public static final int TAG_SPAN = 25TAG_STRONG
public static final int TAG_STRONG = 26TAG_VAR
public static final int TAG_VAR = 27TAG_A
public static final int TAG_A = 28TAG_DL
public static final int TAG_DL = 29TAG_DT
public static final int TAG_DT = 30TAG_DD
public static final int TAG_DD = 31TAG_OL
public static final int TAG_OL = 32TAG_UL
public static final int TAG_UL = 33TAG_LI
public static final int TAG_LI = 34TAG_FORM
public static final int TAG_FORM = 35TAG_INPUT
public static final int TAG_INPUT = 36TAG_LABEL
public static final int TAG_LABEL = 37TAG_SELECT
public static final int TAG_SELECT = 38TAG_OPTION
public static final int TAG_OPTION = 39TAG_TEXTAREA
public static final int TAG_TEXTAREA = 40TAG_CAPTION
public static final int TAG_CAPTION = 41TAG_TABLE
public static final int TAG_TABLE = 42TAG_TD
public static final int TAG_TD = 43TAG_TH
public static final int TAG_TH = 44TAG_TR
public static final int TAG_TR = 45TAG_IMG
public static final int TAG_IMG = 46TAG_OBJECT
public static final int TAG_OBJECT = 47TAG_PARAM
public static final int TAG_PARAM = 48TAG_META
public static final int TAG_META = 49TAG_LINK
public static final int TAG_LINK = 50TAG_BASE
public static final int TAG_BASE = 51TAG_HR
public static final int TAG_HR = 52TAG_OPTGROUP
public static final int TAG_OPTGROUP = 53TAG_STYLE
public static final int TAG_STYLE = 54TAG_B
public static final int TAG_B = 55TAG_I
public static final int TAG_I = 56TAG_BIG
public static final int TAG_BIG = 57TAG_SMALL
public static final int TAG_SMALL = 58TAG_FIELDSET
public static final int TAG_FIELDSET = 59TAG_U
public static final int TAG_U = 60TAG_FONT
public static final int TAG_FONT = 61TAG_DEL
public static final int TAG_DEL = 62TAG_INS
public static final int TAG_INS = 63TAG_TT
public static final int TAG_TT = 64TAG_BASEFONT
public static final int TAG_BASEFONT = 65TAG_MENU
public static final int TAG_MENU = 66TAG_S
public static final int TAG_S = 67TAG_STRIKE
public static final int TAG_STRIKE = 68TAG_CENTER
public static final int TAG_CENTER = 69TAG_DIR
public static final int TAG_DIR = 70TAG_MAP
public static final int TAG_MAP = 71TAG_AREA
public static final int TAG_AREA = 72TAG_LEGEND
public static final int TAG_LEGEND = 73TAG_SUB
public static final int TAG_SUB = 74TAG_SUP
public static final int TAG_SUP = 75TAG_NOSCRIPT
public static final int TAG_NOSCRIPT = 76TAG_NOFRAMES
public static final int TAG_NOFRAMES = 77TAG_THEAD
public static final int TAG_THEAD = 78TAG_TBODY
public static final int TAG_TBODY = 79TAG_TFOOT
public static final int TAG_TFOOT = 80TAG_BUTTON
public static final int TAG_BUTTON = 81TAG_TEXT
public static final int TAG_TEXT = 82ATTR_CLASS
public static final int ATTR_CLASS = 0///////////////////////////////
ATTR_ID
public static final int ATTR_ID = 1ATTR_STYLE
public static final int ATTR_STYLE = 2///////////////////////////////
ATTR_TITLE
public static final int ATTR_TITLE = 3ATTR_XMLNS
public static final int ATTR_XMLNS = 4ATTR_XMLLANG
public static final int ATTR_XMLLANG = 5ATTR_ALIGN
public static final int ATTR_ALIGN = 6ATTR_BGCOLOR
public static final int ATTR_BGCOLOR = 7ATTR_LINK
public static final int ATTR_LINK = 8ATTR_TEXT
public static final int ATTR_TEXT = 9ATTR_VERSION
public static final int ATTR_VERSION = 10ATTR_CITE
public static final int ATTR_CITE = 11ATTR_ACCESSKEY
public static final int ATTR_ACCESSKEY = 12ATTR_CHARSET
public static final int ATTR_CHARSET = 13ATTR_HREF
public static final int ATTR_HREF = 14ATTR_HREFLANG
public static final int ATTR_HREFLANG = 15ATTR_REL
public static final int ATTR_REL = 16ATTR_REV
public static final int ATTR_REV = 17ATTR_TABINDEX
public static final int ATTR_TABINDEX = 18ATTR_TYPE
public static final int ATTR_TYPE = 19ATTR_ACTION
public static final int ATTR_ACTION = 20ATTR_ENCTYPE
public static final int ATTR_ENCTYPE = 21ATTR_METHOD
public static final int ATTR_METHOD = 22ATTR_WIDTH
public static final int ATTR_WIDTH = 23ATTR_HEIGHT
public static final int ATTR_HEIGHT = 24ATTR_ALT
public static final int ATTR_ALT = 25ATTR_HSPACE
public static final int ATTR_HSPACE = 26ATTR_VSPACE
public static final int ATTR_VSPACE = 27ATTR_LONGDESC
public static final int ATTR_LONGDESC = 28ATTR_LOCALSRC
public static final int ATTR_LOCALSRC = 29ATTR_SRC
public static final int ATTR_SRC = 30ATTR_SIZE
public static final int ATTR_SIZE = 31ATTR_CHECKED
public static final int ATTR_CHECKED = 32ATTR_EMPTYOK
public static final int ATTR_EMPTYOK = 33ATTR_FORMAT
public static final int ATTR_FORMAT = 34ATTR_ISTYLE
public static final int ATTR_ISTYLE = 35ATTR_MAXLENGTH
public static final int ATTR_MAXLENGTH = 36ATTR_NAME
public static final int ATTR_NAME = 37ATTR_VALUE
public static final int ATTR_VALUE = 38ATTR_FOR
public static final int ATTR_FOR = 39ATTR_XMLSPACE
public static final int ATTR_XMLSPACE = 40ATTR_MULTIPLE
public static final int ATTR_MULTIPLE = 41ATTR_SELECTED
public static final int ATTR_SELECTED = 42ATTR_ABBR
public static final int ATTR_ABBR = 43ATTR_AXIS
public static final int ATTR_AXIS = 44ATTR_COLSPAN
public static final int ATTR_COLSPAN = 45ATTR_HEADERS
public static final int ATTR_HEADERS = 46ATTR_ROWSPAN
public static final int ATTR_ROWSPAN = 47ATTR_SCOPE
public static final int ATTR_SCOPE = 48ATTR_VALIGN
public static final int ATTR_VALIGN = 49ATTR_START
public static final int ATTR_START = 50ATTR_MEDIA
public static final int ATTR_MEDIA = 51ATTR_LABEL
public static final int ATTR_LABEL = 52ATTR_SUMMARY
public static final int ATTR_SUMMARY = 53ATTR_CONTENT
public static final int ATTR_CONTENT = 54ATTR_HTTPEQUIV
public static final int ATTR_HTTPEQUIV = 55ATTR_SCHEME
public static final int ATTR_SCHEME = 56ATTR_COLS
public static final int ATTR_COLS = 57ATTR_ROWS
public static final int ATTR_ROWS = 58ATTR_DIR
public static final int ATTR_DIR = 59ATTR_BORDER
public static final int ATTR_BORDER = 60ATTR_COLOR
public static final int ATTR_COLOR = 61ATTR_FACE
public static final int ATTR_FACE = 62ATTR_SHAPE
public static final int ATTR_SHAPE = 63ATTR_COORDS
public static final int ATTR_COORDS = 64ATTR_USEMAP
public static final int ATTR_USEMAP = 65ATTR_LANG
public static final int ATTR_LANG = 66ATTR_CELLSPACING
public static final int ATTR_CELLSPACING = 67ATTR_CELLPADDING
public static final int ATTR_CELLPADDING = 68ATTR_FRAME
public static final int ATTR_FRAME = 69ATTR_RULES
public static final int ATTR_RULES = 70ATTR_DISABLED
public static final int ATTR_DISABLED = 71ATTR_READONLY
public static final int ATTR_READONLY = 72ATTR_ISMAP
public static final int ATTR_ISMAP = 73COLOR_AQUA
public static final int COLOR_AQUA = 65535///////////////////////////////
COLOR_BLACK
public static final int COLOR_BLACK = 0COLOR_BLUE
public static final int COLOR_BLUE = 255COLOR_FUCHSIA
public static final int COLOR_FUCHSIA = 16711935COLOR_GRAY
public static final int COLOR_GRAY = 8421504COLOR_GREEN
public static final int COLOR_GREEN = 32768///////////////////////////////
COLOR_LIME
public static final int COLOR_LIME = 65280COLOR_MAROON
public static final int COLOR_MAROON = 8388608COLOR_NAVY
public static final int COLOR_NAVY = 128COLOR_OLIVE
public static final int COLOR_OLIVE = 8421376COLOR_PURPLE
public static final int COLOR_PURPLE = 8388736COLOR_RED
public static final int COLOR_RED = 16711680COLOR_SILVER
public static final int COLOR_SILVER = 12632256COLOR_TEAL
public static final int COLOR_TEAL = 32896COLOR_WHITE
public static final int COLOR_WHITE = 16777215COLOR_YELLOW
public static final int COLOR_YELLOW = 16776960COLOR_ORANGE
public static final int COLOR_ORANGE = 16753920Constructor details
HTMLElement
protected HTMLElement()Constructs and HTMLElement without specifying a name.
This can be used by subclasses that do not require name assigments.
HTMLElement
public HTMLElement(String tagName)Constructor for HTMLElement. This mostly sets up the element’s ID.
Parameters
tagNameString- The HTMLElement’s name
HTMLElement
public HTMLElement(String tagName, boolean isTextElement)Constructor for HTMLElement. This mostly sets up the element’s ID.
Parameters
tagNameString- The HTMLElement’s name, or the text for text elements
isTextElementboolean- true for a text element, false otherwise
Method details
setAttribute
public int setAttribute(String attribute, String value)Adds the specified attribute and value to this Element if it is supported for the Element and has a valid value.
Parameters
attributeString- The attribute’s name
valueString- The attribute’s value
Returns
a positive error code or -1 if attribute is supported and valid
setAttributeById
public void setAttributeById(int attrId, String value)Allows setting an attribute with an attribute id
Parameters
attrIdint- The attribute Id (One of the ATTR_ constants)
valueString- The value to set to the attribute
removeAttributeById
public void removeAttributeById(int attrId)Removes the specified attribute
Parameters
attrIdint- The attribute Id (One of the ATTR_ constants)
getSupportedAttributesList
public String getSupportedAttributesList()Returns a list of supported attributes for this tag. Note that the list does not include the core attributes that are supported on almost all tags
Returns
a list of supported attributes for this tag
getTagName
public String getTagName()Returns this HTMLElement’s tag name
Returns
the HTMLElement’s tag name
getTagId
public int getTagId()Returns this HTMLElement’s ID
Returns
the HTMLELement’s ID
setTagId
protected void setTagId(int tagId)Sets this HTMLElement’s ID
Parameters
tagIdint- The tag ID to set, one of the TAG_* constants (Not to be confused with the id attribute)
getFirstChildByTagId
public HTMLElement getFirstChildByTagId(int tagId)Returns an HTMLElement’s child by a tag ID (One of the TAG_* constants)
Parameters
tagIdint- The child’s tag ID, one of the TAG_* constants (Not to be confused with the id attribute)
Returns
the first child with the specified ID, or null if not found
getAttributeById
public String getAttributeById(int id)Returns an HTMLElement’s attribute by the attribute’s ID (One of the ATTR_* constants)
Parameters
idint- The attribute’s ID
Returns
the attribute with the specified ID, or null if not found
toString
public String toString(){Returns a printable string representing this element}
Returns
a printable string representing this element
getAttributeName
public String getAttributeName(Integer attrKey)Returns the attribute name of the requested attribute
Parameters
attrKeyInteger- The attribute key, which is typically an Integer object made of its int attrId
Returns
the attribute name of the requested attribute
getAttribute
public String getAttribute(String name)Returns the attribute value by its name (or null if it wasn’t defined for this element)
Parameters
nameString- The attribute id
Returns
the attribute value by its name (or null if it wasn’t defined for this element)
toString
public String toString(String spacing)A recursive method for creating a printout of a full tag with its entire hierarchy.
This is used by the public method toString().
Parameters
spacingString- Increased by one in each recursion phase to provide with indentation
Returns
the printout of this tag
removeChildAt
public void removeChildAt(int index){Removes the child at the given index}
Parameters
indexint- The child’s index
getDescendantsByTagId
public Vector getDescendantsByTagId(int tagId, int depth)Returns all descendants with the specified tag id
Parameters
tagIdint- The tag ID to look for, one of the TAG_* constants (Not to be confused with the id attribute)
depthint- The search depth (1 - children, 2 - grandchildren …. DEPTH_INFINITE - for all descendants)
Returns
A vector containing descendants with the specified tag id
getDescendantsByTagId
public Vector getDescendantsByTagId(int tagId)Returns all descendants with the specified tag id
Parameters
tagIdint- The tag ID to look for, one of the TAG_* constants (Not to be confused with the id attribute)
Returns
A vector containing descendants with the specified tag id