[New-bugs-announce] [issue42341] xml.dom.minidom parsing omits Text nodes in top level

Mike Frysinger report at bugs.python.org
Fri Nov 13 01:22:54 EST 2020


New submission from Mike Frysinger <vapier at gmail.com>:

$ 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'">]

----------
components: XML
messages: 380872
nosy: vapier
priority: normal
severity: normal
status: open
title: xml.dom.minidom parsing omits Text nodes in top level
versions: Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42341>
_______________________________________


More information about the New-bugs-announce mailing list