Revision 999
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/xml_dom.py | ||
---|---|---|
104 | 104 |
##### Parent nodes |
105 | 105 |
|
106 | 106 |
class NodeParentIter: |
107 |
'''Does not treat the document object as the root node's parent, since it's |
|
108 |
not a true element node''' |
|
107 | 109 |
def __init__(self, node): self.node = node |
108 | 110 |
|
109 | 111 |
def __iter__(self): return self |
... | ... | |
117 | 119 |
self.node = self.node.parentNode |
118 | 120 |
return node |
119 | 121 |
|
122 |
def parent(node): |
|
123 |
'''See NodeParentIter for special treatment of root node''' |
|
124 |
try: return NodeParentIter(root).next() |
|
125 |
except StopIteration: return None |
|
126 |
|
|
120 | 127 |
##### Element nodes containing text |
121 | 128 |
|
122 | 129 |
def is_text_node(node): return node.nodeType == Node.TEXT_NODE |
Also available in: Unified diff
xml_dom.py: Added parent() to get parent node without recursing past the root node to the document object. Documented that NodeParentIter incorporates this sanity check.