in src/simplify_docx/iterators/generic.py [0:0]
def xml_iter(
p: xmlFragment,
name: str,
msg: Optional[str] = None) -> Generator[el, None, None]:
"""
Iterates over an XML node yielding an appropriate element (el)
"""
handlers = __built__[name]
# INIT PHASE
children = p.getchildren()
if not children:
return
current: Optional[xmlFragment] = p.getchildren()[0]
# ITERATION PHASE
while current is not None:
if msg is not None and current.tag not in handlers.TAGS_TO_IGNORE:
print(msg +
("" if current.prefix is None else (current.prefix + ":")) +
current.tag)
if handlers.TAGS_TO_YIELD \
and current.tag in handlers.TAGS_TO_YIELD:
# Yield all math tags
yield handlers.TAGS_TO_YIELD[current.tag](current)
if handlers.TAGS_TO_NEST \
and current.tag in handlers.TAGS_TO_NEST:
_msg = None if msg is None else (" "+msg)
for elt in xml_iter(current, handlers.TAGS_TO_NEST[current.tag], _msg):
yield elt
elif handlers.TAGS_TO_NEST \
and current.tag in handlers.TAGS_TO_NEST:
_msg = None if msg is None else (" "+msg)
for elt in xml_iter(current, handlers.TAGS_TO_NEST[current.tag], _msg):
yield elt
elif handlers.TAGS_TO_WARN \
and current.tag in handlers.TAGS_TO_WARN:
# Skip these unhandled tags with a warning
warn("Skipping %s tag: %s" % (handlers.TAGS_TO_WARN[current.tag],
current.tag, ))
elif handlers.TAGS_TO_IGNORE \
and current.tag in handlers.TAGS_TO_IGNORE:
# ignore paragraph properties, deleted content and meta tags
# like bookmarks, permissions, comments, etc.
pass
elif handlers.TAGS_TO_SKIP \
and current.tag in handlers.TAGS_TO_SKIP:
# Skip over content that has been moved elsewhere
data = handlers.TAGS_TO_SKIP[current.tag]
current = skip_range(current, data[0], data[1])
if current is None:
return
else:
warn("Skipping unexpected tag: %s" % (current.tag),
UnexpectedElementWarning)
current = current.getnext()
return