Hello
,
I need to parse XML file.
For example, my XML file looks like this:

I need to parse XML file.
For example, my XML file looks like this:
<root> <child1 attr1="value1" attr2="value2"/> <child2> <child3> some text </child3> </child2> </root>And when I use this code:
walkAll = root.getiterator() for elt in walkAll: atr = elt.attrib if elt.attrib: stdout.write('<%s ' %elt.tag) for name, value in elt.attrib.items(): attributes =' {0:s} = "{1:s}"'.format(name, value) stdout.write(attributes) #print("<%s %s>" % (elt.tag, atr)) else: print("<%s>" % elt.tag) if elt.text == None: continue print("</%s>" % elt.tag)My output looks like:
Output:<root>
</root>
<child1 attr1= "value1" attr2 = "value2"<child2>
</child2>
<child3>
some text
</child3>
And I want to look like this without convert it to string.Output:<root>
<child1 attr1="value1" attr2="value2"/>
<child2>
<child3>
some text
</child3>
</child2>
</root>