XML document being parsed as single element instead of sequence of nodes

Posted by Rob Carr on Stack Overflow See other posts from Stack Overflow or by Rob Carr
Published on 2010-03-25T02:07:28Z Indexed on 2010/03/25 2:13 UTC
Read the original article Hit count: 450

Filed under:
|
|

Given xml that looks like this:

<Store>
<foo>
<book>
<isbn>123456</isbn>
</book>
<title>XYZ</title>
<checkout>no</checkout>
</foo>
<bar>
<book>
<isbn>7890</isbn>
</book>
<title>XYZ2</title>
<checkout>yes</checkout>
</bar>
</Store>

I am getting this as my parsed xmldoc:

>>> from xml.dom import minidom
>>> xmldoc = minidom.parse('bar.xml')
>>> xmldoc.toxml()
u'<?xml version="1.0" ?><Store>\n<foo>\n<book>\n<isbn>123456</isbn>\n</book>\n<t
itle>XYZ</title>\n<checkout>no</checkout>\n</foo>\n<bar>\n<book>\n<isbn>7890</is
bn>\n</book>\n<title>XYZ2</title>\n<checkout>yes</checkout>\n</bar>\n</Store>'

Is there an easy way to pre-process this document so that when it is parsed, it isn't parsed as a single xml element?

© Stack Overflow or respective owner

Related posts about python

Related posts about Xml