Breaking News
yeni film izle hd film seyret film izle

Mozilla & Opera XML Parser

XML Parser in Mozilla, Firefox, Opera and other browser work little differently from Microsoft XML parser. If you try to open the example of the previous chapter with a browser other then the Microsoft Internet Explorer, you might not be able to see the parser output. Reason is the previous example is optimized for the Microsoft Internet Explorer.
 
Mozilla’s XML (I’ve used Mozilla XML parser to refer to XML parser of Mozilla, Firefox and Opera browsers) parser supports all the necessary functions to traverse the node tree, access the nodes and their attribute values, insert and delete nodes, and convert the node tree back to XML.
 
 
Creating an instance of the XML Parser in Mozilla:
 
var xmlDoc=document.implementation.createDocument(“namespace”,”rootelement”,null);
 
The first parameter, namespace, defines the namespace used for the XML document. The second parameter, rootelement , is the XML root element in the XML file. The third parameter, null, is always null because it is not implemented yet.
 
 
Loading an XML document into parser
 
The following code fragment loads an existing XML document (“simple_xml.xml”) into Mozillas’ XML parser:
 
var xmlDoc=document.implementation.createDocument(“”,”address”,null);

xmlDoc.load(“simple_xml.xml”);

 
The second line tells the parser to load an XML document called “simple_xml.xml”.
 
<html>
<head>
<script type=”text/javascript”>
var xmlDoc;
function createParserInstance()
{
    xmlDoc=document.implementation.createDocument(“”,””,null);
    xmlDoc.load(“simple_xml.xml”);
    xmlDoc.onload=loadMSG;

}
function loadMSG()
{
    document.getElementById(“name”).innerHTML= xmlDoc.getElementsByTagName(“name”)[0].childNodes[0].nodeValue;

//document.write(xmlDoc.getElementsByTagName(“name”)
[0].childNodes[0].nodeValue);

    document.getElementById(“address_str”).innerHTML= xmlDoc.getElementsByTagName(“address_str”)[0].childNodes[0].nodeValue;

    document.getElementById(“city”).innerHTML= xmlDoc.getElementsByTagName(“city”)[0].childNodes[0].nodeValue;

    document.getElementById(“state”).innerHTML= xmlDoc.getElementsByTagName(“state”)[0].childNodes[0].nodeValue;

    document.getElementById(“pin”).innerHTML= xmlDoc.getElementsByTagName(“pin”)[0].childNodes[0].nodeValue;
}
</script>
</head><body onload=”javascript:createParserInstance();”>
<h1>Address details of Associate</h1>
<p><b>Name </b> <span id=”name”></span><br />
<b>Address </b> <span id=”address_str”></span><br />
<b>City:</b> <span id=”city”></span><br />
<b>State :</b><span id=”state”></span><br />
<b>Pin : </b><span id=”pin”></span>
</p>
</body>
</html>

 

Check Also

XML and Server

Generating XML with JSP   XML can be generated on a server without any installed …