Kasimier<br><br>My fault on the xml namespace. It should be xmlns:xml=" <a href="http://www.w3.org/XML/1998/namespace">http://www.w3.org/XML/1998/namespace</a>". That solves the xmllint problem.<br><br>The problem I am seeing occurs with or without the additional space before the URI. I have two test scripts to illustrate my problem. The two scripts and the test xml file follow. Another test file would be an Inkscape document with a text element.
<br><br>Problem does not occur in this script:<br><br>from lxml import etree<br>import sys<br>intree = etree.parse("test.xml")<br>intree.write(sys.stdout)<br><br>Problem occurs: Note the xml namespace in the output.
<br><br>from lxml import etree<br>import sys<br>intree = etree.parse("test.xml")<br>outroot = etree.Element("root")<br>doc = intree.getiterator()<br>for el in doc:<br> newel = el<br> outroot.append
(newel)<br>outtree = etree.ElementTree(outroot)<br>outtree.write(sys.stdout)<br><br>Test file:<br><br><?xml version="1.0"?><br><svg<br> xmlns:svg="<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg
</a>"<br> xmlns:xml=" <a href="http://www.w3.org/XML/1998/namespace">http://www.w3.org/XML/1998/namespace</a>"><br><a id="first" xml:space="default"></a><br></svg>
<br><br>Interesting notes:<br>The space before the URI does not affect result.<br>Switching for xml:space to svg:space fixes the problem<br>Problem occurs with or without xml namespace declaration<br>__copy__ and/or append are suspect? Parsing not handling the xml namespace properly? I wish I knew more about the library.
<br><br>Scott<br><br><br><br><div><span class="gmail_quote">On 2/22/06, <b class="gmail_sendername">Kasimier Buchcik</b> <<a href="mailto:K.Buchcik@4commerce.de">K.Buchcik@4commerce.de</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br><br>On Wed, 2006-02-22 at 08:39 +0100, Stefan Behnel wrote:<br>> Scott Haeger wrote:<br><br>[...]<br><br>> > Test.xml is the following:<br>> ><br>> > <?xml version="1.0"?><br>> > <svg
<br>> > xmlns:xml=" <a href="http://www.w3.org/1998/XML">http://www.w3.org/1998/XML</a>"><br>> > <a id="first" xml:space="default"></a><br>> > </svg>
<br><br>[...]<br><br>I don't know if this is just a typo in the example, but the<br>namespace-URI begins with a space-character:<br><svg xmlns:xml=" <a href="http://www.w3.org/1998/XML">http://www.w3.org/1998/XML</a>
"><br><br>$ xmllint --debug xmlns.xml<br>xmlns.xml:2: namespace error : xml namespace prefix mapped to wrong URI<br><svg xmlns:xml=" <a href="http://www.w3.org/1998/XML">http://www.w3.org/1998/XML</a>">
<br> ^<br>DOCUMENT<br>version=1.0<br>URL=xmlns.xml<br>standalone=true<br>namespace xml href=<a href="http://www.w3.org/XML/1998/namespace">http://www.w3.org/XML/1998/namespace</a>
<br> ELEMENT svg<br> TEXT interned<br> content=<br> ELEMENT a<br> ATTRIBUTE id<br> TEXT<br> content=first<br> ATTRIBUTE space<br> TEXT<br> content=default<br> TEXT interned
<br> content=<br><br>[...]<br><br>> """<br>> The prefix xml is by definition bound to the namespace name<br>> <a href="http://www.w3.org/XML/1998/namespace">http://www.w3.org/XML/1998/namespace
</a>.<br>> """<br>><br>> Source: <a href="http://www.w3.org/TR/REC-xml-names/">http://www.w3.org/TR/REC-xml-names/</a><br><br><br>[...]<br><br>Just an info: Libxml2 strips all explicit declarations of the XML
<br>namespace, since it stores the XML ns-declaration in a special field on<br>the doc itself, namely in xmlDoc->oldNs. The XML namespace declaration<br>is "built-in" by every XML processor, so you don't have to declare it.
<br><br>Regards,<br><br>Kasimier<br></blockquote></div><br>