Kasimier<br><br>My fault on the xml namespace.&nbsp; It should be xmlns:xml=&quot; <a href="http://www.w3.org/XML/1998/namespace">http://www.w3.org/XML/1998/namespace</a>&quot;.&nbsp; That solves the xmllint problem.<br><br>The problem I am seeing occurs with or without the additional space before the URI.&nbsp; I have two test scripts to illustrate my problem.&nbsp; The two scripts and the test xml file follow.&nbsp; 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(&quot;test.xml&quot;)<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(&quot;test.xml&quot;)<br>outroot = etree.Element(&quot;root&quot;)<br>doc = intree.getiterator()<br>for el in doc:<br>&nbsp;&nbsp;&nbsp; newel = el<br>&nbsp;&nbsp;&nbsp; outroot.append
(newel)<br>outtree = etree.ElementTree(outroot)<br>outtree.write(sys.stdout)<br><br>Test file:<br><br>&lt;?xml version=&quot;1.0&quot;?&gt;<br>&lt;svg<br>&nbsp;&nbsp;&nbsp; xmlns:svg=&quot;<a href="http://www.w3.org/2000/svg">http://www.w3.org/2000/svg
</a>&quot;<br>&nbsp;&nbsp;&nbsp; xmlns:xml=&quot; <a href="http://www.w3.org/XML/1998/namespace">http://www.w3.org/XML/1998/namespace</a>&quot;&gt;<br>&lt;a id=&quot;first&quot; xml:space=&quot;default&quot;&gt;&lt;/a&gt;<br>&lt;/svg&gt;
<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?&nbsp; Parsing not handling the xml namespace properly?&nbsp; 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> &lt;<a href="mailto:K.Buchcik@4commerce.de">K.Buchcik@4commerce.de</a>&gt; 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>&gt; Scott Haeger wrote:<br><br>[...]<br><br>&gt; &gt; Test.xml is the following:<br>&gt; &gt;<br>&gt; &gt; &lt;?xml version=&quot;1.0&quot;?&gt;<br>&gt; &gt; &lt;svg
<br>&gt; &gt;&nbsp;&nbsp;&nbsp;&nbsp; xmlns:xml=&quot; <a href="http://www.w3.org/1998/XML">http://www.w3.org/1998/XML</a>&quot;&gt;<br>&gt; &gt; &lt;a id=&quot;first&quot; xml:space=&quot;default&quot;&gt;&lt;/a&gt;<br>&gt; &gt; &lt;/svg&gt;
<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>&lt;svg xmlns:xml=&quot; <a href="http://www.w3.org/1998/XML">http://www.w3.org/1998/XML</a>
&quot;&gt;<br><br>$ xmllint --debug xmlns.xml<br>xmlns.xml:2: namespace error : xml namespace prefix mapped to wrong URI<br>&lt;svg xmlns:xml=&quot; <a href="http://www.w3.org/1998/XML">http://www.w3.org/1998/XML</a>&quot;&gt;
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;^<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>&nbsp;&nbsp;ELEMENT svg<br>&nbsp;&nbsp;&nbsp;&nbsp;TEXT interned<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content=<br>&nbsp;&nbsp;&nbsp;&nbsp;ELEMENT a<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ATTRIBUTE id<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TEXT<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content=first<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ATTRIBUTE space<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TEXT<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content=default<br>&nbsp;&nbsp;&nbsp;&nbsp;TEXT interned
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;content=<br><br>[...]<br><br>&gt; &quot;&quot;&quot;<br>&gt; The prefix xml is by definition bound to the namespace name<br>&gt; <a href="http://www.w3.org/XML/1998/namespace">http://www.w3.org/XML/1998/namespace
</a>.<br>&gt; &quot;&quot;&quot;<br>&gt;<br>&gt; 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-&gt;oldNs. The XML namespace declaration<br>is &quot;built-in&quot; by every XML processor, so you don't have to declare it.
<br><br>Regards,<br><br>Kasimier<br></blockquote></div><br>