Thursday, December 4, 2008

Coding for Accessing xml file using javascript

var xml_doc_variable;
function read_xml_file(file_name)
{
xml_doc_variable=new ActiveXObject"Microsoft.XMLDOM");
xml_doc_variable.async=false;
xml_doc_variable.load(file_name);
var xml_doc_values=xml_doc_variable.getElementsByTagName("company");
var xml_value=xml_doc_values[0].getElementsByTagName("employee");
var user_name=xml_value[0].firstChild.nodeValue);//accessing values from specified tag
var text_box_value=document.getElementById('t1');
if(username==text_box_value)
alert('rite user');
else
alert('wrong user');
document.write(xml_value[0].getAttribute("id"));//getting value of attribute
}

No comments: