If you create an element with createElement(), when you call getNamespaceURI() on that element it will return a null string. So even if you get the same output when you serialize the DOM, it doesn't mean the element is identical to an element created with createElementNS(). Some differences in the elements are not representable in serialized output.
The "advantage" to using createElementNS() is that any namespace-aware applications that need to use your DOM will actually get a DOM with namespaces, not just elements and attribute that have names with ":" in them. The prefixes are syntactic sugar, while the namespace URI values are not. If all you're doing is creating a DOM, then immediately serializing it, the difference may not be obvious. But since you said you needed to create a "namespace-aware" DOM, then you _have_ to use createElementNS() and createAttributeNS(). Dave "Keyur Dalal" <[EMAIL PROTECTED] To: <[EMAIL PROTECTED]> > cc: (bcc: David N Bertoni/Cambridge/IBM) Subject: Re: xerces DOM API: to NS or not to NS? 02/21/2002 09:51 AM Please respond to xerces-c-dev It seems that both sets of API can lead to *exactly* the same output when the DOM was converted back into XML. I was only wondering if the NS API offered any advantages in a situation where XML was being generated and not parsed or validated... especially since creating a NS element would not necessarily create the appropriate xmlns attribute. e.g. createElementNS( "DAV:", "D:prop" ) would still require that setAttributeNS( "http://www.w3.org/2000/xmlns/", "xmlns:D="DAV:") be called. And now I have the overhead of correct naming the namespace for my attribute without which the API would not work.( In my generated XML, I do not care about the default namespace for 'xmlns' attributes ). The non-NS API allow me to simplify my code, by merely adding the the appropriate attribute and not worrying about the default value being right... Which is why I asked the questions - any benefits of using the NS methods... Regards, Keyur ----- Original Message ----- From: "David N Bertoni/Cambridge/IBM" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, February 21, 2002 12:10 PM Subject: Re: xerces DOM API: to NS or not to NS? > > If you want to create a document with the correct namespaces, you must use > createElementNS and createAttributeNS. Isn't that obvious from their names > and the DOM recommendation? > > Dave > > > > > "Keyur Dalal" > <[EMAIL PROTECTED] To: <[EMAIL PROTECTED]> > > cc: (bcc: David N Bertoni/Cambridge/IBM) > Subject: xerces DOM API: to NS or not to NS? > 02/21/2002 07:57 > AM > Please respond > to xerces-c-dev > > > > > > I need to create the following namespace aware XML document: > > <D:propstat xmlns:D="DAV:"> > <D:prop xmlns:R="http://foo.bar/ns"> > <D:getcontentlanguage>enUS</D:getcontentlanguage> > <R:lockedby>someuser</R:lockedby> > </D:prop> > </D:propstat> > > If I use the DOM API to generate element nodes and append > attributes, what advantages are there in using createElementNS > and createAttributeNS over createElement and createAttribute? > > Regards, > > Keyur > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]