
Andreas Pakulat wrote:
So the following should not happen, if I understand you correctly?
from lxml.etree import * [25180 refs] doc = fromstring("<elem xmlns=\"test\" />") [25226 refs] doc.append("{test}sub") Traceback (most recent call last): File "<stdin>", line 1, in ? File "etree.pyx", line 397, in etree._Element.append TypeError: Argument 'element' has incorrect type (expected etree._Element, got str) [25278 refs] doc.append(Element("{test}sub")) [25278 refs] tostring(doc) '<elem xmlns="test"><ns0:sub xmlns:ns0="test"/></elem>' [25280 refs] doc2 = fromstring("<main />") [25284 refs] doc2.append(doc) [25284 refs] tostring(doc2) '<main><elem xmlns="test"><sub xmlns:ns0="test"/></elem></main>'
Correct, that should not happen, as my patch calls the DOMWrap function on "elem" at the before last line. So I would assume the modified libxml2 function doesn't solve the problem.
However this works:
doc = fromstring("<ns0:elem xmlns:ns0=\"test\" />") [25285 refs] doc.append(Element("{test}sub")) [25285 refs] tostring(doc) '<ns0:elem xmlns:ns0="test"><ns0:sub/></ns0:elem>' [25285 refs]
So at least something works (my system lxml doesn't show this behaviour). However I think this is the normal ns-cleanup working and it doesn't fix the bug I reported with libxml...
Right, the Element() call should create an ns0 prefix, which is then merged with the existing one. So that should just work as before. Stefan