View Full Version : Javascript Xml Load problem in Safari.

12-18-2006, 09:39 PM
I stated this problem incorrectly earlier and am revising it now.
I having a problem loading data from an xml document into the Safari browser for the mac. The code works fine with firefox and IE.

The problem occurs in the following block of code:

else if (document.implementation && document.implementation.createDocument){
xmlDoc = document.implementation.createDocument("","", null);

I'm not exactly sure what the issue is, but it seems that the line xmlDoc = document.implementation.createDocument("","", null); craetes a Document Object in Safari rather an XMLDocument object as in Firefox. Consequently the script dies on the line xmlDoc.load(xmlFile); and I think the xml file is never loaded.

Any ideas.

12-19-2006, 12:39 PM
Sadly, Safari DOM support is a bit of a blind spot for me, as I haven't really played around with that browser except for confirming that things work in it.

Does Safari support the load method on DOMDocument at all? This method was part of one of the early DOM3LS Working Drafts (http://www.w3.org/TR/2003/WD-DOM-Level-3-LS-20030619/load-save.html#LS-DocumentLS), but it did not make it into the DOM2LS Recommendation (http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/).

Maybe you should try using XMLHttpRequest instead. Just a thought.

Tarquin's support table in this article (http://www.howtocreate.co.uk/tutorials/jsexamples/importingXML.html) suggest neither Opera nor Safari supports the load method on DOMDocument objects. which is entirely okay by me, since those browsers support XMLHttpRequest.

I also know Opera states support for DOM3LS, which means you can try using document.implementation. createLSParser and then use the LSParser (http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/load-save.html#LS-LSParser) interface in that browser.

I do not think Safari supports that interface, however, so XMLHttpRequest is probably your best bet.