tags:

views:

1259

answers:

3

The ElementTree.parse reads from a file, how can I use this if I already have the XML data in a string?

Maybe I am missing something here, but there must be a way to use the ElementTree without writing out the string to a file and reading it again.

xml.etree.elementtree

+1  A: 

It's on the page you linked. Use fromstring.

sanxiyn
+7  A: 

If you're using xml.etree.ElementTree.parse to parse from a file, then you can use xml.etree.ElementTree.fromstring to parse from text.

See xml.etree.ElementTree

Jim H.
+5  A: 

You need the xml.etree.ElementTree.fromstring(text)

from elementtree.ElementTree import XML, fromstring, tostring
myxml = fromstring(text)
karlcow