It seems that the problem is that Safari does not support document.implementation.createDocument as a method for extracting and loading XML sources. You must use XMLHttpRequest to retrieve and parse AFAIK XML.
I tried a modified version of the code from the Apple tutorial that you linked, and it seems to work for me. This code is not the best in the world, and it misses a lot of processing errors, but this is the only evidence I had at hand.
Note. I highly recommend using the library. There are browser incompatibilities with XMLHttpRequests and XML syntax. It is worth the investment!
For the non-library version, I used a modified version of safari code to get XMLHttpRequest:
function getXHR(url,callback) { var req = false; // branch for native XMLHttpRequest object if(window.XMLHttpRequest && !(window.ActiveXObject)) { try { req = new XMLHttpRequest(); } catch(e) { req = false; } // branch for IE/Windows ActiveX version } else if(window.ActiveXObject) { try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { req = false; } } } if(req) { req.onreadystatechange = function() { callback( req ) }; req.open("GET", url, true); req.send(""); } }
Capturing XML from the result is not without its own entry:
function getXML( response ) { if( response.readyState==4 ) { //Get the xml document element for IE or firefox var xml; if ( response.responseXML ) { xml = new ActiveXObject("Microsoft.XMLDOM"); xml.async = false; xml.loadXML(response.responseText); } else { xml = response.responseXML; } return xml; } return null; }
Finally, use what you get:
function callback( response ) { var xmlDoc = getXML( response ); if( xmlDoc ) {
If you still have problems, there are a few things you can verify that are most likely to solve your problem.
- Have you set your content type to text / xml?
- Is your request actually sending to and from the server?
- When you warn / check responseText, do you see something that does not belong?
- Is your XML formatted correctly? Run it through the validator.
Good luck Greetings.
source share