Forum Moderators: open
var isIE = false;
if (window.ActiveXObject){
isIE = true;
}
function GetText(node){
if(isIE){
return node.text;
}else{
return node.textContent;
}
}
function GetByTagName(node, name){
var childArray = new Array();
for(var i=0; i<node.childNodes.length; i++){
if(node.childNodes[i].nodeName == name){
childArray[childArray.length] = node.childNodes[i];
}
}
return childArray;
}
var xmlDocVersions = new Array("Msxml2.DOMDocument.5.0", "Msxml2.DOMDocument.4.0", "Msxml2.DOMDocument.3.0", "Msxml2.DOMDocument", "Microsoft.DOMDocument");
function push_GetXmlDoc(xml, index){
var xmlDoc=null;
if (window.ActiveXObject && index < xmlHttpVersions.length){
try{
xmlDoc = new ActiveXObject(xmlDocVersions[index]);
Debug("XML Doc Version: "+xmlDocVersions[index]+"<br>");
xmlDoc.async="false";
xmlDoc.loadXML(xml);
}catch(e){
push_GetXmlDoc(xml, index+1);
}
}
if (document.implementation.createDocument){
var parser = new DOMParser();
xmlDoc = parser.parseFromString(xml, "text/xml");
}
if(xmlDoc == null) alert("XML Doc Load Failed");
return xmlDoc;
}
xmlDoc = GetXmlDoc(XMLSTRINGVARIABLE, 0).documentElement;
var tags = GetByTagName(xmlDoc, TAGNAMEASSTRING);
for(var t in tags){
alert(GetText(tags));
}
And last but not least! I use this code to get XML data with javascript and then affect the DOM. I'm hoping to use XSL in future coding, I believe it is an acceptable replacement(and a lot nicer), but need to learn it first.