Re: xmlns attribute in new node

Martin Honnen <[email protected]> Sun, 16 Nov 2008 13:55:26 +0100
Newsgroups gmane.comp.mozilla.devel.xml
Organization Liberty Development
Message-ID <[email protected]>
NONE wrote:

> i m working ona firefow extension that use xml documents but i have a 
> little trouble when i create a new node. All the new nodes created with 
> createElement from a DOMParser have an empty xmlns="" . I can not remove 
> this one or prevent this one from beeing added to the new node.
> Does someone have a solution or an explanation ?

Use the namespace aware DOM Level 2 methods like createElementNS e.g. to 
create
<root xmlns="http://example.com/2008/ns1"><foo><bar>baz</bar></foo></root>
with the DOM you need e.g.

const ns1 = 'http://example.com/2008/ns1';
var doc = document.implementation.createDocument(ns1, 'root', null);
var foo = doc.createElementNS(ns1, 'foo');
var bar = doc.createElementNS(ns1, 'bar');
bar.textContent = 'baz';
foo.appendChild(bar);
doc.documentElement.appendChild(foo);


-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/