Amara: Where's my attribute?

uche.ogbuji at gmail.com uche.ogbuji at gmail.com
Sun Jul 2 22:36:50 EDT 2006


AdSR wrote:
> Hi,
>
> I'm having a problem with the Amara toolkit. Try this:
>
> >>> from amara import binderytools
> >>> raw = '<pq:test xmlns="http://example.com/namespace" xmlns:pq="http://pq.com/ns2"/>'
> >>> rwd = binderytools.bind_string(raw)
> >>> print rwd.xml()
> <?xml version="1.0" encoding="UTF-8"?>
> <pq:test xmlns:pq="http://pq.com/ns2"/>
>
> What happened to the xmlns attribute? Does anyone know a solution to
> this? The only workaround I found is to:
>
> >>> rwd.test.xml_set_attribute(u'xmlns', u'http://example.com/namespace')
> u'xmlns'
> >>> print rwd.xml()
> <?xml version="1.0" encoding="UTF-8"?>
> <pq:test xmlns:pq="http://pq.com/ns2"
> xmlns="http://example.com/namespace"/>
>
> but it only helps if you know what to patch.
>
> My setup:
>
> Python 2.4.3
> 4Suite 1.0b3
> Amara 1.0
>
> I see that people have reported similar problems with other XML
> toolkits, so I guess this is a general namespace ugliness.

What is the actual problem you're trying to solve?  If you just want to
force a namespace declaration in output (this is sually to support
QNames in content) the most well-known XML hack is to create a dummy
attribute with the needed prefix and namespace.  But this does not work
when you're trying to force a default namespace declaration.  Then
again, you generally can't use QNames in content with a default
namespace declaration.  So my guess is that you somehow got way off the
rails in your problem-solving, and you'll need to provide mre
background if you want help.

BTW, I recommend upgrading to Amara 1.1.7.  That branch will soon be
1.2, and I consider it more mature than 1.0 at this point.  The API's
also easier:

>>> import amara
>>> rwd = amara.parse('<pq:test xmlns="http://example.com/namespace" xmlns:pq="http://pq.com/ns2"/>')


--
Uche Ogbuji                               Fourthought, Inc.
http://uche.ogbuji.net                    http://fourthought.com
http://copia.ogbuji.net                   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/




More information about the Python-list mailing list