What is XML DOM Function
In this articles I am going to explain about how to use XML DOM function.
DOM Load Functions in XML
The code for loading XML documents can be stored in a function.
loadXMLDoc() Function in XML
the loadXMLDoc() function can be called from a script in the page. The "loadxmldoc.xml", and will be loaded of an HTML page
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="loadxmldoc.html"></script>
</head>
<body>
<script type="text/javascript">
xmlDoc=loadXMLDoc("Library.xml");
document.write(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue + "<br />");
document.write(xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue + "<br />");
document.write(xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue);
</script>
</body>
</html>
|
Define the code
- First we create XML http object and open it.
- XML http script send the request to the server.
- "loadxmldoc.html" get the data.
- Set the response as an XML DOM object.
- Document. write is print the document
- Internet Explorer uses the load XML() method to parse an XML documents.
loadXMLString() Function in XML
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="loadxmlstring.html"></script>
</head>
<body>
<script type="text/javascript">
text="<bookstore>
<book>
";
text=text+"<title>Everyday Indian</title>";
text=text+"<author>Aman</author>";
text=text+"<year>2012</year>";
text=text+"
</book>
</bookstore>";
xmlDoc=loadXMLString(text);
document.write(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue);
document.write("<br />");
document.write(xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue);
document.write("<br />");
document.write(xmlDoc.getElementsByTagName("year")[0].childNodes[0].nodeValue);
</script>
</body>
</html>
|
Define the code
- First we create XML http object and open it.
- XML http script send the request to the server.
- "loadxmldoc.html" get the data.
- Set the response as an XML DOM object.
- Document. write is print the document
- Internet Explorer uses the load XML() method to parse an XML documents
You may also want to read these related articles :
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here