XML and JavaScript instances
Brief introduction:
Browser problem:
When it comes to browser-incompatible client language is a major problem. But here we have to use XML and Javascript,xml is the problem. Not all browsers have support for parsing XML documents. I will use IE6 to interpret the code. The browser does not support XML and cannot be read. When you are in a browser such an XML file, you will just ignore all the tags.
Sample XML file:
<company>
<employee id= "001" sex= "M" age= ">premshree pillai</employee>"
<employee id= "002" sex= "M" age= "a" >kumar singh</employee>
<employee id= "003" sex= "M" age= ">ranjit"
<turnover>
<year id= ">100,000</year>"
<year id= "2001" >140,000</year>
<year id= "2002" >200,000</year>
</turnover>
</company>
The above XML file shows employee data and turnover of the company (just a e.g).
Manipulating XML file data using JavaScript:
Loading XML file data using Javascript
var xmldoc = new ActiveXObject ("Microsoft.XMLDOM");
function Loadxml (xmlFile)
{
Xmldoc.async= "false";
xmldoc.onreadystatechange=verify;
Xmldoc.load (XmlFile);
Xmlobj=xmldoc.documentelement;
}
In fact, only the last two lines of functionality are sufficient to load an XML file. The two preceding lines are written to ensure that the JavaScript function, which we can use later to manipulate the data in the XML file, is an uninitialized object that does not perform any function. Therefore, functional validation () is invoked.
function Verify ()
{
0 Object is not initialized
1 Loading object is Loading data
2 Loaded object has Loaded data
3 Data from Object can is worked with
4 Object completely initialized
if (xmldoc.readystate!= 4)
{
return false;
}
}
Now the XML file can is loaded
Loadxml (' Xml_file.xml ');