[New-bugs-announce] [issue18182] xml.dom.createElement() does not take implicit namespaces into account
Alexander Tobias Heinrich
report at bugs.python.org
Mon Jun 10 15:59:13 CEST 2013
New submission from Alexander Tobias Heinrich:
First of all, I am not sure, if this is a bug in python itself - it could as well be a bug in the py-dom-xpath module (http://code.google.com/p/py-dom-xpath) or not a bug at all (but I find the latter to be highly unlikely).
Consider an XML document such as:
<?xml version="1.0" encoding="utf-8"?>
If one creates a new Chimp-element using the xml.dom.createElement() function and then appends it to the Compound element, then the xpath module will not find the element unless the whole document is saved and then re-parsed.
Creating the element with xml.dom.createElementNS() and thus explicitly specifying its namespace works around the problem.
I consider this to be a bug, because in both cases, xml.dom will create the same valid XML, so I believe xpath should produce the same results in both cases, too. My believe, that the bug is in xml.dom is just a feeling and I could be wrong. I imagine, that xml.dom.createElement() forgets about adding the new element to its inherited namespace and adds it to the null namespace instead. In consequence xpath doesn't find the new element.
I originally posted a more verbose explanation of this issue to StackOverflow (see http://stackoverflow.com/questions/16980521/python-xpath-find-wont-find-new-elements-if-they-were-added-without-namespac
), because I was unsure about whether this is a bug or not - and if it was, then in which module. Because I did not receive any feedback on that post, I have now decided to file it here as a bug report.
I attached a sample script that demonstrates the problem if (xpath dependency is installed). I tested it under Windows with Python 2.7.5 and 2.7.4.
title: xml.dom.createElement() does not take implicit namespaces into account
versions: Python 2.7
Added file: http://bugs.python.org/file30527/pydomprob.py
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce