[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Namespace declaration using DOM


namespace declaration attribute
> 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



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.