I have a site where I retrive information (articles submitted by the current user) and allow the user to edit them. The article information is in XML format. The code works in FF, but only gives me nulls in IE (like the elements don’t exist, but since it works in FF I know the document I am refering to is correct URL (yes, I do show the URL that am retrieving data from.)
(sorry for posting a large snitbit)
var _AC_tmp_XMLDoc;
function XMLParser(doc, fcn, fcn2){
_AC_tmp_XMLDoc = “”;
if (document.implementation && document.implementation.createDocument){
_AC_tmp_XMLDoc = document.implementation.createDocument(“”, “”, null);
_AC_tmp_XMLDoc.onload = fcn;
}
else if (window.ActiveXObject)
{
_AC_tmp_XMLDoc = new ActiveXObject(“Microsoft.XMLDOM”);
_AC_tmp_XMLDoc.onreadystatechange = fcn2;
}
else
{
alert(‘Your browser can’t handle this script’);
return;
}
_AC_tmp_XMLDoc.load(doc);
this.getTextArrayForTag = function(tag){
var arry = new Array();
var x = xmlDoc.getElementsByTagName(tag);
var tmplnt = x.length;
for(var i = 0; i < tmplnt; i++){
this.getElementTextNS(tag, i);
}
return arry;
}
this.toString = function(){
return “XMLParser:JK:2”
}
this.getReadyState = function(){
return _AC_tmp_XMLDoc.readyState;
}
this.getElementsByTagName = function(tag){
prefix = “”;
var result = “”;
if (prefix && isIE) {
// IE/Windows way of handling namespaces
result = _AC_tmp_XMLDoc.getElementsByTagName(prefix + “:” + tag);
} else {
// the namespace versions of this method
// (getElementsByTagNameNS()) operate
// differently in Safari and Mozilla, but both
// return value with just local name, provided
// there aren’t conflicts with non-namespace element
// names
result =
}
//alert(result);
return result;
}
// retrieve text of an XML document element, including
// elements using namespaces
this.getElementTextNS = function (local, index) {
var result = this.getElementsByTagName(local)[index];
if (result) {
// get text, accounting for possible
// whitespace (carriage return) text nodes
if (result.childNodes.length > 1) {
return result.childNodes[1].nodeValue;
} else {
return result.firstChild.nodeValue;
}
} else {
return “n/a”;
}
}
}
Another problem. I have to have the variable _AC_tmp_XMLDoc global because I need to reference its readyState bc IE has no onload rutiune (that I am aware of). I would love to have it encapsulated inside my Object, but cannot do this as of now. It seems that if an object creates an event, the object cannot be referenced by the function it calls to handle the event (I’ve seen this in multible places).
Any help would be gladly appriciated.
BTW: the doc is good XML.