Skip to content

Is there a way to iterate through all the sub-elements? #4

Answered by Rogdham
amry-daud asked this question in Q&A
Discussion options

You must be logged in to vote

Hello, currently this was not a targeted use case, so the way to do it is not optimal nor documented.

I'm wondering if this use case is really prevalent, as usually XML documents tends to follow a specific schema.

If you have public XML items that fall into this use case, please share them so that I have a better understanding of real-world examples.


The usual way would be as you said to explicitly set the subnode names when defining the handler, by chaining the decorators:

@xml_handle_element("animals", "cats", "name1")
@xml_handle_element("animals", "cats", "name2")
def handle_cats_names(node):
    yield (node.name, node.text)
>>> with open('animals.xml', 'rb') as f:
...     for item in 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@amry-daud
Comment options

Answer selected by amry-daud
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants