Revision 3325
Added by Aaron Marcuse-Kubitza over 12 years ago
lib/xml_dom.py | ||
---|---|---|
247 | 247 |
remove(from_) |
248 | 248 |
|
249 | 249 |
def merge_adjacent(node): |
250 |
'''Repeatedly merges two nodes as long as they or their newly-adjacent
|
|
251 |
children have the same tag name''' |
|
250 |
'''Repeatedly merges a node with its siblings as long as they or their
|
|
251 |
newly-adjacent children have the same tag name'''
|
|
252 | 252 |
if node == None: return # base case |
253 | 253 |
|
254 | 254 |
for node_, next in [(node.previousSibling, node), (node, node.nextSibling)]: |
... | ... | |
257 | 257 |
merge(next, node_) |
258 | 258 |
merge_adjacent(next_first) # previousSibling is now node_.lastChild |
259 | 259 |
|
260 |
def merge_same_name(node): |
|
261 |
'''Merges nodes with the same name as a node, using merge_adjacent()''' |
|
262 |
for node_ in by_tag_name(node.parentNode, node.tagName): |
|
263 |
if node_ is node: continue # not self |
|
264 |
merge_adjacent(node_) |
|
265 |
|
|
260 | 266 |
##### XML documents |
261 | 267 |
|
262 | 268 |
def create_doc(root='_'): |
Also available in: Unified diff
xml_dom.py: Added merge_same_name()