Discussion:
Adding a namespace to a Dom document
Marina Dorelli
2010-05-25 10:41:02 UTC
Permalink
I'd like to add a XML namespace with the URI of my own ontology in the DOM
document of an existing web page.
Is it possible to add a namespace element?

Thanks in advance
Boris Zbarsky
2010-05-25 12:13:28 UTC
Permalink
Post by Marina Dorelli
I'd like to add a XML namespace with the URI of my own ontology in the DOM
document of an existing web page.
Is it possible to add a namespace element?
There are no "namespace elements" in the DOM.

You can add attributes in a given namespace, obviously, and you can add
nodes in a given namespace...

That said, what are you actually trying to do? Can you give an example?

-Boris
Boris Zbarsky
2010-05-25 19:59:04 UTC
Permalink
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
Marina Dorelli
2010-05-25 22:16:46 UTC
Permalink
I used:
wbp.saveDocument(content.document,localFile,null,"text/xml",null,null);
Is it wrong?
Post by Boris Zbarsky
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
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
_______________________________________________
dev-tech-dom mailing list
https://lists.mozilla.org/listinfo/dev-tech-dom
Boris Zbarsky
2010-05-26 02:46:25 UTC
Permalink
Post by Marina Dorelli
wbp.saveDocument(content.document,localFile,null,"text/xml",null,null);
Is it wrong?
That should work, assuming you changed nodes of content.document.

-Boris
Marina Dorelli
2010-05-27 11:59:50 UTC
Permalink
You' re right now it works properly.
Thank you very much
Post by Boris Zbarsky
Post by Marina Dorelli
wbp.saveDocument(content.document,localFile,null,"text/xml",null,null);
Is it wrong?
That should work, assuming you changed nodes of content.document.
-Boris
_______________________________________________
dev-tech-dom mailing list
https://lists.mozilla.org/listinfo/dev-tech-dom
Marina Dorelli
2010-05-25 19:36:15 UTC
Permalink
I'm sorry I was in a hurry, and I took the wrong address...

well I tried to use createAttributeNS and then root.appendChild()

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
Not sure why you didn't reply on the list...
<htmlxmlns="http://www.w3.org/1999/xhtml"
xmlns:dc="http://purl.org/dc/elements/1.1/"
version="XHTML+RDFa 1.0" xml:lang="en">
OK, so you can do this using setAttributeNS, no?
-Boris
Loading...