Pretty printing

It would be useful for us to be able to produce output in a more legible format, such as the example shown at the beginning of this section. To do this, we can use another XML API, minidom, provided by the standard library.

We can use the following commands to print some nicely formatted XML:

>>> import xml.dom.minidom as minidom
>>> print(minidom.parseString(ET.tostring(root)).toprettyxml())
<?xml version="1.0" ?>
<root>
<book>
<name>Book1</name>
</book>
</root>
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset