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.

Author Alexander.Tobias.Heinrich
Recipients Alexander.Tobias.Heinrich
Date 2013-06-10.13:59:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1370872753.13.0.359771001968.issue18182@psf.upfronthosting.co.za>
In-reply-to
Content
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"?>
<Zoo xmlns='http://foo.bar/zoo'>
  <Compound><Chimp/></Compound>
</Zoo>

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.
History
Date User Action Args
2013-06-10 13:59:13Alexander.Tobias.Heinrichsetrecipients: + Alexander.Tobias.Heinrich
2013-06-10 13:59:13Alexander.Tobias.Heinrichsetmessageid: <1370872753.13.0.359771001968.issue18182@psf.upfronthosting.co.za>
2013-06-10 13:59:13Alexander.Tobias.Heinrichlinkissue18182 messages
2013-06-10 13:59:12Alexander.Tobias.Heinrichcreate