Skip to content

Instantly share code, notes, and snippets.

@DineshDevaraj
Created December 31, 2017 05:51
Show Gist options
  • Save DineshDevaraj/3cfc012e54ff6f60adfa9c192a98e813 to your computer and use it in GitHub Desktop.
Save DineshDevaraj/3cfc012e54ff6f60adfa9c192a98e813 to your computer and use it in GitHub Desktop.
import sys
from xml.dom import minidom
def PrintXml(root, pad) :
sys.stdout.write("\n%s%s : " % (' '*pad, root.tagName))
for child in root.childNodes :
if isinstance(child, minidom.Text) :
if child.data[0] != "\n" :
sys.stdout.write("%s" % child.data)
else :
PrintXml(child, pad+3)
dom = minidom.parse('sample.xml')
PrintXml(dom.documentElement, 3)
print("\n")
---------------------------------------------------------------
import sys
from xml.dom import minidom
def PrintXml (root, pad) : # {
sys.stdout.write("\n%s%s : " % (' '*pad, root.tagName))
for child in root.childNodes : # {
if isinstance(child, minidom.Text) : # {
if child.data[0] != "\n" : # {
sys.stdout.write("%s" % child.data)
# }
# }
else : # {
PrintXml(child, pad+3)
# }
# }
# }
dom = minidom.parse('sample.xml')
PrintXml(dom.documentElement, 3)
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment