lexor.core.node module¶
This module defines the basic object of the document object model (DOM).
- class lexor.core.node.Node[source]¶
Bases: object
Primary datatype for the entire Document Object Model.
- __init__()[source]¶
Initializes all data descriptors to None. Each descriptor has an associated READ-ONLY property. Read the comment on each property to see what each descriptor represents.
- node_name[source]¶
Read-Only Property
The name of this node. Its value depends on the node type. This property is associated with the attribute name.
- owner_document[source]¶
Read-Only Property
The Document in which this node resides. This property is associated with the attribute owner.
- parent_node[source]¶
Read-Only Property
The parent of this node. If the node has been just created or removed from a Document then this property is None. This property is associated with the attribute parent.
- node_index[source]¶
Read-Only Property
The number of preceding siblings.
>>> x is x.parent_node[x.node_index] True
This property is associated with the attribute index.
- node_level[source]¶
Read-Only Property
The nodes level of containtment in a Document object.
This property is associated with the attribute level.
- previous_sibling[source]¶
Read-Only Property
The node immediately preceding this node. If this property is not None then
>>> x.previous_sibling <==> x.parent_node[x.node_index - 1]
This property is associated with the attribute prev.
- next_sibling[source]¶
Read-Only Property
The node immediately following this node. If this property is not None then
>>> x.next_sibling <==> x.parent_node[x.node_index + 1]
This property is associated with the attribute next.
- insert_before(index, new_child)[source]¶
Inserts new_child to the list of children just before the child specified by index.
- extend_before(index, new_children)[source]¶
Inserts the contents of an iterable containing nodes just before the child specified by index. The following are equivalent:
>>> while doc: node.parent.insert_before(index, doc[0])
>>> node.extend_before(index, doc)
The second form, however, has a more efficient reindexing method.
- append_child(new_child)[source]¶
Adds the node new_child to the end of the list of children of this node. If the node is a DocumentFragment then it appends its child nodes. Returns the calling node.
- extend_children(new_children)[source]¶
Extend the list of children by appending children from an iterable containing nodes.
- __getitem__(i)[source]¶
Return the i-th child of this node.
>>> x.__getitem__(i) <==> x[i] >>> x.__getitem__(slice(i, j)) <==> x[i:j] >>> x.__getitem__(slice(i, j, dt)) <==> x[i:j:dt]
When using a slice, the __getitem__ function will return a list with references to the requested nodes.
- __delitem__(index)[source]¶
Delete child nodes.
>>> x.__delitem__(index) <==> del x[index] >>> x.__delitem__(slice(i, j)) <==> del x[i:j] >>> x.__delitem__(slice(i, j, dt)) <==> del x[i:j:dt]
- __setitem__(index, node)[source]¶
Replace child nodes.
>>> x.__setitem__(index) = node <==> x[index] = node >>> x.__setitem__(slice(i, j)) = dfrag <==> x[i:j] = dfrag >>> x.__setitem__(slice(i, j, dt)) = dfrag <==> x[i:j:dt] = dfrag
When using slices the nodes to be assigned to the indices need to be contained in a DocumentFragment node. This function does not support insertion as the regular slice for list does. To insert use a node use insert_before() or append_after().
- set_parent(parent, index)[source]¶
Helper Method
Modifies the parent node and takes care of the child node levels.
- append_child_node(new_child)[source]¶
Helper Method
Use this method to insert a node at a the end of the child list. See append_child() and extend_children() to see this method in action.
- insert_node_before(index, new_child)[source]¶
Helper Method
Insert a new_child at a given index. See insert_before() and extend_before() to see this method in action.