Element is the superclass to all specific elements.
Elements contain attributes and child nodes. Elements emulate dictionaries for attributes, indexing by attribute name (a string). To set the attribute 'att' to 'value', do:
element['att'] = 'value'
There are two special attributes: 'ids' and 'names'. Both are lists of unique identifiers, and names serve as human interfaces to IDs. Names are case- and whitespace-normalized (see the fully_normalize_name() function), and IDs conform to the regular expression [a-z](-?[a-z0-9]+)* (see the make_id() function).
Elements also emulate lists for child nodes (element nodes and/or text nodes), indexing by integer. To get the first child node, use:
element[0]
Elements may be constructed using the += operator. To add one new child node to element, do:
element += node
This is equivalent to element.append(node).
To add a list of multiple child nodes at once, use the same += operator:
element += [node1, node2]
This is equivalent to element.extend([node1, node2]).
There are no implemented interfaces.
child_text_separator
(type:
str
)
'\n\n'
document
(type: NoneType
)
None
line
(type: NoneType
)
None
list_attributes
(type:
tuple
)
('ids', 'classes', 'names', 'dupnames', 'backrefs')
parent
(type: NoneType
)
None
source
(type: NoneType
)
None
tagname
(type: NoneType
)
None
append(item)
asdom(dom=None)
Return a DOM fragment representation of this Node.
astext()
attlist()
clear()
copy()
deepcopy()
delattr(attr)
emptytag()
endtag()
extend(item)
first_child_matching_class(childclass, start=0, end=2147483647)
Return the index of the first child whose class exactly matches.
Parameters:
first_child_not_matching_class(childclass, start=0, end=2147483647)
Return the index of the first child whose class does not match.
Parameters:
get(key, failobj=None)
has_key(attr)
hasattr(attr)
index(item)
insert(index, item)
is_not_default(key)
next_node(condition=None, include_self=0, descend=1, siblings=0, ascend=0)
Return the first node in the iterable returned by traverse(), or None if the iterable is empty.
Parameter list is the same as of traverse. Note that include_self defaults to 0, though.
non_default_attributes()
note_referenced_by(name=None, id=None)
Note that this Element has been referenced by its name name or id id.
pformat(indent=' ', level=0)
pop(i=-1)
remove(item)
replace(old, new)
Replace one child Node with another child or children.
replace_self(new)
Replace self node with new, where new is a node or a list of nodes.
set_class(name)
Add a new class to the "classes" attribute.
setdefault(key, failobj=None)
setup_child(child)
shortrepr()
starttag()
traverse(condition=None, include_self=1, descend=1, siblings=0, ascend=0)
Return an iterable containing
If condition is not None, the iterable contains only nodes for which condition(node) is true. If condition is a node class cls, it is equivalent to a function consisting of return isinstance(node, cls).
If ascend is true, assume siblings to be true as well.
For example, given the following tree:
<paragraph> <emphasis> <--- emphasis.traverse() and <strong> <--- strong.traverse() are called. Foo Bar <reference name="Baz" refid="baz"> Baz
Then list(emphasis.traverse()) equals
[<emphasis>, <strong>, <#text: Foo>, <#text: Bar>]
and list(strong.traverse(ascend=1)) equals
[<strong>, <#text: Foo>, <#text: Bar>, <reference>, <#text: Baz>]
update_basic_atts(dict)
Update basic attributes ('ids', 'names', 'classes', 'dupnames', but not 'source') from node or dictionary dict.
walk(visitor)
Traverse a tree of Node objects, calling the dispatch_visit() method of visitor when entering each node. (The walkabout() method is similar, except it also calls the dispatch_departure() method before exiting each node.)
This tree traversal supports limited in-place tree modifications. Replacing one node with one or more nodes is OK, as is removing an element. However, if the node removed or replaced occurs after the current node, the old node will still be traversed, and any new nodes will not.
Within visit methods (and depart methods for walkabout()), TreePruningException subclasses may be raised (SkipChildren, SkipSiblings, SkipNode, SkipDeparture).
Parameter visitor: A NodeVisitor object, containing a visit implementation for each Node subclass encountered.
walkabout(visitor)
Perform a tree traversal similarly to Node.walk() (which see), except also call the dispatch_departure() method before exiting each node.
Parameter visitor: A NodeVisitor object, containing a visit and depart implementation for each Node subclass encountered.