public class HTMLElement

  1. Object
  2. Element
  3. 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

public static final int TAG_CSS_ILLEGAL_SELECTOR = -3///////////////////////////////
public static final int TAG_CSS_SELECTOR = -2
public static final int TAG_UNSUPPORTED = -1
public static final int TAG_BODY = 0
public static final int TAG_HEAD = 1
public static final int TAG_HTML = 2
public static final int TAG_TITLE = 3
public static final int TAG_ABBR = 4
public static final int TAG_ACRONYM = 5
public static final int TAG_ADDRESS = 6
public static final int TAG_BLOCKQUOTE = 7
public static final int TAG_BR = 8
public static final int TAG_CITE = 9
public static final int TAG_CODE = 10
public static final int TAG_DFN = 11
public static final int TAG_DIV = 12
public static final int TAG_EM = 13
public static final int TAG_H1 = 14
public static final int TAG_H2 = 15
public static final int TAG_H3 = 16
public static final int TAG_H4 = 17
public static final int TAG_H5 = 18
public static final int TAG_H6 = 19
public static final int TAG_KBD = 20
public static final int TAG_P = 21
public static final int TAG_PRE = 22
public static final int TAG_Q = 23
public static final int TAG_SAMP = 24
public static final int TAG_SPAN = 25
public static final int TAG_STRONG = 26
public static final int TAG_VAR = 27
public static final int TAG_A = 28
public static final int TAG_DL = 29
public static final int TAG_DT = 30
public static final int TAG_DD = 31
public static final int TAG_OL = 32
public static final int TAG_UL = 33
public static final int TAG_LI = 34
public static final int TAG_FORM = 35
public static final int TAG_INPUT = 36
public static final int TAG_LABEL = 37
public static final int TAG_SELECT = 38
public static final int TAG_OPTION = 39
public static final int TAG_TEXTAREA = 40
public static final int TAG_CAPTION = 41
public static final int TAG_TABLE = 42
public static final int TAG_TD = 43
public static final int TAG_TH = 44
public static final int TAG_TR = 45
public static final int TAG_IMG = 46
public static final int TAG_OBJECT = 47
public static final int TAG_PARAM = 48
public static final int TAG_META = 49
public static final int TAG_LINK = 50
public static final int TAG_BASE = 51
public static final int TAG_HR = 52
public static final int TAG_OPTGROUP = 53
public static final int TAG_STYLE = 54
public static final int TAG_B = 55
public static final int TAG_I = 56
public static final int TAG_BIG = 57
public static final int TAG_SMALL = 58
public static final int TAG_FIELDSET = 59
public static final int TAG_U = 60
public static final int TAG_FONT = 61
public static final int TAG_DEL = 62
public static final int TAG_INS = 63
public static final int TAG_TT = 64
public static final int TAG_BASEFONT = 65
public static final int TAG_MENU = 66
public static final int TAG_S = 67
public static final int TAG_STRIKE = 68
public static final int TAG_CENTER = 69
public static final int TAG_DIR = 70
public static final int TAG_MAP = 71
public static final int TAG_AREA = 72
public static final int TAG_LEGEND = 73
public static final int TAG_SUB = 74
public static final int TAG_SUP = 75
public static final int TAG_NOSCRIPT = 76
public static final int TAG_NOFRAMES = 77
public static final int TAG_THEAD = 78
public static final int TAG_TBODY = 79
public static final int TAG_TFOOT = 80
public static final int TAG_BUTTON = 81
public static final int TAG_TEXT = 82
public static final int ATTR_CLASS = 0///////////////////////////////
public static final int ATTR_ID = 1
public static final int ATTR_STYLE = 2///////////////////////////////
public static final int ATTR_TITLE = 3
public static final int ATTR_XMLNS = 4
public static final int ATTR_XMLLANG = 5
public static final int ATTR_ALIGN = 6
public static final int ATTR_BGCOLOR = 7
public static final int ATTR_LINK = 8
public static final int ATTR_TEXT = 9
public static final int ATTR_VERSION = 10
public static final int ATTR_CITE = 11
public static final int ATTR_ACCESSKEY = 12
public static final int ATTR_CHARSET = 13
public static final int ATTR_HREF = 14
public static final int ATTR_HREFLANG = 15
public static final int ATTR_REL = 16
public static final int ATTR_REV = 17
public static final int ATTR_TABINDEX = 18
public static final int ATTR_TYPE = 19
public static final int ATTR_ACTION = 20
public static final int ATTR_ENCTYPE = 21
public static final int ATTR_METHOD = 22
public static final int ATTR_WIDTH = 23
public static final int ATTR_HEIGHT = 24
public static final int ATTR_ALT = 25
public static final int ATTR_HSPACE = 26
public static final int ATTR_VSPACE = 27
public static final int ATTR_LONGDESC = 28
public static final int ATTR_LOCALSRC = 29
public static final int ATTR_SRC = 30
public static final int ATTR_SIZE = 31
public static final int ATTR_CHECKED = 32
public static final int ATTR_EMPTYOK = 33
public static final int ATTR_FORMAT = 34
public static final int ATTR_ISTYLE = 35
public static final int ATTR_MAXLENGTH = 36
public static final int ATTR_NAME = 37
public static final int ATTR_VALUE = 38
public static final int ATTR_FOR = 39
public static final int ATTR_XMLSPACE = 40
public static final int ATTR_MULTIPLE = 41
public static final int ATTR_SELECTED = 42
public static final int ATTR_ABBR = 43
public static final int ATTR_AXIS = 44
public static final int ATTR_COLSPAN = 45
public static final int ATTR_HEADERS = 46
public static final int ATTR_ROWSPAN = 47
public static final int ATTR_SCOPE = 48
public static final int ATTR_VALIGN = 49
public static final int ATTR_START = 50
public static final int ATTR_MEDIA = 51
public static final int ATTR_LABEL = 52
public static final int ATTR_SUMMARY = 53
public static final int ATTR_CONTENT = 54
public static final int ATTR_HTTPEQUIV = 55
public static final int ATTR_SCHEME = 56
public static final int ATTR_COLS = 57
public static final int ATTR_ROWS = 58
public static final int ATTR_DIR = 59
public static final int ATTR_BORDER = 60
public static final int ATTR_COLOR = 61
public static final int ATTR_FACE = 62
public static final int ATTR_SHAPE = 63
public static final int ATTR_COORDS = 64
public static final int ATTR_USEMAP = 65
public static final int ATTR_LANG = 66
public static final int ATTR_CELLSPACING = 67
public static final int ATTR_CELLPADDING = 68
public static final int ATTR_FRAME = 69
public static final int ATTR_RULES = 70
public static final int ATTR_DISABLED = 71
public static final int ATTR_READONLY = 72
public static final int ATTR_ISMAP = 73
public static final int COLOR_AQUA = 65535///////////////////////////////
public static final int COLOR_BLACK = 0
public static final int COLOR_BLUE = 255
public static final int COLOR_FUCHSIA = 16711935
public static final int COLOR_GRAY = 8421504
public static final int COLOR_GREEN = 32768///////////////////////////////
public static final int COLOR_LIME = 65280
public static final int COLOR_MAROON = 8388608
public static final int COLOR_NAVY = 128
public static final int COLOR_OLIVE = 8421376
public static final int COLOR_PURPLE = 8388736
public static final int COLOR_RED = 16711680
public static final int COLOR_SILVER = 12632256
public static final int COLOR_TEAL = 32896
public static final int COLOR_WHITE = 16777215
public static final int COLOR_YELLOW = 16776960
public static final int COLOR_ORANGE = 16753920

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

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 = -2

