In many ways, an Element instance acts
like a Python list, with its XML child elements acting as
the members of that list.
You can use the Python len() function to
determine how many children an element has. For example,
if node is an Element
instance with five element children, len(node) will return the value 5.
You can add, replace, or delete children of an element
using regular Python list operations. For example, if an
Element instance node has
three child elements, node[0] is the first
child, and node[2] is the third child.
In the examples that follow, assume that is an EElement instance.
returns the child element
of E[i] at
position E, if there is one. If there is no child element at
that position, this operation raises an iIndexError exception.
returns a list of the child elements
between positions E[i:j] and i.
j
For example, node[2:4] returns a list
containing the third and fourth children of node.
You can replace one child of an element with a new
element Ec using a statement of this
form:
E[i] =c
If is
not the position of an existing child, this operation
will raise an iIndexError.
You can replace a sequence of adjacent children of an
element
using slice assignment:
E
E[i:j] =seq
where
is a sequence of seqElement instances.
If the slice [ does not
specify an existing set of children, this operation
will raise an i:j]IndexError exception.
You can delete one child of an element like this:
delE[i]
where
is the index of that child.
i
You can delete a slice out of the list of element children like this:
delE[i:j]