[XML-SIG] more on DOM and namespaces
Uche Ogbuji
uche.ogbuji@fourthought.com
Sat, 20 Jul 2002 18:08:04 -0600
> Hello again,
> =
> I have another DOM and Namespaces questions. =
> =
> Is it necessary to add the xmlns attribute to an element which is
> created with createElementNS ?
> =
> This is what I get with 4DOM:
> >>> from xml.dom.ext.reader.Sax2 import Reader
> >>> d =3D Reader().fromString("<a:doc xmlns:a=3D'foo'/>")
> >>> e =3D d.createElementNS("bar","b:elt")
> >>> d.documentElement.appendChild(e)
> <Element Node at 8270dec: Name=3D'b:elt' with 0 attributes and 0 childr=
en>
> >>> d.documentElement.attributes
> <NamedNodeMap at 82a796c: {('http://www.w3.org/2000/xmlns/', u'a'):
> <Attribute Node at 82a7d0c: Name=3D"xmlns:a", Value=3D"foo">}>
> >>> e.attributes
> <NamedNodeMap at 829e604: {}>
> >>> from xml.dom.ext import PrettyPrint
> >>> PrettyPrint(d)
> <?xml version=3D'1.0' encoding=3D'UTF-8'?>
> <!DOCTYPE a:doc>
> <a:doc xmlns:a=3D'foo' xmlns:b=3D'bar'>
> <b:elt/>
> </a:doc>
> =
> So it looks like I don't need to explicitely setAttributeNS for
> namespace attributes, at least with 4DOM, but reading the DOML2 spec
> =A71.1.8 didn't help me telling if theis was just a nice property of 4D=
OM
> or a DOM requirement. =
It's a DOM L2 requirment. A node can have a namespaceURI property withou=
t =
having a corresponding nsdecl cttribute.
-- =
Uche Ogbuji Fourthought, Inc.
http://uche.ogbuji.net http://4Suite.org http://fourthought.com
Track chair, XML/Web Services One Boston: http://www.xmlconference.com/
The many heads of XML modeling - http://adtmag.com/article.asp?id=3D6393
Will XML live up to its promise? - http://www-106.ibm.com/developerworks/=
xml/library/x-think11.html