Revision 1321
Added by Aaron Marcuse-Kubitza almost 13 years ago
lib/xml_func.py | ||
---|---|---|
11 | 11 |
import term |
12 | 12 |
import util |
13 | 13 |
import xml_dom |
14 |
import xpath |
|
14 | 15 |
|
15 | 16 |
##### Exceptions |
16 | 17 |
|
... | ... | |
251 | 252 |
out_items.append((part, ' '.join(value.split(' ')[slice_]))) |
252 | 253 |
return _name(out_items) |
253 | 254 |
funcs['_namePart'] = _namePart |
255 |
|
|
256 |
def _simplifyPath(items): |
|
257 |
items = dict(items) |
|
258 |
try: |
|
259 |
next = cast(str, items['next']) |
|
260 |
require = cast(str, items['require']) |
|
261 |
root = items['path'] |
|
262 |
except KeyError, e: raise SyntaxException(e) |
|
263 |
|
|
264 |
node = root |
|
265 |
while node != None: |
|
266 |
new_node = xpath.get_1(node, next, allow_rooted=False) |
|
267 |
if xpath.get_1(node, require, allow_rooted=False) == None: # empty elem |
|
268 |
xml_dom.replace(node, new_node) # remove current elem |
|
269 |
if node is root: root = new_node # also update root |
|
270 |
node = new_node |
|
271 |
return root |
|
272 |
funcs['_simplifyPath'] = _simplifyPath |
Also available in: Unified diff
xml_func.py: Added _simplifyPath