Re: Adding a namespace to a Dom document

Boris Zbarsky <[email protected]> Tue, 25 May 2010 15:59:04 -0400
Newsgroups gmane.comp.mozilla.devel.dom
Message-ID <[email protected]>
On 5/25/10 3:36 PM, Marina Dorelli wrote:
> so I should use root.setAttributeNS("http://www.w3.org/2000/xmlns/",
> "xmlns:foo",
> "http://foo.org#"); , no?
>
> I've tried this way but it doesn't work, I saved my document and i can't
> find the attribute I set

How did you save it?  This works fine over here:

   var doc = document.implementation.createDocument(null, null, null);
   var elm = doc.createElement("root");
   doc.appendChild(elm);
   elm.setAttributeNS("http://www.w3.org/2000/xmlns/",
                      "xmlns:foo","http://foo.org#");
   var str = (new XMLSerializer()).serializeToString(doc);
   alert(str);

-Boris