Skip to content

Commit

Permalink
add rewrite_ids to xmlutils
Browse files Browse the repository at this point in the history
  • Loading branch information
goose-life committed Oct 17, 2019
1 parent 47ac386 commit 2154338
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions indigo/xmlutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,14 @@ def unwrap_element(elem):
parent.text = (parent.text or '') + (elem.tail or '')

parent.remove(elem)


def rewrite_ids(elem, old_id_prefix, new_id_prefix):
old_id_len = len(old_id_prefix)
if elem.get('id').startswith(old_id_prefix):
elem.set('id', new_id_prefix + elem.get('id')[old_id_len:])

# rewrite children
for child in elem.xpath('.//a:*[@id]', namespaces={'a': elem.nsmap[None]}):
if child.get('id').startswith(old_id_prefix):
child.set('id', new_id_prefix + child.get('id')[old_id_len:])

0 comments on commit 2154338

Please sign in to comment.