TAG_UNSUPPORTED

public static final int TAG_UNSUPPORTED = -1

TAG_BODY

public static final int TAG_BODY = 0

TAG_HEAD

public static final int TAG_HEAD = 1

TAG_HTML

public static final int TAG_HTML = 2

TAG_TITLE

public static final int TAG_TITLE = 3

TAG_ABBR

public static final int TAG_ABBR = 4

TAG_ACRONYM

public static final int TAG_ACRONYM = 5

TAG_ADDRESS

public static final int TAG_ADDRESS = 6

TAG_BLOCKQUOTE

public static final int TAG_BLOCKQUOTE = 7

TAG_BR

public static final int TAG_BR = 8

TAG_CITE

public static final int TAG_CITE = 9

TAG_CODE

public static final int TAG_CODE = 10

TAG_DFN

public static final int TAG_DFN = 11

TAG_DIV

public static final int TAG_DIV = 12

TAG_EM

public static final int TAG_EM = 13

TAG_H1

public static final int TAG_H1 = 14

TAG_H2

public static final int TAG_H2 = 15

TAG_H3

public static final int TAG_H3 = 16

TAG_H4

public static final int TAG_H4 = 17

TAG_H5

public static final int TAG_H5 = 18

TAG_H6

public static final int TAG_H6 = 19

TAG_KBD

public static final int TAG_KBD = 20

TAG_P

public static final int TAG_P = 21

TAG_PRE

public static final int TAG_PRE = 22

TAG_Q

public static final int TAG_Q = 23

TAG_SAMP

public static final int TAG_SAMP = 24

TAG_SPAN

public static final int TAG_SPAN = 25

TAG_STRONG

public static final int TAG_STRONG = 26

TAG_VAR

public static final int TAG_VAR = 27

TAG_A

public static final int TAG_A = 28

TAG_DL

public static final int TAG_DL = 29

TAG_DT

public static final int TAG_DT = 30

TAG_DD

public static final int TAG_DD = 31

TAG_OL

public static final int TAG_OL = 32

TAG_UL

public static final int TAG_UL = 33

TAG_LI

public static final int TAG_LI = 34

TAG_FORM

public static final int TAG_FORM = 35

TAG_INPUT

public static final int TAG_INPUT = 36

TAG_LABEL

public static final int TAG_LABEL = 37

TAG_SELECT

public static final int TAG_SELECT = 38

TAG_OPTION

public static final int TAG_OPTION = 39

TAG_TEXTAREA

public static final int TAG_TEXTAREA = 40

TAG_CAPTION

public static final int TAG_CAPTION = 41

TAG_TABLE

public static final int TAG_TABLE = 42

TAG_TD

public static final int TAG_TD = 43

TAG_TH

public static final int TAG_TH = 44

TAG_TR

public static final int TAG_TR = 45

TAG_IMG

public static final int TAG_IMG = 46

TAG_OBJECT

public static final int TAG_OBJECT = 47

TAG_PARAM

public static final int TAG_PARAM = 48

TAG_META

public static final int TAG_META = 49

TAG_BASE

public static final int TAG_BASE = 51

TAG_HR

public static final int TAG_HR = 52

TAG_OPTGROUP

public static final int TAG_OPTGROUP = 53

TAG_STYLE

public static final int TAG_STYLE = 54

TAG_B

public static final int TAG_B = 55

TAG_I

public static final int TAG_I = 56

TAG_BIG

public static final int TAG_BIG = 57

TAG_SMALL

public static final int TAG_SMALL = 58

TAG_FIELDSET

public static final int TAG_FIELDSET = 59

TAG_U

public static final int TAG_U = 60

TAG_FONT

public static final int TAG_FONT = 61

TAG_DEL

public static final int TAG_DEL = 62

TAG_INS

public static final int TAG_INS = 63

TAG_TT

public static final int TAG_TT = 64

TAG_BASEFONT

public static final int TAG_BASEFONT = 65

TAG_MENU

public static final int TAG_MENU = 66

TAG_S

public static final int TAG_S = 67

TAG_STRIKE

public static final int TAG_STRIKE = 68

TAG_CENTER

public static final int TAG_CENTER = 69

TAG_DIR

public static final int TAG_DIR = 70

TAG_MAP

public static final int TAG_MAP = 71

TAG_AREA

public static final int TAG_AREA = 72

TAG_LEGEND

public static final int TAG_LEGEND = 73

TAG_SUB

