Python-Ref > XML > DOM > Summary of Node interface

Klíčová slova
Knihovní funkce

Summary of Node interface

What can you do with a node (element or text-node)


The following methods and properties are common to all nodes. More details are available in the Python documentation.
Name Arguments Description
parentNode returns the parent node
attributes NamedNodeMap of all atributes - example is here
previousSibling returns the previous sibling
nextSibling returns the next sibling
childNodes list of all child nodes
firstChild the first child node
lastChild the last child node
appendChild() newChild adds a new node at end of child nodes list
insertBefore() newChild,refChild inserts a new node before the node refChild
removeChild() oldChild removes the child oldChild
replaceChild() newChild,oldChild replace the child newChild with oldChild
normalize() join adjacent text nodes together
cloneNode() deep clone the current node to obtain a copy. If deep is True, child nodes are copied as well


The Text node has only one property - data.
Name Arguments Description
data returns the content of the Text node as a unicode string


The following properties and methods are specific to elements. More details are available in the Python documentation.
Name Arguments Description
tagName returns the name of the tag
getElementsByTagName() name returns all descendant elements with a specified name
hasAttribute() name returns True if the element has a specified attribute
getAttribute() name returns the value of a specified attribute, empty string if attribute does not exist
removeAttribute() name removes an attribute from element
setAttribute() name,value sets a value of an attribute, replacing an old value if necessary