XML
extensible Markup Language designed to transport & store data. XML document contains plain text wrapped in tags. It is like a plane text file with .xml extension.HTML & XML are totally differnt html is designed how to display data & xml how to stor data. XML seperates data from HTML.I most liked xml defination is "It is software & hardware independenet tool for carring information". Xml's advantages are it greatly simplifies data sharing, data transport, increases data availablity. Dont confuse xml with database. xml comes in the picture when data is not so complex, not large but plain text file are not enough to handle then you can go for xml.
Syntax Rules
-All XML elements must be closed.
-All xml elements must ne properly nested.
-Attribute values must be quoted.
-XML elements are case sensitive.
XML Parser
To manipulate xml document we need xml parser.xml parser reads xml document & covert it into the XML DOM object that can easily accessed with javascript. Most of the browsers have built-in xml parser.There are two types of xml parser tree-based & event-based. Event-based parser is faster than tree-based.
How to load xml document
- First get xmlHTTPReqest object
- open request
- send request to the server
- get respose from server
<script type="text/javascrit">
if(window.XMLHttpRequest)
{
xhtttp = new XMLHttpRequest; // mozilla
}
else
{
xhttp = new ActiveXObject("Microsoft.XMLHTTP"); // IE
}
xhttp.open("get","filename.xml",false);
xhttp.send("");
xmldoc = xhttp.resposnseXML;
document.getElementById("result").innerHTML = xmlDoc.getElementsByTagName("nameof tag in xmlfile")[0].childNodes[0].nodeValue;
<script>
XML DOM
Document Object Model defines a standard way for accessing & manipulating xml document. It provied all functions to create, delete, update xml elements.
PHP XML Parser
To manipulate xml document in php there are three ways to Expat Parser, SimpleXML Parser & XML DOM.
Expat is event-based parser & faster because it focus on the content of the document not its structure.
SimpleXML Parser is easy way to read change delete xml elements but when you want to deal advance xml then you have to decide other parser.
e.g.
$xml = simplexml_load_file("Filename.xml");
echo $xml->asXML;
OR
$xmldom = new domDocument;
$xmldom->load("Filename.xml");
$xmldom->saveXML();
No comments:
Post a Comment