XMLHttpRequest to read data from XML file
JavaScript XML
All modern browsers support XML parser to read data from a XML file. Here is a sample code to read data from XML
<script type="text/javascript">
if (window.XMLHttpRequest)
{ my_xml=new XMLHttpRequest();
}
else
{
my_xml=new ActiveXObject("Microsoft.XMLHTTP");
}
</script>
XMLHttpRequest is widely used in Ajax to interact with server without reloading the page. Along with any server side scripting language we can develop powerful applications. You can read more on our PHP Ajax section .
We will be using our sample XML file
https://www.plus2net.com/php_tutorial/file-xml-demo.xml
Here is the code to read the xml file.
<script type="text/javascript">
if (window.XMLHttpRequest)
{ my_xml=new XMLHttpRequest();
}
else
{
my_xml=new ActiveXObject("Microsoft.XMLHTTP");
}
/////////////////////////////
my_xml.open("GET",'https://www.plus2net.com/php_tutorial/file-xml-demo.xml',false);
my_xml.send();
xml_str=my_xml.responseXML;
</script>
Displaying node value of xml file
← XML
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
plus2net.com