473,803 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Amara: Where's my attribute?

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.bi nd_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_se t_attribute(u'x mlns', 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.

Regards,

AdSR

Jun 29 '06 #1
5 1534
"AdSR" wrote:
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.bi nd_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 documents are 100% identical in XML infoset terms, so what's the problem here ?
I see that people have reported similar problems with other XML toolkits, so I guess this is a
general namespace ugliness.


lack of namespace understanding, more likely.

</F>

Jun 29 '06 #2
Fredrik Lundh wrote:
[cut]
the documents are 100% identical in XML infoset terms, so what's the problem here ?


Looks like the problem is somewere else, after all: Some software
relies on these "unused" xmlns attributes, most notably XML Schema
tools. Which is unfortunate, because xmlns attributes indeed have the
full right to receive special treatment.
I see that people have reported similar problems with other XML toolkits, so I guess this is a
general namespace ugliness.


lack of namespace understanding, more likely.


May I suggest a saying: Never attribute to lack of knowledge what you
can attribute to confusing signals :)

Yours truly,
AdSR

Jun 29 '06 #3
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.bi nd_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_s et_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('<p q: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/

Jul 3 '06 #4
uc*********@gma il.com wrote:
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.
I wanted to remove documentation elements from some XML Schema files.
The problem showed when I tried to use the stripped schemas, because
the namespace declaration for user-defined types was missing. Of
course, since these types are named and referred to in attribute
*values*, Amara had no way to know that the namespace declaration was
still needed (didn't matter if default or non-default). This is more a
problem of how XML Schema is defined against XML namespace rules, since
XML Schena uses namespaces in a context of which XML parsers aren't
normally aware.
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:
I know, especially the insert-before/after feature :) But I ran into a
problem that I describe below and you advertised 1.0 as "stable
version", so I switched immediately.

The problem can be reproduced like this:
>>import amara
amara.parse(' http://www.w3.org/2001/XMLSchema.xsd')
START DTD xs:schema -//W3C//DTD XMLSCHEMA 200102//EN XMLSchema.dtd
http://www.w3.org/2001/datatypes.dtd:99:23: Attribute 'id' already
declared
http://www.w3.org/2001/datatypes.dtd:122:23: Attribute 'id' already
declared
http://www.w3.org/2001/datatypes.dtd:130:27: Attribute 'id' already
declared
....some 40 more lines like this and then Python crashes (Windows shows
the bug-reporting dialog)

Thanks for your interest,

AdSR

Jul 4 '06 #5
AdSR wrote:
uc*********@gma il.com wrote:
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.

I wanted to remove documentation elements from some XML Schema files.
The problem showed when I tried to use the stripped schemas, because
the namespace declaration for user-defined types was missing. Of
course, since these types are named and referred to in attribute
*values*, Amara had no way to know that the namespace declaration was
still needed (didn't matter if default or non-default). This is more a
problem of how XML Schema is defined against XML namespace rules, since
XML Schena uses namespaces in a context of which XML parsers aren't
normally aware.
Yeah. Just so you know. This is one of those things about XML that
make sane people want to dye their eyeballs red.

Unfortunately there isn't much recourse but to switch to namespace
qualified form for your QNames and adding dummy attributes so the
namespace is recognized. Let me know if you need an example.

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:

I know, especially the insert-before/after feature :) But I ran into a
problem that I describe below and you advertised 1.0 as "stable
version", so I switched immediately.

The problem can be reproduced like this:
>import amara
amara.parse('h ttp://www.w3.org/2001/XMLSchema.xsd')
START DTD xs:schema -//W3C//DTD XMLSCHEMA 200102//EN XMLSchema.dtd
http://www.w3.org/2001/datatypes.dtd:99:23: Attribute 'id' already
declared
http://www.w3.org/2001/datatypes.dtd:122:23: Attribute 'id' already
declared
http://www.w3.org/2001/datatypes.dtd:130:27: Attribute 'id' already
declared
...some 40 more lines like this and then Python crashes (Windows shows
the bug-reporting dialog)

I don't get a crash on my system (Ubuntu), but I do get a legitimate
error message because that DTD is broken. The W3C seems to like
disseminating broken DTDs. Just yesterday I was helping someone around
the infamous broken XHTML 1.1 DTDs.

I do want to know why you're gettign a crash rather than just the error
message. What version of Python is that? Any chance you can try with
current CVS Amara (you can use easy_install)? This part of the
discussion should perhaps move to the 4Suite mailing list. I only
check this NG once a week.

--
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/

Jul 7 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1910
by: Ralf Wahner | last post by:
Dear Masters of XML As I'm new to XML Schema I dare to ask a possibly recurring question: Given an element <elem> with two attributes @a and @b. The attributes are bound by the condition, that either both or none must be present, i.e. <elem a="val_a" b="val_b"/> or <elem/> is valid, whilst
3
1975
by: Tony Johansson | last post by:
Hello!! Assume we have one base class called Vehicle and two derived classes called Car and Bus. I would be able to call method getName on an object of class Car or Bus and return back the name that is set for this class. Asking getName on an object of class Vehicle is of no interest. Assume we have an attribute called name of type string. Now to my question do you think it's right to put the name attribute in each
0
1006
by: Jay | last post by:
Ok, i had this posted on the other thread "XML w/ Python" but it kinda got off topic from the title to ill start a new thread. My question is this... the import of amara works in ActivePython... PythonWin 2.3.5 (#62, Feb 9 2005, 16:17:08) on win32. Portions Copyright 1994-2004 Mark Hammond (mhammond@skippinet.com.au) - see 'Help/About PythonWin' for further copyright information. >>> import amara
3
1371
by: Doru-Catalin Togea | last post by:
Hi! I have ActiveState Python 2.4.1 on Win XP Pro, with Amara 1.1.6. I have a script which works fine. I am trying to run the same script on a Solaris machine, with Python 2.4.2 and Amara 1.1.6. It gives me this error: bash-2.03$ python generateXML.py Traceback (most recent call last):
0
932
by: Doru-Catalin Togea | last post by:
Hi! I am using Amara 1.1.6 in a project. I made an executable with py2exe but when I try to run it I am referred to the log file, which states: Traceback (most recent call last): File "makeTestSpec.py", line 281, in ? File "makeTestSpec.py", line 114, in __init__ File "makeTestSpec.py", line 125, in loadTests File "amara\__init__.pyc", line 50, in parse
2
1440
by: mirandacascade | last post by:
O/S WinXP Home Vsn of Python: 2.4 Wish to install Amara. Using amara-allinone-1.0.win32-py2.4.exe (2965KB) Forder structure before installation: c: python24
0
1059
by: Rustom Mody | last post by:
I tried to install amara according to the recommendations on this list. There were evidently compilation errors. The results are below Also the quick reference gives 404 not found errors Thanks $ sudo easy_install amara Searching for amara
2
3309
by: ismailc | last post by:
Hi, I would like to do the following. I have an href where onclick the focus is on the href: I got it to change focus to another object but i don't really want that. It must be as if the user clicked nothing. The href is what i use for my tooltip so it's only surppose to work onmouseover! This is the jscript: onClick="document.getElementById('__Submit').focus();"
0
1009
by: Enbe | last post by:
I am currently trying to output the results in Amara. Her is an example count = 0 for root, dir, files in os.walk(path): for s in files: count += 1 print s this will only output to a console. How do I output 's' to xml using amara. Thanks. I can also post what process I am making with trying to get it output with amara.
0
9699
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9562
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9119
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.