OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Namespace declaration using DOM

[ Lists Home | Date Index | Thread Index ]

> Christian Nentwich wrote:
> > 
> >><RootElement xmlns:c="http://pradeepbhat.com";>
> >><c:name>pradeep</c:name>
> >><RootElement>
> >>My problem is how to put the xml name space declaration in RootElement.
> >>Some one plz help;
> > 
> > 
> > root.setAttribute("xmlns:c","http://pradeepbhat.com";);
> > 
> 
> I don't think this is correct.

Yes it is.  You'll want to read

http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113/core.html#Namespaces-Considerations

to see why.

I would have actually suggested

setAttributeNS("http://www.w3.org/2000/xmlns/";, "xmlns:c", "http://pradeepbhat.com";)

Since it's dangerous to mix DOM level 1 interfaces with namespace processing.  But Christian's basic idea is right.

> Namespaces are *not* attributes.

You mean "namespace declarations", right?  Well, in DOM they are attributes.  From the section I posted above:

"As far as the DOM is concerned, special attributes used for declaring XML namespaces are still exposed and can be manipulated just like any other attribute."

Of course, the element so update will not have a namespaceURI atribute set to "http://pradeepbhat.com"; after this operation, unless the impl does some non-standard fix-ups, but most DOM/NS code has no choice but to check both attribute nodes and the namespaceURI/prefix/localname attributes in general processing.  Yes this is a very ugly situation, but that's just the way it is right now.

> You'll have to create the c:name element using
>    createElementNS("http://pradeepbhat.com","c:name";);

This does something quite different from what the original poster wanted.


-- 
Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
Track chair, XML/Web Services One (San Jose, Boston): http://www.xmlconference.com/
DAML Reference - http://www.xml.com/pub/a/2002/05/01/damlref.html
The Languages of the Semantic Web - http://www.newarchitectmag.com/documents/s=2453/new1020218556549/index.html
XML, The Model Driven Architecture, and RDF @ XML Europe - http://www.xmleurope.com/2002/kttrack.asp#themodel






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS