load() support in document.implementation.createDocument

David Joham djoham at yahoo.com
Wed Mar 19 07:15:58 GMT 2003


Hello all,

I'm looking at the different options available for taking advantage of modern browser's built-in
XML DOM Parsers with the goal of being able to natively manipuate XML via JavaScript without
having to jump through many hoops.

So far, I've found that IE has the MSXML ActiveX control that you can load and use as your XML
parser. Mozilla supports creating an xmlDOM object by using
document.implementation.createDocument. Amazingly enough, both of these implementations allow you
to populate the XML DOM object by calling a load() method on the object. Even more amazing, they
both seem to support the standard DOM methods and properties so aside from how the XML DOM object
is created, code for one browser will work in the other.

I'm curious what my options are for Konqueror. Konq seems to support
document.implemenation.createDocument, but it doesn't seem to support any kind of method that
would allow this object to get populated from a file (either locally or on the web). 

>From what I've read, the load() method that Mozilla implements is an extension and not actually
part of any W3C specification. However, it's a very useful extension.

I've put together a quick sample page that demonstrates the basics of what I'm trying to
accomplish. Basically, it creates an XML DOM object, sets it's onload method and then calls load
to actually populate the XML object. I've added some code to the page that iterates through the
XML DOM object and displays its capabilities. This display is useful for comparing what Mozilla
has available vs what Konq has. For the most part, it looks as though the objects are very
comparible, with the exception of load(). 

When this page is loaded in Mozilla, you'll get an alert that says "hi". Konqueror dies when I ask
the object to perform the load() method.

In the end, I would like to be able to get a page like http://www.xs4all.nl/~ppk/js/importxml.html
working in Konqueror. In Mozilla, click the link named "link" in the paragraph that starts with
"Anyway, try..." to see the behavior that I'm shooting for.

Are there any plans to implement an XML DOM object load() method in Konqueror similar to what
Mozilla has? Am I missing anything now that will allow me to do this?

Thanks for any feedback.

Best regards,

David

code:


<html>
	<body>
		<form>
			<input type="button" onclick="importXML()" value="go"><br>
			<select id="list" size="2" style="width: 300px; height: 500px"></select>
		</form>
	</body>
</html>

<script type="text/javascript">

function importXML()
{
        
	var xmlDoc;
	if (document.implementation && document.implementation.createDocument)
        {
                xmlDoc = document.implementation.createDocument("", "", null);
		try {
                	xmlDoc.onload = sayhi;
		}
		catch (e) {
			alert("death setting onload\n" + e);
		}
        }
	for (var e in xmlDoc) {
		var x = new Option(e);
		document.getElementById("list").add(x, null);
	}
	try {       
		//this can be any file on the same domain.
		xmlDoc.load("xml.xml");
	}
	catch(e) {
		alert("death calling load\n" + e);
	}

	alert("the list has " + document.getElementById("list").length + "items");

}

function sayhi() {
	alert("hi");
}

</script>


__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com




More information about the kfm-devel mailing list