Skip to content

Carve Code

A blog about coding

Pretty printing XML in Python


import xml.dom.minidom

dom = xml.dom.minidom.parse(xml_fname) 
# or 
# dom = xml.dom.minidom.parseString(xml_string)
pretty_xml_as_string = dom.toprettyxml()


Share this:

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
Author pashanhuPosted on June 13, 2020Categories PythonTags print, XML

Post navigation

Previous Previous post: Delete files owned by a specific user on Linux
Next Next post: Use ElementTree to add elements and sub-elements

Recent Posts

  • Traits and Template Partial Specialisation – 2
  • Traits and Template Partial Specialisation – 1
  • Assert exception during python unit test
  • Resize VirtualBox hard disk capacity
  • Solution to “Another app is currently holding the yum lock; waiting for it to exit”

Recent Comments

    Archives

    • September 2022
    • July 2022
    • June 2022
    • April 2022
    • August 2021
    • November 2020
    • October 2020
    • June 2020
    • May 2020
    • February 2020
    • October 2019
    • September 2019
    • August 2019

    Categories

    • Algorithm
    • Boost
    • C/C++
    • Debug
    • git
    • GitHub
    • Image/Graphics
    • Java
    • Linux
    • Node.js
    • Other
    • Python
    • Qt
    • Swift
    Carve Code Proudly powered by WordPress