#include <stdio.h>
Functions | |
| TAG * | createElement () |
| Create empty DOM node. | |
| TAG * | createTextNode () |
| Create empty text DOM node. | |
| TAG * | appendChild (TAG *, TAG *) |
| Append child. | |
| TAG * | appendSibling (TAG *, TAG *) |
| Append sibling. | |
| void | removeSibling (TAG *, TAG *) |
| Remove sibling. | |
| void | removeChild (TAG *, TAG *) |
| Remove b from a's children list. | |
| void | deleteNode (TAG *) |
| Delete node. | |
| void | deleteTree (TAG *) |
| Delete tree. | |
| TAG * | findBack (TAG *, char *) |
| Reverse find tree node. | |
| TAG * | findBackPlain (TAG *, char *) |
| Reverse find tree node. | |
| TAG * | findPrev (TAG *) |
| Find tree node. | |
| TAG * | copyTree (TAG *a) |
| Copy tree. | |
| TAG * | copyBranch (TAG *a) |
| Copy branch. | |
| TAG * | copyNode (TAG *a) |
| Copy node. | |
| void | dumpTree (TAG *, FILE *) |
| Construct document from tree. | |
| TAG * | findNode (TAG *a, char *name) |
| Find tree node. | |
| TAG * | findNext (TAG *a) |
| Find tree node. | |
| TAG * | findNextPlain (TAG *a) |
| Find tree node. | |
| TAG * | insertAfter (TAG *, TAG *) |
| Insert node after given node. | |
| TAG * | insertBefore (TAG *, TAG *) |
| Insert node before given node. | |
| TAG * | extractFrom (TAG *) |
| Extract tree. | |
| TAG * | replaceNode (TAG *, TAG *) |
| Replace node. | |
| TAG * | recurseNodes (TAG *) |
| Recursively walk through all nodes. | |
| TAG * | getElementById (TAG *, char *) |
| Find element with given ID. | |
| char * | getAttribute (TAG *, char *) |
| Get element's attribute with given name. | |
| void | setAttribute (TAG *, char *, char *) |
| Set element's attribute with given name. | |
| void | removeAttribute (TAG *, char *) |
| Remove element's attribute with given name. | |
HTML DOM tree is an object model of the document, where each tag is represented by corresponding tree node. HTML DOM is widely used to access document elements in JavaScript in client-side scripting.
However, I thought it would be convenient sometimes to have access to the document's DOM tree on the server side. This file contains functions and structures to enable one to access HTML DOM tree from CGI script.
| TAG* appendChild | ( | TAG * | a, | |
| TAG * | b | |||
| ) |
Append child.
Appends child node to the DOM node. The child is appended into the end of list of children.
| a | parent node. | |
| b | node to attach. |
| TAG* appendSibling | ( | TAG * | a, | |
| TAG * | b | |||
| ) |
Append sibling.
Appends sibling node to the DOM node. The child is appended into the end of list of children.
| a | node to attach to. | |
| b | node to attach. |
| TAG* copyBranch | ( | TAG * | a | ) |
Copy branch.
Acts the same way as copyTree, but copies only tree without siblings.
| a | starting node to copy. |
| TAG* copyNode | ( | TAG * | a | ) |
Copy node.
Creates and returns full copy of given node.
| a | node to copy. |
| TAG* copyTree | ( | TAG * | a | ) |
Copy tree.
Acts the same way as copyNode, but copies the whole tree along with siblings.
| a | starting node to copy. |
| TAG* createElement | ( | ) |
Create empty DOM node.
Creates empty DOM node.
| TAG* createTextNode | ( | ) |
Create empty text DOM node.
Creates empty text DOM node.
| void deleteNode | ( | TAG * | a | ) |
Delete node.
Deletes node and frees associated memory.
| a | node to delete. |
| void deleteTree | ( | TAG * | a | ) |
Delete tree.
Deletes the whole tree and frees associated memory.
| a | starting tree node. |
| void dumpTree | ( | TAG * | root, | |
| FILE * | out | |||
| ) |
Construct document from tree.
Constructs document from tree and dumps it to the output stream.
| root | tree root node. | |
| out | output stream. |
| TAG* extractFrom | ( | TAG * | a | ) |
Extract tree.
Extracts tree/child nodes from given node.
| a | node to extract from. |
| TAG* findBack | ( | TAG * | a, | |
| char * | name | |||
| ) |
Reverse find tree node.
Searches for the first node with given tag name in reverse direction.
| a | node to start search from. | |
| name | tag name. |
| TAG* findBackPlain | ( | TAG * | a, | |
| char * | name | |||
| ) |
Reverse find tree node.
Searches current level for the first node with given tag name in reverse direction. Processes only siblings, but not child nodes.
| a | node to start search from. | |
| name | tag name. |
| TAG* findNext | ( | TAG * | a | ) |
Find tree node.
Searches tree for the next node with given tag name.
| a | previous found node with given tag name. |
| TAG* findNextPlain | ( | TAG * | a | ) |
Find tree node.
Searches current level for the next node with given tag name. Processes only siblings, but not child nodes.
| a | previous found node with given tag name. |
| TAG* findNode | ( | TAG * | a, | |
| char * | name | |||
| ) |
Find tree node.
Searches tree for the first node with given tag name.
| a | node to start search from. | |
| name | tag name. |
| TAG* findPrev | ( | TAG * | a | ) |
Find tree node.
Searches tree for the previous node with given tag name.
| a | previous found node with given tag name. |
| char* getAttribute | ( | TAG * | a, | |
| char * | name | |||
| ) |
Get element's attribute with given name.
Returns element's attribute with given name.
| a | node. | |
| name | attribute name. |
| TAG* getElementById | ( | TAG * | node, | |
| char * | id | |||
| ) |
Find element with given ID.
Searches document for the element with given ID attribute.
| node | tree root node. | |
| id | id to search for. |
| TAG* insertAfter | ( | TAG * | a, | |
| TAG * | b | |||
| ) |
Insert node after given node.
Inserts node after given node.
| a | node after which to insert. | |
| b | node to insert. |
| TAG* insertBefore | ( | TAG * | a, | |
| TAG * | b | |||
| ) |
Insert node before given node.
Inserts node before given node.
| a | node before which to insert. | |
| b | node to insert. |
| TAG* recurseNodes | ( | TAG * | a | ) |
Recursively walk through all nodes.
Subsequently returns nodes as they appear in tree. When there are no more nodes, NULL is returned.
| a | node to start. |
| void removeAttribute | ( | TAG * | a, | |
| char * | name | |||
| ) |
Remove element's attribute with given name.
Removes element's attribute with given name.
| a | node. | |
| name | attribute name. |
| void removeChild | ( | TAG * | a, | |
| TAG * | b | |||
| ) |
Remove b from a's children list.
Remove element b from a's children list.
| a | node to delete from. | |
| b | node to delete. |
| void removeSibling | ( | TAG * | a, | |
| TAG * | b | |||
| ) |
Remove sibling.
Removes sibling node from the DOM node.
| a | node for which the sibling is deleted. | |
| b | node to delete. |
| TAG* replaceNode | ( | TAG * | a, | |
| TAG * | b | |||
| ) |
Replace node.
Replaces node with another node.
| a | node to replace. | |
| b | node to replace with. |
| void setAttribute | ( | TAG * | a, | |
| char * | name, | |||
| char * | value | |||
| ) |
Set element's attribute with given name.
Sets element's attribute with given name. If attribute does not exist, it is created first.
| a | node. | |
| name | attribute name. | |
| value | attribute value. |
1.5.5