Click to See Complete Forum and Search --> : need help with loading XML data using javascript


buzibuzi
10-02-2009, 07:17 AM
Hi, i need to traverse this xml file (data.xml) for both FF and IE using javascript


<?xml version="1.0"?>
<ArrayOfMenu>
<menu name="רוקח ברישום">
<menu name="לרשום תרופה חדשה">
<item name="לשרת התשלומים של אגף הרוקחות" action="gotoURL" variables="http://ecom.gov.il/Counter/general/Homepage.aspx?counter=21"/>
</menu>
<menu name="לקבל אישור לאצווה ראשונה לתכשיר חדש">
<item name="טופס בקשה לאישור שיווק אצווה ראשונה של תכשיר רפואי" action="gotoURL" variables="http://www.psi.org.il/ToolBox/Docs/1st_batch.rtf"/>
</menu>
<menu name="לחדש רישום של תרופה">
<item name="טופס בקשה לתעודת איכות - המכון לביקורת ולתקינה" action="gotoURL" variables="http://www.psi.org.il/ToolBox/Docs/MachonCert.doc"/>
<item name="נספח 1 - בטיחות TSE" action="gotoURL" variables="http://www.psi.org.il/ToolBox/Docs/TSE.doc"/>
</menu>
<menu name="לקבל אישור לשינוי בתכשיר רשום">
<item name="טופס בקשה לשינוי ברישום תכשיר רפואי מהיבט האיכות" action="gotoURL" variables="http://www.psi.org.il/ToolBox/Docs/Change_Machon.doc"/>
</menu>
<item name="google" action="gotoURL" variables="http://www.google.com"/>
</menu>
</ArrayOfMenu>





so far i have this code, but i can't seem to manage to go beyond this point



//Firefox only function - happens when a XML file is loaded
function loadHandler () {
xmlProcessor(this); //Call the Commen function with 'this' data.
}

//Load the xml file - using different method for different browsers
function xmlLoad(xml_file) {
//Initializations
feed_id = 0;
feed_total = 0;

var xmlDocument = "";
feed_file = xml_file;
if(document.implementation.createDocument) {//Firefox
xmlDocument = document.implementation.createDocument('', '', null);
xmlDocument.load(xml_file);
//This function will happen when the file is loaded
xmlDocument.addEventListener('load', loadHandler, false);
//xmlProcessor(xmlDocument); // i need help with this function to recurse through the tree structure

}
else { //IE
var xmlDocument = new ActiveXObject('Microsoft.XMLDOM');
xmlDocument.async = false;
var loadResult = xmlDocument.load(xml_file);
if (loadResult) {
// process xml document with DOM methods e.g.
// xmlProcessor(xmlDocument)
} else {
xmlError();
return false;
}
}
return true;
}

function xmlError() {
alert("Some error has occurred!")
}

//Process the xml data
function xmlProcessor(xmlDoc) {
if(!xmlDoc) {
feedError();
}


xmlLoad("data.xml"); // Load the XML file.




thanks
Buzi

Hack
10-07-2009, 07:40 AM
What problems are you having? Are you getting errors?

buzibuzi
10-21-2009, 04:49 AM
i decided to use a different method
thanks anyway