public static final int TAG_SUB = 74

TAG_SUP

public static final int TAG_SUP = 75

TAG_NOSCRIPT

public static final int TAG_NOSCRIPT = 76

TAG_NOFRAMES

public static final int TAG_NOFRAMES = 77

TAG_THEAD

public static final int TAG_THEAD = 78

TAG_TBODY

public static final int TAG_TBODY = 79

TAG_TFOOT

public static final int TAG_TFOOT = 80

TAG_BUTTON

public static final int TAG_BUTTON = 81

TAG_TEXT

public static final int TAG_TEXT = 82

ATTR_CLASS

public static final int ATTR_CLASS = 0
///////////////////////////////

ATTR_ID

public static final int ATTR_ID = 1

ATTR_STYLE

public static final int ATTR_STYLE = 2
///////////////////////////////

ATTR_TITLE

public static final int ATTR_TITLE = 3

ATTR_XMLNS

public static final int ATTR_XMLNS = 4

ATTR_XMLLANG

public static final int ATTR_XMLLANG = 5

ATTR_ALIGN

public static final int ATTR_ALIGN = 6

ATTR_BGCOLOR

public static final int ATTR_BGCOLOR = 7

ATTR_TEXT

public static final int ATTR_TEXT = 9

ATTR_VERSION

public static final int ATTR_VERSION = 10

ATTR_CITE

public static final int ATTR_CITE = 11

ATTR_ACCESSKEY

public static final int ATTR_ACCESSKEY = 12

ATTR_CHARSET

public static final int ATTR_CHARSET = 13

ATTR_HREF

public static final int ATTR_HREF = 14

ATTR_HREFLANG

public static final int ATTR_HREFLANG = 15

ATTR_REL

public static final int ATTR_REL = 16

ATTR_REV

public static final int ATTR_REV = 17

ATTR_TABINDEX

public static final int ATTR_TABINDEX = 18

ATTR_TYPE

public static final int ATTR_TYPE = 19

ATTR_ACTION

public static final int ATTR_ACTION = 20

ATTR_ENCTYPE

public static final int ATTR_ENCTYPE = 21

ATTR_METHOD

public static final int ATTR_METHOD = 22

ATTR_WIDTH

public static final int ATTR_WIDTH = 23

ATTR_HEIGHT

public static final int ATTR_HEIGHT = 24

ATTR_ALT

public static final int ATTR_ALT = 25

ATTR_HSPACE

public static final int ATTR_HSPACE = 26

ATTR_VSPACE

public static final int ATTR_VSPACE = 27

ATTR_LONGDESC

public static final int ATTR_LONGDESC = 28

ATTR_LOCALSRC

public static final int ATTR_LOCALSRC = 29

ATTR_SRC

public static final int ATTR_SRC = 30

ATTR_SIZE

public static final int ATTR_SIZE = 31

ATTR_CHECKED

public static final int ATTR_CHECKED = 32

ATTR_EMPTYOK

public static final int ATTR_EMPTYOK = 33

ATTR_FORMAT

public static final int ATTR_FORMAT = 34

ATTR_ISTYLE

public static final int ATTR_ISTYLE = 35

ATTR_MAXLENGTH

public static final int ATTR_MAXLENGTH = 36

ATTR_NAME

public static final int ATTR_NAME = 37

ATTR_VALUE

public static final int ATTR_VALUE = 38

ATTR_FOR

public static final int ATTR_FOR = 39

ATTR_XMLSPACE

public static final int ATTR_XMLSPACE = 40

ATTR_MULTIPLE

public static final int ATTR_MULTIPLE = 41

ATTR_SELECTED

public static final int ATTR_SELECTED = 42

ATTR_ABBR

public static final int ATTR_ABBR = 43

ATTR_AXIS

public static final int ATTR_AXIS = 44

ATTR_COLSPAN

public static final int ATTR_COLSPAN = 45

ATTR_HEADERS

public static final int ATTR_HEADERS = 46

ATTR_ROWSPAN

public static final int ATTR_ROWSPAN = 47

ATTR_SCOPE

