| 1 |
The definitions below are an essential part of the parser. |
| 2 |
|
| 3 |
## Node Types |
| 4 |
|
| 5 |
The type of node is determined during parsing and represented by one of the elements in the list below. |
| 6 |
|
| 7 |
| Type | Description | |
| 8 |
|---------------------|---------------------------------------------------------------------| |
| 9 |
| `HDOM_TYPE_ELEMENT` | Start tag (i.e. `<html>`) | |
| 10 |
| `HDOM_TYPE_COMMENT` | HTML comment (i.e. `<!-- Hello, World! -->`) | |
| 11 |
| `HDOM_TYPE_TEXT` | Plain text (i.e. `Hello, World!`) | |
| 12 |
| `HDOM_TYPE_ROOT` | Root element. There can always only be one root element in the DOM. | |
| 13 |
| `HDOM_TYPE_UNKNOWN` | Unknown type (i.e. CDATA, DOCTYPE, etc...) | |
| 14 |
|
| 15 |
### Example |
| 16 |
|
| 17 |
```html |
| 18 |
<!DOCTYPE html><html><!-- Hello, World! --></html>Hello, World! |
| 19 |
``` |
| 20 |
|
| 21 |
_Note_: `HDOM_TYPE_ROOT` always exists regardless of the actual document structure. |
| 22 |
|
| 23 |
| HTML | Node Type | |
| 24 |
|--------------------------|---------------------| |
| 25 |
| | `HDOM_TYPE_ROOT` | |
| 26 |
| `<!DOCTYPE html>` | `HDOM_TYPE_UNKNOWN` | |
| 27 |
| `<html>` | `HDOM_TYPE_ELEMENT` | |
| 28 |
| `<!-- Hello, World! -->` | `HDOM_TYPE_COMMENT` | |
| 29 |
| `Hello, World!` | `HDOM_TYPE_TEXT` | |
| 30 |
|
| 31 |
## Quote Types |
| 32 |
|
| 33 |
Identifies the quoting type on attribute values. |
| 34 |
|
| 35 |
| Type | Description | |
| 36 |
|---------------------|----------------------| |
| 37 |
| `HDOM_QUOTE_DOUBLE` | Double quotes (`""`) | |
| 38 |
| `HDOM_QUOTE_SINGLE` | Single quotes (`''`) | |
| 39 |
| `HDOM_QUOTE_NO` | Not quoted (flag) | |
| 40 |
|
| 41 |
_Note_: Attributes with no values (flags) are stored as `HDOM_QUOTE_NO`. |
| 42 |
|
| 43 |
### Example |
| 44 |
|
| 45 |
```html |
| 46 |
<p class="paragraph" id='info1' hidden>Hello, World!</p> |
| 47 |
``` |
| 48 |
|
| 49 |
| Attribute | Description | |
| 50 |
|---------------------|---------------------| |
| 51 |
| `class="paragraph"` | `HDOM_QUOTE_DOUBLE` | |
| 52 |
| `id='info1'` | `HDOM_QUOTE_SINGLE` | |
| 53 |
| `hidden` | `HDOM_QUOTE_NO` | |
| 54 |
|
| 55 |
## Node Info Types |
| 56 |
|
| 57 |
Each node stores additional information (metadata) that is identified by the elements below. |
| 58 |
|
| 59 |
| Type | Description | |
| 60 |
|----------------------|--------------------------------------------------------------------------------------------------------------------| |
| 61 |
| `HDOM_INFO_BEGIN` | Cursor position for the start tag of a node. | |
| 62 |
| `HDOM_INFO_END` | Cursor position for the end tag of a node. A value of zero indicates a node with no end tag (missing closing tag). | |
| 63 |
| `HDOM_INFO_QUOTE` | Quote type for attribute values. The value must be an element of [](#quote-typesQuote Type](#quote-types](#quote-types). | |
| 64 |
| `HDOM_INFO_SPACE` | Array of whitespace around attributes (see [](#attribute-whitespaceAttribute Whitespace](#attribute-whitespace](#attribute-whitespace)). | |
| 65 |
| `HDOM_INFO_TEXT` | Non-HTML text in tags (i.e. comments, doctype, etc...). | |
| 66 |
| `HDOM_INFO_INNER` | Inner text of a node. | |
| 67 |
| `HDOM_INFO_OUTER` | Outer text of a node. | |
| 68 |
| `HDOM_INFO_ENDSPACE` | Whitespace at the end of a tag before the closing bracket. | |
| 69 |
|
| 70 |
## Attribute Whitespace |
| 71 |
|
| 72 |
Whitespace around attributes is stored in the form of an array with three elements: |
| 73 |
|
| 74 |
| Element | Description | |
| 75 |
|---------|-----------------------------------------------------------| |
| 76 |
| `0` | Whitespace before the attribute name. | |
| 77 |
| `1` | Whitespace between attribute name and the equal sign. | |
| 78 |
| `2` | Whitespace between the equal sign and the attribute value | |
| 79 |
|
| 80 |
### Example |
| 81 |
|
| 82 |
```html |
| 83 |
<p class="paragraph" id = 'info1'hidden>Hello, World!</p> |
| 84 |
``` |
| 85 |
|
| 86 |
_Note_: Whitespace before attribute names is not displayed in the browser. It is, however, part of the attributes. |
| 87 |
|
| 88 |
| Attribute | Description | |
| 89 |
|----------------------|--------------------------------------| |
| 90 |
| ` class="paragraph"` | `[0] => ' ', [1] => '', [2] => ''` | |
| 91 |
| ` id = 'info1'` | `[0] => ' ', [1] => ' ', [2] => ' '` | |
| 92 |
| `hidden` | `[0] => '', [1] => '', [2] => ''` | |