How do I get the whole content between two xml tags in Python?

justinboar

New Member
I try to get the whole content between an opening xml tag and it's closing counterpart. Getting the content in straight cases like \[code\]title\[/code\] below is easy, but how can I get the whole content between the tags if mixed-content is used and I want to preserve the inner tags?\[code\]<?xml version="1.0" encoding="UTF-8"?><review> <title>Some testing stuff</title> <text sometimes="attribute">Some text with <extradata>data</extradata> in it. It spans <sometag>multiple lines: <tag>one</tag>, <tag>two</tag> or more</sometag>.</text></review>\[/code\]What I want is the content between the two \[code\]text\[/code\] tags, including any tags: \[code\]Some text with <extradata>data</extradata> in it. It spans <sometag>multiple lines: <tag>one</tag>, <tag>two</tag> or more</sometag>.\[/code\]For now I use regular expressions but it get's kinda messy and I don't like this approach. I lean towards a XML parser based solution. I looked over \[code\]minidom\[/code\], \[code\]etree\[/code\], \[code\]lxml\[/code\] and \[code\]BeautifulSoup\[/code\] but couldn't find a solution for this case (whole content, including inner tags).
 
Back
Top