12 Sep 15:19
Re: Serialization with namespaces
From: Anders Bruun Olsen <anders <at> bruun-olsen.net>
Subject: Re: Serialization with namespaces
Newsgroups: gmane.comp.python.lxml.devel
Date: 2007-09-12 13:19:21 GMT
Subject: Re: Serialization with namespaces
Newsgroups: gmane.comp.python.lxml.devel
Date: 2007-09-12 13:19:21 GMT
Stefan Behnel wrote: > Stefan Behnel wrote: >> Stefan Behnel wrote: >>> Anders Bruun Olsen wrote: >>>> Now the problem occurs when I try to serialize. When I serialize the >>>> root, everything looks fine: >>>> >>>> >>> etree.tostring(root, pretty_print=True) >>>> '<topicMap xmlns="http://www.topicmaps.org/xtm/1.0/" >>>> xmlns:xlink="http://www.w3.org/1999/xlink" id="personnavnereg1"> >>>> ... >>>> >>>> The XML Namespace is applied as it should. However on the topic-element >>>> that I found using XPath no XML Namespace is output: >>>> >>>> >>> etree.tostring(elem, pretty_print=True) >>>> '<topic id="abeleHenriksdatter">\n\t\t<instanceOf>\n\t\t\t<topicRef >>>> ... >>>> >>>> Even though the nsmap attribute is set correctly: >>>> >>>> >>> elem.nsmap >>>> {None: 'http://www.topicmaps.org/xtm/1.0/', 'xlink': >>>> 'http://www.w3.org/1999/xlink'} >>> Hmm, I actually thought these problems were gone with 1.3, but I can reproduce >>> this with the current trunk. >> Ok, so the problem here is libxml2. It serialises only the namespaces that are >> defined on the node itself, not all those that are defined in the node's context. > > Here's a patch (against the trunk) that works for me. It copies the node > before the serialisation and adds all namespaces that were declared up in the > tree. > > Stefan > Something seems amiss with the patch: $ svn co http://codespeak.net/svn/lxml/trunk lxml $ cd lxml $ patch <~/download/ns-serialisation.patch can't find file to patch at input line 5 Perhaps you should have used the -p or --strip option? The text leading up to this was: -------------------------- |Index: src/lxml/proxy.pxi |=================================================================== |--- src/lxml/proxy.pxi (Revision 46423) |+++ src/lxml/proxy.pxi (Arbeitskopie) -------------------------- File to patch: -- -- Anders
RSS Feed