DDMAL/libmei

Move children, lose id search

Closed this issue · 1 comments

Moving children to a new parent consists of performing an add and delete operation. The list of children to move must be constructed, moved to the new parent, and then the old children are removed from the document. However, removing children as the last step removes the ids from the document-id-map, meaning these moved children can no longer be searched by id, although they can be found by filtering the list of elements formed through parent.getChildrenByName().

Example: (in python)

# get list of children to move
old_staff_elements = old_staff.getChildren()
example_id = old_staff_elements[0].getId()

# create new parent
new_staff = MeiElement("staff")

# move chlidren to new parent
new_staff.setChildren(old_staff_elements)

# remove old parent tree
old_staff.getParent().removeChild(old_staff)

At this point, calling meidoc.getElementById(example_id) is not found, although it is in the document.

It's not really a bug after looking at the code, everything functions as expected. However, from an end user perspective, it may be unclear why this is happening.

In the example you gave, new_staff isn't being added to the document so it makes sense that the id would not be in the document id map.