This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: xml.dom.minidom parsing omits Text nodes in top level
Type: Stage:
Components: XML Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: vapier
Priority: normal Keywords:

Created on 2020-11-13 06:22 by vapier, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg380872 - (view) Author: Mike Frysinger (vapier) Date: 2020-11-13 06:22
$ 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'">]
History
Date User Action Args
2022-04-11 14:59:38adminsetgithub: 86507
2020-11-13 06:22:54vapiercreate