Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

UncleRic

macrumors newbie
Original poster
Greetings:

Safari fires off an exception when attempting to create a DOM:


// code for IE
if (window.ActiveXObject) {
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument) {
xmlDoc=document.implementation.createDocument("","",null);
} else {
alert('Your browser cannot handle this script');
}


The exception raised on:

document.implementation.createDocument()

Thusly:
TypeError: Value undefined (result of expression xmlDoc.load) is not object.


So even though the script thinks the browser is W3C compliant (passing the
'document.implementation.createDocument()') criteria, it fails.

1) Doesn't anyone know a solution/remedy for this?
2) How do I create a DOM doc in Safari?

-- Ric.
 
Safari lacks Mozilla's support for W3C DOM creation

Try
Code:
xmlDoc=document.implementation.createDocument("","SomeRootTagName",null);
or
Code:
xmlDoc=document.implementation.createDocument("",null,null);

I've read documentation of document.implementation.createDocument() that Mozilla browsers follow; but Safari does NOT. I've tried various syntaxes including what you had suggested, but they don't work.

I can get Safari to parse a XML doc. But I CAN'T get it to CREATE ONE. Nobody seems to know a solution to this; hence I assume Safari isn't ready for prime-time XML processing.

That is, using JavaScript within Safari to create/load a XML document.
BTW: Having E4X support is apparently, a secondary priority for Safari.

Bummer.

Ric.
 
I've read documentation of document.implementation.createDocument() that Mozilla browsers follow; but Safari does NOT. I've tried various syntaxes including what you had suggested, but they don't work.

I can get Safari to parse a XML doc. But I CAN'T get it to CREATE ONE. Nobody seems to know a solution to this; hence I assume Safari isn't ready for prime-time XML processing.

That is, using JavaScript within Safari to create/load a XML document.
BTW: Having E4X support is apparently, a secondary priority for Safari.

Bummer.

Ric.

Hey we have a problem reading a xml with javascript in safari would you mind looking at this code and see what we are doing wrong? Thanks.

Code:
try{//try IE first
		xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
	
	}
	catch(e){
		try{//try Mozilla, Firefox, Opera, etc.
			xmlDoc=document.implementation.createDocument("",null,null);
	
		}
	  	catch(e){
			alert(e.message);
			return;
		}
	}
	
	xmlDoc.async=false;
	  xmlDoc.load("http://url/testFeed.xml");

We're getting this error:

Code:
Value undefined (result of expression xmlDoc.load) is not object

TIA, Mark
 
...
We're getting this error:

Code:
Value undefined (result of expression xmlDoc.load) is not object

TIA, Mark

Is xmlDoc define outside the try block? If not, that's a problem because it's out of scope when you are trying your load.
 
Simple Solution to get an XML Doc Object across Browsers

  1. Include prototype.js in your page.
  2. Assuming you have an XML file to be parsed at this relative path, "mypath/myfile.xml", it can have real contents to be parsed or an empty XML document with proper content-type header (thus you will be able to create an empty DOM object later).
  3. Use the following javascript:
    Code:
        var xmlDoc;
        var xmlURL = "mypath/myfile.xml";
        new Ajax.Request(xmlURL, {
            method: "get",
            asynchronous: false,
            onSuccess: function(resp, jsonObj) {
                xmlDoc = resp.responseXML;
            }
        });
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.