ELinks 0.18.0
node.h File Reference

DOM node module. More...

#include "dom/string.h"
Include dependency graph for node.h:
This graph shows which files directly or indirectly include this file:

Data Structures

struct  dom_document_node
struct  dom_id
struct  dom_doctype_subset_info
struct  dom_document_type_node
struct  dom_element_node
struct  dom_attribute_node
struct  dom_text_node
struct  dom_proc_instruction_node
union  dom_node_data
struct  dom_node
 DOM node. More...
struct  dom_node_list
 DOM node list. More...

Macros

#define foreach_dom_node(list, node, i)
#define foreachback_dom_node(list, node, i)
#define is_dom_node_list_member(list, member)
#define init_dom_node(type, string, allocated)
#define add_dom_node(parent, type, string)
#define add_dom_element(parent, string)
#define get_dom_node_list(parent, node)

Enumerations

enum  dom_node_type {
  DOM_NODE_UNKNOWN = 0 , DOM_NODE_ELEMENT = 1 , DOM_NODE_ATTRIBUTE = 2 , DOM_NODE_TEXT = 3 ,
  DOM_NODE_CDATA_SECTION = 4 , DOM_NODE_ENTITY_REFERENCE = 5 , DOM_NODE_ENTITY = 6 , DOM_NODE_PROCESSING_INSTRUCTION = 7 ,
  DOM_NODE_COMMENT = 8 , DOM_NODE_DOCUMENT = 9 , DOM_NODE_DOCUMENT_TYPE = 10 , DOM_NODE_DOCUMENT_FRAGMENT = 11 ,
  DOM_NODE_NOTATION = 12 , DOM_NODES
}
 DOM node types. More...
enum  dom_proc_instruction_type { DOM_PROC_INSTRUCTION , DOM_PROC_INSTRUCTION_XML , DOM_PROC_INSTRUCTION_XML_STYLESHEET , DOM_PROC_INSTRUCTION_TYPES }

Functions

struct dom_node_listadd_to_dom_node_list (struct dom_node_list **list_ptr, struct dom_node *node, int position)
void done_dom_node_list (struct dom_node_list *list)
int get_dom_node_list_index (struct dom_node *parent, struct dom_node *node)
int get_dom_node_map_index (struct dom_node_list *list, struct dom_node *node)
struct dom_nodeget_dom_node_prev (struct dom_node *node)
struct dom_nodeget_dom_node_next (struct dom_node *node)
struct dom_nodeget_dom_node_child (struct dom_node *node, uint16_t child_type, int16_t child_subtype)
struct dom_nodeget_dom_node_map_entry (struct dom_node_list *node_map, uint16_t type, uint16_t subtype, struct dom_string *name)
void done_dom_node (struct dom_node *node)
struct dom_nodeinit_dom_node_at (struct dom_node *parent, uint16_t type, struct dom_string *string, int allocated)
static struct dom_nodeadd_dom_attribute (struct dom_node *parent, struct dom_string *name, struct dom_string *value)
static struct dom_nodeadd_dom_proc_instruction (struct dom_node *parent, struct dom_string *string, struct dom_string *instruction)
int dom_node_casecmp (struct dom_node *node1, struct dom_node *node2)
struct dom_stringget_dom_node_name (struct dom_node *node)
struct dom_stringget_dom_node_value (struct dom_node *node)
struct dom_stringget_dom_node_type_name (uint16_t type)
static struct dom_node_list ** get_dom_node_list_by_type (struct dom_node *parent, uint16_t type)
 Based on the type of the parent and the node type return a proper list or NULL.

Detailed Description

DOM node module.

This module defines the various node and node list data structures and functionality to modify and access them, such as adding a node as a child to a given node and getting the text string of a node as defined by the DOM specification.

Node hierarchy

DOM documents are represented as a collection of nodes arranged in a hierarchic structure. At the root is either a DOM_NODE_DOCUMENT or DOM_NODE_DOCUMENT_FRAGMENT node, each of which may have multiple child nodes. There is a well-defined order that dictates which child nodes may be descendants of a given type of node. For example, text and attribute nodes can have no children, while elements node may have both attribute and element nodes as children but with each type in different node lists. The hierarchy is somewhat encoded in the type specific node data, however, certain node types also define "custom" node lists for conveniently storing additional "embedded" data, such as processing instruction nodes having an attribute node list for conveniently accessing variable-value pairs given for XML-specific processing instructions:

<?xml version="1.0"?> 
Node lists

There are two types of list: unordered (the default) and alphabetically ordered (also called "maps"). Both types of list stores all contained nodes in the index-oriented dom_node_list data structure.

When inserting a node into a list, first use either get_dom_node_list_index or get_dom_node_map_index (depending on whether the list is unordered or ordered respectively) to calculate the index at which to insert the new node. Then use add_to_dom_node_list to insert the node in the list at the given position. Alternatively (and mostly preferred), simply use add_dom_node to have all of the above done automatically plus some additional checks.

A variety of node list accessors are defined. The node structure does not define any "next" or "previous" members to get siblings due to reduce memory usage (this might have to change –jonas). Instead, use get_dom_node_next and get_dom_node_next to access siblings. To lookup the existence of a node in a sorted node list (map) use get_dom_node_map_entry. If a specific and unique node subtype should be found use get_dom_node_child that given a parent node will find a child node based on a specific child node type and subtype. Finally, list can be iterated in forward and reverse order using foreach_dom_node and foreachback_dom_node.

Macro Definition Documentation

◆ add_dom_element

#define add_dom_element ( parent,
string )
Value:
add_dom_node(parent, DOM_NODE_ELEMENT, string)
#define add_dom_node(parent, type, string)
Definition node.h:338
@ DOM_NODE_ELEMENT
Element node.
Definition node.h:72

