[XML-SIG] namespace headache

Ludvig Svenonius ludvig.svenonius@excosoft.se
Tue, 2 May 2000 16:52:03 +0200


I'm pretty sure an unprefixed attribute will default to the same namespace
URI as its host element, so in the snippet:

<ns:body xmlns:ns='namespace:'>
    <ns:member attribute='value'>
    </ns:member>
</ns:body>

'attribute' would have the namespace URI 'namespace:', as its host element,
whereas in:

<body>
    <member attribute='value'>
    </member>
</body>

it would have no namespace URI. I think I read about this somewhere in the
namespace specification at W3C. This also explains why XSL-specific
attributes in XSLT elements needn't be prefixed (they will conveniently
default to the same namespaces as their host elements, i.e. the XSLT
namespace). The same goes for XHTML, I guess. I think xmllib has it right. I
have no explanation for James Clark's note however. The alternative of
forcing the XML author to explicitly prefix every attribute in elements that
belong to a certain namespace just to declare that they belong to the same
namespace seems pretty inconvenient.

--
Ludvig Svenonius
Excosoft AB
ludvig@excosoft.se

-----Original Message-----
From: xml-sig-admin@python.org [mailto:xml-sig-admin@python.org]On
Behalf Of Fredrik Lundh
Sent: Tuesday, May 02, 2000 4:19 PM
To: xml-sig@python.org
Subject: [XML-SIG] namespace headache


reading the XML namespace specification makes my brain
hurt, so I thought I'd ask here before it explodes...

given the following XML snippet, what's the correct namespace
for the "attribute" attribute?

<ns:body xmlns:ns='namespace:'>
    <ns:member attribute='value'>
    </ns:member>
</ns:body>

I'm not smart enough to figure that out from the specification,
my intuition says "no namespace", and so does James Clark's
namespace note (http://www.jclark.com/xml/xmlns.htm) where

<RESERVATION xmlns:HTML="http://www.w3.org/TR/REC-html40">
   <HTML:A HREF='/cgi-bin/ResStatus'>Check Status</HTML:A>
</RESERVATION>

is mapped to:

<RESERVATION>
   <{http://www.w3.org/TR/REC-html40}A HREF='/cgi-bin/ResStatus'
     >Check Status</{http://www.w3.org/TR/REC-html40}A>
</RESERVATION>

(slightly edited -- see the note for the full example).

but 1.5.2's xmllib doesn't agree with this:

import xmllib

class Parser(xmllib.XMLParser):
    def unknown_starttag(self, tag, attr):
        print "S", repr(tag), attr
    def unknown_endtag(self, tag):
        print "E", repr(tag)

p = Parser()
p.feed("""
<ns:body xmlns:ns='namespace:'>
    <ns:member attribute='value'>
    </ns:member>
</ns:body>
""")
p.close()

gives the following output:

S 'namespace: body' {}
S 'namespace: member' {'namespace: attribute': 'value'}
E 'namespace: member'
E 'namespace: body'

instead of

S 'namespace: body' {}
S 'namespace: member' {'attribute': 'value'}
E 'namespace: member'
E 'namespace: body'

can anyone sort this out for me?

(and no, I really have to be able to use xmllib, to make sure
soaplib.py works under an off-the-shelf Python distribution...)

</F>


_______________________________________________
XML-SIG maillist  -  XML-SIG@python.org
http://www.python.org/mailman/listinfo/xml-sig