public static final int ATTR_SCOPE = 48

ATTR_VALIGN

public static final int ATTR_VALIGN = 49

ATTR_START

public static final int ATTR_START = 50

ATTR_MEDIA

public static final int ATTR_MEDIA = 51

ATTR_LABEL

public static final int ATTR_LABEL = 52

ATTR_SUMMARY

public static final int ATTR_SUMMARY = 53

ATTR_CONTENT

public static final int ATTR_CONTENT = 54

ATTR_HTTPEQUIV

public static final int ATTR_HTTPEQUIV = 55

ATTR_SCHEME

public static final int ATTR_SCHEME = 56

ATTR_COLS

public static final int ATTR_COLS = 57

ATTR_ROWS

public static final int ATTR_ROWS = 58

ATTR_DIR

public static final int ATTR_DIR = 59

ATTR_BORDER

public static final int ATTR_BORDER = 60

ATTR_COLOR

public static final int ATTR_COLOR = 61

ATTR_FACE

public static final int ATTR_FACE = 62

ATTR_SHAPE

public static final int ATTR_SHAPE = 63

ATTR_COORDS

public static final int ATTR_COORDS = 64

ATTR_USEMAP

public static final int ATTR_USEMAP = 65

ATTR_LANG

public static final int ATTR_LANG = 66

ATTR_CELLSPACING

public static final int ATTR_CELLSPACING = 67

ATTR_CELLPADDING

public static final int ATTR_CELLPADDING = 68

ATTR_FRAME

public static final int ATTR_FRAME = 69

ATTR_RULES

public static final int ATTR_RULES = 70

ATTR_DISABLED

public static final int ATTR_DISABLED = 71

ATTR_READONLY

public static final int ATTR_READONLY = 72

ATTR_ISMAP

public static final int ATTR_ISMAP = 73

COLOR_AQUA

public static final int COLOR_AQUA = 65535
///////////////////////////////

COLOR_BLACK

public static final int COLOR_BLACK = 0

COLOR_BLUE

public static final int COLOR_BLUE = 255

COLOR_FUCHSIA

public static final int COLOR_FUCHSIA = 16711935

COLOR_GRAY

public static final int COLOR_GRAY = 8421504

COLOR_GREEN

public static final int COLOR_GREEN = 32768
///////////////////////////////

COLOR_LIME

public static final int COLOR_LIME = 65280

COLOR_MAROON

public static final int COLOR_MAROON = 8388608

COLOR_NAVY

public static final int COLOR_NAVY = 128

COLOR_OLIVE

public static final int COLOR_OLIVE = 8421376

COLOR_PURPLE

public static final int COLOR_PURPLE = 8388736

COLOR_RED

public static final int COLOR_RED = 16711680

COLOR_SILVER

public static final int COLOR_SILVER = 12632256

COLOR_TEAL

public static final int COLOR_TEAL = 32896

COLOR_WHITE

public static final int COLOR_WHITE = 16777215

COLOR_YELLOW

public static final int COLOR_YELLOW = 16776960

COLOR_ORANGE

public static final int COLOR_ORANGE = 16753920

Constructor 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

tagName String
The HTMLElement’s name

HTMLElement

public HTMLElement(String tagName, boolean isTextElement)
Constructor for HTMLElement. This mostly sets up the element’s ID.

Parameters

tagName String
The HTMLElement’s name, or the text for text elements
isTextElement boolean
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

attribute String
The attribute’s name
value String
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

attrId int
The attribute Id (One of the ATTR_ constants)
value String
The value to set to the attribute

removeAttributeById

public void removeAttributeById(int attrId)
Removes the specified attribute

Parameters

attrId int
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

tagId int
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

tagId int
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

id int
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

attrKey Integer
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

name String
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

spacing String
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

index int
The child’s index

getDescendantsByTagId

public Vector getDescendantsByTagId(int tagId, int depth)
Returns all descendants with the specified tag id

Parameters

tagId int
The tag ID to look for, one of the TAG_* constants (Not to be confused with the id attribute)
depth int
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

tagId int
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