◆ add_dom_node

#define add_dom_node ( parent,
type,
string )
Value:
init_dom_node_at(parent, type, string, -1)
struct dom_node * init_dom_node_at(char *file, int line, struct dom_node *parent, uint16_t type, struct dom_string *string, int allocated)
Definition node.c:354
const char * type
Definition download.c:1899

◆ foreach_dom_node

#define foreach_dom_node ( list,
node,
i )
Value:
for ((i) = 0; (i) < (list)->size; (i)++) \
if (((node) = (list)->entries[(i)]))
Nodes are used for marking areas of text on the document canvas as searchable.
Definition document.h:32
i
Definition uni_7b.inc:369

◆ foreachback_dom_node

#define foreachback_dom_node ( list,
node,
i )
Value:
for ((i) = (list)->size - 1; (i) > 0; (i)--) \
if (((node) = (list)->entries[(i)]))

◆ get_dom_node_list

#define get_dom_node_list ( parent,
node )
Value:
static struct dom_node_list ** get_dom_node_list_by_type(struct dom_node *parent, uint16_t type)
Based on the type of the parent and the node type return a proper list or NULL.
Definition node.h:438

◆ init_dom_node

#define init_dom_node ( type,
string,
allocated )
Value:
init_dom_node_at(NULL, type, string, allocated)
#define NULL
Definition explodename.c:35

◆ is_dom_node_list_member

#define is_dom_node_list_member ( list,
member )
Value:
((list) && 0 <= (member) && (member) < (list)->size)

Enumeration Type Documentation

◆ dom_node_type

DOM node types.

Enumerator
DOM_NODE_UNKNOWN 

Node type used internally.

DOM_NODE_ELEMENT 

Element node.

DOM_NODE_ATTRIBUTE 

Attribute node.

DOM_NODE_TEXT 

Text node.

DOM_NODE_CDATA_SECTION 

CData section node.

DOM_NODE_ENTITY_REFERENCE 

Entity reference node.

DOM_NODE_ENTITY 

Entity node.

DOM_NODE_PROCESSING_INSTRUCTION 

Processing instruction node.

DOM_NODE_COMMENT 

Comment node.

DOM_NODE_DOCUMENT 

Document root node.

DOM_NODE_DOCUMENT_TYPE 

Document type (DTD) node.

DOM_NODE_DOCUMENT_FRAGMENT 

Document fragment node.

DOM_NODE_NOTATION 

Notation node.

DOM_NODES 

The number of DOM nodes.

◆ dom_proc_instruction_type

Enumerator
DOM_PROC_INSTRUCTION 
DOM_PROC_INSTRUCTION_XML 
DOM_PROC_INSTRUCTION_XML_STYLESHEET 
DOM_PROC_INSTRUCTION_TYPES 

Function Documentation

◆ add_dom_attribute()

struct dom_node * add_dom_attribute ( struct dom_node * parent,
struct dom_string * name,
struct dom_string * value )
inlinestatic

◆ add_dom_proc_instruction()

struct dom_node * add_dom_proc_instruction ( struct dom_node * parent,
struct dom_string * string,
struct dom_string * instruction )
inlinestatic

◆ add_to_dom_node_list()

struct dom_node_list * add_to_dom_node_list ( struct dom_node_list ** list_ptr,
struct dom_node * node,
int position )

◆ dom_node_casecmp()

int dom_node_casecmp ( struct dom_node * node1,
struct dom_node * node2 )

◆ done_dom_node()

void done_dom_node ( struct dom_node * node)

◆ done_dom_node_list()

void done_dom_node_list ( struct dom_node_list * list)

◆ get_dom_node_child()

struct dom_node * get_dom_node_child ( struct dom_node * node,
uint16_t child_type,
int16_t child_subtype )

◆ get_dom_node_list_by_type()

struct dom_node_list ** get_dom_node_list_by_type ( struct dom_node * parent,
uint16_t type )
inlinestatic

Based on the type of the parent and the node type return a proper list or NULL.

This is useful when adding a node to a parent node.

With a struct dom_node_list **list returned by this function, there are four possibilities:

  • list == NULL. This means parent does not support child nodes of the given type.
  • *list == NULL. This means parent does not yet have any child nodes of the given type and so no list has been allocated for them. Callers should treat the lack of a list in the same way as an empty list.
  • (*list)->size == 0. This is an empty list. It is unspecified whether the DOM code keeps such lists; it could instead change them back to NULL.
  • (*list)->size != 0. This is a nonempty list. However, the nodes in it might not actually be of the given type because some lists are used for multiple types.

◆ get_dom_node_list_index()

int get_dom_node_list_index ( struct dom_node * parent,
struct dom_node * node )

◆ get_dom_node_map_entry()

struct dom_node * get_dom_node_map_entry ( struct dom_node_list * node_map,
uint16_t type,
uint16_t subtype,
struct dom_string * name )

◆ get_dom_node_map_index()

int get_dom_node_map_index ( struct dom_node_list * list,
struct dom_node * node )

◆ get_dom_node_name()

struct dom_string * get_dom_node_name ( struct dom_node * node)

◆ get_dom_node_next()

struct dom_node * get_dom_node_next ( struct dom_node * node)

◆ get_dom_node_prev()

struct dom_node * get_dom_node_prev ( struct dom_node * node)

◆ get_dom_node_type_name()

struct dom_string * get_dom_node_type_name ( uint16_t type)

◆ get_dom_node_value()

struct dom_string * get_dom_node_value ( struct dom_node * node)

◆ init_dom_node_at()

struct dom_node * init_dom_node_at ( struct dom_node * parent,
uint16_t type,
struct dom_string * string,
int allocated )