View Full Version : document.implementation.createDocument in Chrome&Safari

10-09-2008, 03:38 PM
As I expected, Chrome (which I believe is based very much on the WebKit project engine, same as Safari) is not able to return correctly an XML document as object on using the document.implementation.createDocument() method.

The only workaround I have found is to use an AJAX request based on the XMLHttpRequest object.

My question is:

Do you know other workaround to load XML documents as objects on Safari & Chrome as well as in the other browsers?

10-09-2008, 03:58 PM
Hey kor,
I am far far from being any kind of expert when it comes to Ajax and XML.
I have only utilized xmlHTTPRequests a few times (good stuff btw imo).

I dont know if this has any information that is relevant to this issue beings it looks like its kinda for IE (I think, reply's on the page talk about using it in other browser so who knows).
Dean Edwards wrote up this little blog about XML data islands.

Might this be of any interest?

10-09-2008, 04:13 PM
Something like this maybe?

var xmlObj = new DOMParser().parseFromString(xmlString, "text/xml");

Code is from the off the top of my head, think I got it right.

There is another way with createDocument, something like this

var xmlElem = document.createElement("xml");
xmlElem.innerHTML = xmlString;

var xmlObj = document.implementation.createDocument("temp", "", null);
for(var i=0; i<xmlElem.childNodes.length; i+=1) {
xmlObj.importNode(xmlElem.childNodes.item(i), true);

Again, wrote it here. Been awhile since I played with this.


10-09-2008, 05:07 PM
Thanks ubh and A1ien51 for the responses. Yes, A1ien51, those might be good alternative, as in fact Chrome & Safari create something with document.implementation.createDocument(), but I suspect they create strings, not objects.

I will test to see if a parser could solve that.

Thanks again!