Skip to content
Advertisement

Select XML tags that have certain tags inside them

I am parsing an xml file with Python using ElementTree, and I need to select tags like <PostalAddressText> below that have tags like <insert> inside them. How do I do that? I need to get a list of all relevant tag names in the xml file that satisfy the condition.

Here’s a fragment of XML that I am parsing (the actual text except for inside tags has been replaced with Lorem Ipsum):

JavaScript

I have tried this but nothing gets printed to the console:

JavaScript

Advertisement

Answer

Not sure what is your expected output but see the code and output below

JavaScript

output

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement