LoadXML

Posted @ 4:28 PM on October 11, 2006 by Denis

I also can use the method LoadXML in JavaScript to keep the sidebar consistent, see below, But I haven’t test it . To me, I prefer the Ajax method.


var xmlDoc;

function loadXML(){
//load xml file
// code for IE
if (window.ActiveXObject)
{
xmlDoc=new ActiveXObject(”Microsoft.XMLDOM”);
xmlDoc.async=false;
xmlDoc.load(”NAV.XML”);
}
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc=document.implementation.createDocument(”",”",null);
xmlDoc.load(”NAV.XML”);
}
else
{
alert(’Your browser cannot handle this script’);
}
}

function getNav(){
loadXML();

var out = “”;

var items = xmlDoc.getElementsByTagName(”item”);

var currentItem = “”;

for (var i=0; i currentItem = items[i];

var itemTitle = currentItem.getElementsByTagName("title")[0].childNodes[0].nodeValue;
var itemLink = currentItem.getElementsByTagName("Link")[0].childNodes[0].nodeValue;

out += "

” + itemTitle + “

“;
}

document.getElementById(”NAV”) = out;

}

window.onload = function (){
getNav();
}

The NAV.XML file will be:




When you create pr modify your Google Page, add the following HTML code in your sidebar.

/* Before the navigation is loaded to page, display red Loading… */

/*Call the JS file defidebefore*/
/*Add other code in Sidebar*/

The LoadXML method hasn’t been fully tested. Maybe you will encounter some problem when you use it. If you get some problem, please kindly tell me.

If you feel the article is useful and if you use my method mentioned in this article, I will appreciate if you can add my link in your Google Pages. If you refer to this page, please add the original link in yours.

Thank you very much!

What Is Your Comment?


* = required