$ python3
Python 3.8.5 (default, Aug 2 2020, 15:09:07)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from xml.dom import minidom
# Lets parse a simple XML file with comment & text nodes in the top level.
>>> dom = minidom.parseString('<?xml version="1.0" encoding="UTF-8"?>\n<!--foo-->\n<!--bar-->\n<main>\n<!--foo-->\n<!--bar-->\n</main>\n')
# Where did those newlines get to outside of <main> ?
>>> dom.toxml()
'<?xml version="1.0" ?><!--foo--><!--bar--><main>\n<!--foo-->\n<!--bar-->\n</main>'
# No Text nodes in the root list :(.
>>> dom.childNodes
[<DOM Comment node "'foo'">, <DOM Comment node "'bar'">, <DOM Element: main at 0x7f6f5394c040>]
# But they all exist fine under <main>.
>>> dom.childNodes[2].childNodes
[<DOM Text node "'\n'">, <DOM Comment node "'foo'">, <DOM Text node "'\n'">, <DOM Comment node "'bar'">, <DOM Text node "'\n'">]
|