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.

Revisions

  1. DineshDevaraj created this gist Dec 31, 2017.
    42 changes: 42 additions & 0 deletions input_output.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    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")