Tag Archives: Javascript

JavaScript for read data from XML file

var XmlReq;
function CreateXMLReq()
{
try
{
XmlReq= new ActiveXObject(“Msxml2.XMLHTTP”);
}
catch(ExXML)
{
try
{
XmlReq= new ActiveXObject(“Microsoft.XMLHTTP”);
}
catch(ExActivex)
{
XmlReq= null;
}
}

if(!XmlReq && typeof XMLHttpRequest != “undefined”)
{
XmlReq = new XMLHttpRequest(); //Mozila Firefix Browser
}
}

function parseXML()
{
//load xml file
// code for IE
var urllink=”SaffronMenu.xml”;
CreateXMLReq();

if(XmlReq)
{
if (XmlReq.overrideMimeType)
XmlReq.overrideMimeType(‘text/xml’);

XmlReq.onreadystatechange=function () { if (XmlReq.readyState==4)
if(XmlReq.status==200)
{
getMenuData(“starters_menu”, “divStartersMenu”);
getMenuData(“chicken_delicacies_menu”, “divChickenDelicacies”);
getMenuData(“lamb_specialities_menu”,”divLambSpecialities”);
getMenuData(“duck_specialities_menu”, “divDuckSpecialities”);
getMenuData(“vegetable_main_course_menu”, “divVegetableMainCourse”);
getMenuData(“tandoori_khazana_menu”,”divTandooriKhazana”);
getMenuData(“seafood_specials_menu”, “divSeafoodSpecials”);
getMenuData(“all_time_favourites_menu”, “divAllTimeFavourites”);
getMenuData(“biriani_dishes_menu”,”divBirianiDishes”);
getMenuData(“vegetable_side_menu”, “divVegetableSide”);
getMenuData(“sundries_menu”, “divSundries”);
}
//else alert(“There was a problem during retrieving News.” );
}
XmlReq.open(“GET”,urllink,true);
XmlReq.send(null);
}
//else { alert(‘Your browser cannot handle our java script’); }
}

function getMenuData(tagName, divName)
{
var ItemNode,loopi,litdata;
var backImg;
ItemNode=XmlReq.responseXML.documentElement.getElementsByTagName(tagName);

loopi=0;
litdata = “”;
for(loopi=0;loopi {
if (ItemNode[loopi].getAttribute(“desc”) != null)
{
litdata =litdata+ “”
+ “” + ItemNode[loopi].getAttribute(“desc”)+ “”
+ “”;
}

if (ItemNode[loopi].getElementsByTagName(“item_name”)[0].firstChild == null)
continue;

litdata =litdata+ “”;

if (ItemNode[loopi].getElementsByTagName(“display_Dotted_Line”)[0].firstChild != null)
{
if (ItemNode[loopi].getElementsByTagName(“display_Dotted_Line”)[0].firstChild.data == 1)
backImg = “”;
else
backImg = “”;
}
else
backImg = “”;

litdata = litdata + backImg;

if (ItemNode[loopi].getElementsByTagName(“image_path”)[0].firstChild != null)
litdata = litdata + ” + ItemNode[loopi].getElementsByTagName(“image_path”)[0].firstChild.data
+ “‘)\” onmouseout=\”hideTip()\”>”
+ ItemNode[loopi].getElementsByTagName(“item_name”)[0].firstChild.data;
else
litdata = litdata + “”
+ ItemNode[loopi].getElementsByTagName(“item_name”)[0].firstChild.data;

litdata =litdata + ” ”

if (ItemNode[loopi].getElementsByTagName(“chilli_image_path”)[0].firstChild != null)
litdata =litdata + “[Photo] “;

litdata = litdata + “”;

// if (ItemNode[loopi].getElementsByTagName(“display_Dotted_Line”)[0].firstChild != null)
// {
// if (ItemNode[loopi].getElementsByTagName(“display_Dotted_Line”)[0].firstChild.data = “1”)
// litdata = litdata + ” class = \”dotimage\””;
// }

litdata = litdata + “” + backImg + “”;

if (ItemNode[loopi].getElementsByTagName(“price”)[0].firstChild != null)
litdata = litdata + ” £ ” + ItemNode[loopi].getElementsByTagName(“price”)[0].firstChild.data + “”;

if(ItemNode[loopi].getElementsByTagName(“description”)[0].firstChild != null)
{
litdata =litdata+ “”
+ “” + ItemNode[loopi].getElementsByTagName(“description”)[0].firstChild.data + “”
+ “”;
}

litdata = litdata + “”
}
litdata = litdata + “”;
if (ItemNode.length>0)
document.getElementById(divName).innerHTML = litdata;
else
document.getElementById(divName).innerHTML = “”;

document.getElementById(divName).innerHTML =litdata;
}

/*
function getMenuDataOld2(tagName, divName)
{
var ItemNode,loopi,litdata;
ItemNode=XmlReq.responseXML.documentElement.getElementsByTagName(tagName);

loopi=0;
litdata = “”;
for(loopi=0;loopi {
if (ItemNode[loopi].getElementsByTagName(“item_name”)[0].firstChild == null)
continue;

litdata =litdata+ “”;
if (ItemNode[loopi].getElementsByTagName(“image_path”)[0].firstChild != null)
litdata = litdata + ” + ItemNode[loopi].getElementsByTagName(“image_path”)[0].firstChild.data
+ “‘)\” onmouseout=\”hideTip()\”>”
+ ItemNode[loopi].getElementsByTagName(“item_name”)[0].firstChild.data + “”;
else
litdata = litdata + ItemNode[loopi].getElementsByTagName(“item_name”)[0].firstChild.data + ” “;

//litdata = litdata + “”;
if (ItemNode[loopi].getElementsByTagName(“chilli_image_path”)[0].firstChild != null)
litdata =litdata + “[Photo]”;
litdata = litdata + ” if (ItemNode[loopi].getElementsByTagName(“display_Dotted_Line”)[0].firstChild != null)
{
//if (ItemNode[loopi].getElementsByTagName(“display_Dotted_Line”)[0].firstChild.data = “1”)
// litdata = litdata + “[Photo]”;
if (ItemNode[loopi].getElementsByTagName(“display_Dotted_Line”)[0].firstChild.data = “1”)
litdata = litdata + ” class = \”dotimage\””;
}
litdata = litdata + “>”;
if (ItemNode[loopi].getElementsByTagName(“price”)[0].firstChild != null)
litdata = litdata + “£” + ItemNode[loopi].getElementsByTagName(“price”)[0].firstChild.data
+ “”;

if(ItemNode[loopi].getElementsByTagName(“description”)[0].firstChild != null)
{
litdata =litdata+ “”
+ “” + ItemNode[loopi].getElementsByTagName(“description”)[0].firstChild.data + “”
+ “”;
}
}
litdata = litdata + “”;
if (ItemNode.length>0)
document.getElementById(divName).innerHTML = litdata;
else
document.getElementById(divName).innerHTML = “”;

document.getElementById(divName).innerHTML =litdata;
}

function getMenuData()
{
var ItemNode,loopi,litdata;
ItemNode=XmlReq.responseXML.documentElement.getElementsByTagName(“starters_menu”);

loopi=0;
litdata = “”;
for(loopi=0;loopi {
litdata =litdata+ “”
+ “” + ItemNode[loopi].getElementsByTagName(“item_name”)[0].firstChild.data + “”
+ “” + ItemNode[loopi].getElementsByTagName(“no_of_chilli_image”)[0].firstChild.data + “”
+ “” + ItemNode[loopi].getElementsByTagName(“display_Dotted_Line”)[0].firstChild.data + “”
+ “” + ItemNode[loopi].getElementsByTagName(“price”)[0].firstChild.data + “”
+ “”;
if(ItemNode[loopi].getElementsByTagName(“description”)[0].firstChild.data != “”)
{
litdata =litdata+ “”
+ “” + ItemNode[loopi].getElementsByTagName(“description”)[0].firstChild.data + “”
+ “”;
}
}
litdata = litdata + “”;
if (ItemNode.length>0)
document.getElementById(“divStartersMenu”).innerHTML = litdata;
else
document.getElementById(“divStartersMenu”).innerHTML = “”;

document.getElementById(“divStartersMenu”).innerHTML =litdata;
} */