XML Processors
XML Processors
EXAMPLE:
<html>
<body>
<p id="demo"></p>
<script>
var text, parser, xmlDoc;
text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";
document.getElementById("demo").innerHTML =
xmlDoc.getElementsByTagName("title")
[0].childNodes[0].nodeValue;
</script>
</body>
</html>
EXPLANATION OF EXAMPLE:
A TEXT STRING IS DEFINED
text = "<bookstore><book>" +
"<title>Everyday Italian</title>" +
"<author>Giada De Laurentiis</author>" +
"<year>2005</year>" +
"</book></bookstore>";
AN XML DOM PARSER IS CREATED
parser = new DOMParser();
The parser creates a new XML DOM object using the text string:
xmlDoc = parser.parseFromString(text,"text/xml");