XML ANALYZER

An XML parser is used to convert an XML file into an XML DOM object that can be manipulated in JAVASCRIPT.

JAVASCRIPT sample to analyze the XML file "messages.xml" which is on the same server as the page that will run this JavaScript code:

IF (window.XMLHttpRequest) { // Firefox, Chrome, IE7+, Opera y Safari xmlhttp=new XMLHttpRequest(); } ELSE { // Microsoft Explorer IE6, IE5, .. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.open("GET"," messages.xml",false); xmlhttp.send(); xmlDoc=xmlhttp.responseXML;

JAVASCRIPT sample to analyze a string in XML format

str="<messages><message>"; str=str+"<from>John</from>"; str=str+"<to>Peter</to>"; str=str+"<title>Meeting</title>"; str=str+"<text>Remember out meeting</text>"; str=str+"</message></messages>"; if (window.DOMParser) { parser=new DOMParser(); xmlDoc=parser.parseFromString(str,"text/xml"); } else { // Microsoft Explorer xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async=false; xmlDoc.loadXML(str); }