6.3.2 Node Objects

class Node()

The Node class is the base class for all nodes in the plasTeX DOM inluding elements, text, etc.

attributes

a dictionary containing the attributes, in the case of plasTeX  the LaTeX macro arguments

childNodes

a list of the nodes that are contained by this one. In plasTeX, this generally contains the contents of a LaTeX environment.

isElementContentWhitespace

boolean indicating whether or not the node only contains whitespace.

lastChild

the last node in the childNodes list. If there are no child nodes, the value is None.

nodeName

the name of the node. This is either the special node name as specified in the XML DOM (e.g. #document-fragment, #text, etc.), or, if the node corresponds to an element, it is the name of the element.

nodeType

integer indicating the type of the node. The node types are defined as:

  • Node.ELEMENT_NODE

  • Node.ATTRIBUTE_NODE

  • Node.TEXT_NODE

  • Node.CDATA_SECTION_NODE

  • Node.ENTITY_REFERENCE_NODE

  • Node.ENTITY_NODE

  • Node.PROCESSING_INSTRUCTION_NODE

  • Node.COMMENT_NODE

  • Node.DOCUMENT_NODE

  • Node.DOCUMENT_TYPE_NODE

  • Node.DOCUMENT_FRAGMENT_NODE

  • Node.NOTATION_NODE

Note: These are defined by the XML DOM, not all of them are used by plasTeX.

parentNode

refers to the node that contains this node

previousSibling

the node in the document that is adjacent to and immediately before this node. If one does not exist, the value is None.

nextSibling

the node in the document that is adjacent to and immediately after this node. If one does not exist, the value is None.

ownerDocument

the node that owner of, and ultimate parent of, all nodes in the document

textContent

contains just the text content of this node

unicode

specifies a unicode string that could be used in place of the node. This unicode string will be converted into tokens in the plasTeX  output stream.

userdata

dictionary used for holding user-defined data

__add__(other)

create a new node that is the sum of self and other. This allows you to use nodes in Python statements like: node + other.

append(newChild)

adds a new child to the end of the child nodes

appendChild(newChild)

same as append

cloneNode(deep=False)

create a clone of the current node. If deep is true, then the attributes and child nodes are cloned as well. Otherwise, all references to attributes and child nodes will be shared between the nodes.

__cmp__(other)

same as isEqualNode, but allows you to compare nodes using the Python statement: node == other.

extend(other)

appends other to list of children then returns self

__getitem__(i)

returns the child node at the index given by i. This allows you to use Python’s slicing syntax to retrieve child nodes: node[i].

getUserData(key)

retrieves the data in the userdata dictionary under the name key

hasAttributes()

returns a boolean indicating whether or not this node has attributes defined

hasChildNodes()

returns a boolean indicating whether or not the node has child nodes

__iadd__(other)

same as extend. This allows you to use nodes in Python statements like: node += other.

insert(i, newChild)

inserts node newChild into position i in the child nodes list

insertBefore(newChild, refChild)

inserts newChild before refChild in this node. If refChild is not found, a NotFoundErr exception is raised.

isEqualNode(other)

indicates whether the given node is equivalent to this one

isSameNode(other)

indicates whether the given node is the same node as this one

__iter__()

returns an iterator that iterates over the child nodes. This allows you to use Python’s iter() function on nodes.

__len__()

returns the number of child nodes. This allows you to use Python’s len() function on nodes.

normalize()

combine consecutive text nodes and remove comments in this node

pop(index=-1)

removes child node and the index given by index. If no index is specified, the last child is removed.

__radd__(other)

create a new node that is the sum of other and self. This allows you to use nodes in Python statements like: other + node.

replaceChild(newChild, oldChild)

replaces oldChild with newChild in this node. If oldChild is not found, a NotFoundErr exception is raised.

removeChild(oldChild)

removes oldChild from this node. If oldChild is not found, a NotFoundErr exception is raised.

__setitem__(i, node)

sets the item at index i to node. This allows you to use Python’s slicing syntax to insert child nodes; see the example below.

mynode[5] = othernode
mynode[6:10] = [node1, node2]

setUserData(key, data)

put data specified in data into the userdata dictionary under the name given by key

toXML()

return an XML representation of the node