Original Post
Hello
Ok I've tried to apply the advice about how to create..prototypes(I think thats what it's called) in Javascript thanks to Gamer Gamester's advice. Hopefully it follows the conventions of Javascript.
What should be changed so that it works & so thats its correct javascript coding? The code doesn't compile/work right now
I am attempting to create a Cross Browser XML parser. So I try to "subclass" the XMLDocument object, although I am unsure if that object even exists, I am trying to subclass the object (returned from XMLHttpRequest() object) when I call the function xmlHttp.responseXML;
One important thing is I want to stick to native Javascript & steer clear of EcmaScript 5 for now until I learn the native javascript ways to create prototypes & perform inheritence.
Ok I've tried to apply the advice about how to create..prototypes(I think thats what it's called) in Javascript thanks to Gamer Gamester's advice. Hopefully it follows the conventions of Javascript.
What should be changed so that it works & so thats its correct javascript coding? The code doesn't compile/work right now
I am attempting to create a Cross Browser XML parser. So I try to "subclass" the XMLDocument object, although I am unsure if that object even exists, I am trying to subclass the object (returned from XMLHttpRequest() object) when I call the function xmlHttp.responseXML;
One important thing is I want to stick to native Javascript & steer clear of EcmaScript 5 for now until I learn the native javascript ways to create prototypes & perform inheritence.
// I intend to use the XMLHandler object like so:
var xml = XMLHandler("myXMLFile.xml");
var slides = xml.getElementsByTageName("slide");
function XMLHandler( /*string*/ xmlFilePath )
{
this.getXMLFile = function()
{
return this.xmlFile;
}
this.xmlFile = xmlFilePath;
this.parseXMLFile( this.xmlFile );
}
XMLHandler.prototype = new XMLDocument(); // is this enough to make the object inherit from the XMLDocument
XMLHandler.prototype.constructor = XMLDocument; // make XMLHandler call the base class constructor when created
if ( window.XMLHttpRequest )
{
XMLHandler.prototype.parseXMLFile = function( xmlFilePath )
{
this.xmlFile = xmlFilePath;
var xmlHttp = new XMLHttpRequest();
xmlHttp.open("GET", this.xmlFile, false); //Open the file using the GET routine
xmlHttp.send(null); //Send request
this = xmlHttp.responseXML; //this object holds/is the document information now
}
}
else if ( window.ActiveXObject ) // if the current browser is an old version of IE
{
XMLHandler.prototype.parseXMLFile = function( xmlFilePath )
{
this.xmlFile = xmlFilePath;
var xmlHttp = new ActiveXObject("Microsoft.XMLDOM");
xmlHttp.async = "false"; // keep synchronous for now
this = xmlHttp.load( this.xmlFile );
}
}