You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When we parse XML, we should provide a way to iterate over all nodes at a given level, in the order received.
Currently, you can iterate over all nodes at a given level this way:
for node in root['a'].values():
for subnode in node.list():
pass
But, this has two problems:
It uses two levels of loops to do something common. (And, even if you could use list comprehension to combine this to a single loop, the list comprehension would be more complicated than it should be to do something this common.)
This will lose the original input ordering.
Ideally, we should be able to do something like:
for node in root['a'].nodes():
pass
Expected implementation:
Maintain an internal list of nodes over which to iterate.
When items are added/deleted in an XMLDictNode, update the node list.
Requires overriding the __setitem__, __delitem__, and clear methods
When items are added/deleted in an XMLListNode, update the parent's ordered list.
Requires overriding the __setitem__, __delitem__, __delslice__, and pop methods; however, this will probably actually require switching theXMLListNodeto be a subclass ofMutableSequence`.
Some quirks to be considered:
The in-place dict method shouldn't modify order.
Replacements should inherit the position of their parents.
What if there is no parent? Nested lists? Other strange things?
The text was updated successfully, but these errors were encountered:
When we parse XML, we should provide a way to iterate over all nodes at a given level, in the order received.
Currently, you can iterate over all nodes at a given level this way:
But, this has two problems:
Ideally, we should be able to do something like:
Expected implementation:
XMLDictNode
, update the node list.__setitem__
,__delitem__
, andclear
methodsXMLListNode
, update the parent's ordered list.__setitem__
,__delitem__
,__delslice__
, andpop
methods; however, this will probably actually require switching the
XMLListNodeto be a subclass of
MutableSequence`.Some quirks to be considered:
dict
method shouldn't modify order.The text was updated successfully, but these errors were encountered: