rnd me
12-14-2007, 02:14 AM
i am using the following E4X code to search directories on a server.
the problem is that only firefox supports E4X at the moment.
E4X uses a special operator: ".." to find descendants of nodes without regard to their parent.
trouble is, that ".." raises a syntax error in other browsers, not be a valid statement as far as they are concered.
i would like to keep the E4X code in the same file as other functions, my main module, used by all browsers.
i have it coded as below, and this works ok i guess:
function harvestE4X(ina){ //e4x version
qaa={};
eval( " qaa = { name:ina..displayname.toString(), \
path: ina..href.toString(), \
size: (ina..getcontentlength.toString().toInt() || 0), \
date: (parseDate(ina..getlastmodified.toString())) } ")//end eval hide
return qaa;
}//end e4x harvest
function harvestDOM(ina){ //DOM version
var tname=(obValsl( a.getElementsByTagName("displayname"))[0][TEXT].toString() || "untitled" );
var tpath=(obValsl( a.getElementsByTagName("href"))[0][TEXT].toString() || "nopath" );
var tsize=(obValsl( a.getElementsByTagName("getcontentlength"))[0][TEXT].toString() || 0 );
var tdate=(obValsl( a.getElementsByTagName("getlastmodified"))[0][TEXT].toString() || now() );
var qaa={ name: tname,
path: tpath,
size: tsize,
date: tdate }
return qaa;
}//end harvest DOM
if (!! window.XML ){ harvest=harvestE4X } else { harvest=harvestDOM }
question:
Is there anyway around having to eval the firefox code to hide it from other browsers? (i don't like to use eval)
the problem is that only firefox supports E4X at the moment.
E4X uses a special operator: ".." to find descendants of nodes without regard to their parent.
trouble is, that ".." raises a syntax error in other browsers, not be a valid statement as far as they are concered.
i would like to keep the E4X code in the same file as other functions, my main module, used by all browsers.
i have it coded as below, and this works ok i guess:
function harvestE4X(ina){ //e4x version
qaa={};
eval( " qaa = { name:ina..displayname.toString(), \
path: ina..href.toString(), \
size: (ina..getcontentlength.toString().toInt() || 0), \
date: (parseDate(ina..getlastmodified.toString())) } ")//end eval hide
return qaa;
}//end e4x harvest
function harvestDOM(ina){ //DOM version
var tname=(obValsl( a.getElementsByTagName("displayname"))[0][TEXT].toString() || "untitled" );
var tpath=(obValsl( a.getElementsByTagName("href"))[0][TEXT].toString() || "nopath" );
var tsize=(obValsl( a.getElementsByTagName("getcontentlength"))[0][TEXT].toString() || 0 );
var tdate=(obValsl( a.getElementsByTagName("getlastmodified"))[0][TEXT].toString() || now() );
var qaa={ name: tname,
path: tpath,
size: tsize,
date: tdate }
return qaa;
}//end harvest DOM
if (!! window.XML ){ harvest=harvestE4X } else { harvest=harvestDOM }
question:
Is there anyway around having to eval the firefox code to hide it from other browsers? (i don't like to use eval)