The Microsoft XML parserMSXML Parser 2.5 is the XML parser that is shipped with Windows 2000 and IE 5.5.
MSXML Parser 3.0 is the XML parser that is shipped with IE 6.0 and windows XP.
Once you have installed Internet Explorer, the parser is available to scripts, both inside HTML documents and inside ASP files. The MSXML 3.0 parser features a language-neutral programming model that supports:
JavaScript, VBScript, Perl, VB, Java, C++ and more
Complete XML support
Full DOM and Namespace support
DTD and validation
Complete XSLT and XPath support
SAX2
Server-safe HTTP
To create an XML Document Object with JavaScript, use the following code:
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
To create an XML Document Object with VBScript, use the following code:
set xmlDoc=CreateObject("Microsoft.XMLDOM")
To create an XML Document Object in ASP (with VBScript), use the following code:
set xmlDoc=Server.CreateObject("Microsoft.XMLDOM")
The Mozilla XML ParserPlain XML documents are displayed in a tree-like structure in Mozilla (just like IE).
Mozilla also supports parsing of XML data that resides in a file, using JavaScript. The parsed data can be displayed as HTML.
To create an XML Document object with JavaScript in Mozilla, use the following code:
var xmlDoc=document.implementation.createDocument("ns","root",null)
The first parameter, ns, defines the namespace used for the XML document. The second parameter, root, is the XML root element in the XML file. The third parameter, null, is always null because it is not implemented yet.
Loading an XML File Into the Parser
The following code loads an existing XML document ("note.xml") into the XML parser:
<script type="text/javascript">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("note.xml")
...
...
...
</script>
The first line of the script creates an instance of the Microsoft XML parser. The third line tells the parser to load an XML document called "note.xml". The second line turns off asynchronized loading, to make sure that the parser will not continue execution of the script before the document is fully loaded.
Loading XML Text Into the ParserThe following code loads a text string into the XML parser:
<script type="text/javascript">
var txt="<note>"
txt=txt+"<to>Tove</to><from>Jani</from>"
txt=txt+"<heading>Reminder</heading>"
txt=txt+"<body>Don't forget me this weekend!</body>"
txt=txt+"</note>"
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.loadXML(txt)
...
...
...
</script>
Note that we have used the "loadXML" method (instead of the "load" method) to load a text string.