python - How can I split a xml document into strings between a certain tag? -
say have following xml:
<foo> <spam taste="great"> stuff</spam> <spam taste="moldy"> stuff</spam> <bar taste="eww"> stuff </bar> <bar> stuff </bar> <bacon taste="yum"> stuff </bacon><bacon taste="yum"> stuff </bacon><bacon taste="yum"> stuff </bacon> </foo>
with spam, bar, , bacon being data tags more tags inside, want split xml this
<spam taste="great"> stuff</spam> <spam taste="moldy"> stuff</spam>
,<bar taste="eww"> stuff </bar> <bar> stuff </bar>
,<bacon taste="yum"> stuff </bacon><bacon taste="yum"> stuff </bacon><bacon taste="yum"> stuff </bacon>
,
in order reorder parsing.
the basic structure this, blocks being in order.
<foo> block of bar tags block of spam tags block of bacon tags </foo>
have looked @ elementtree methods?
import xml.etree.elementtree et document = et.parse("file.xml") spams = document.findall("spam") bars = document.findall("bar") bacon = 'document.findall("bacon")
Comments
Post a Comment