Working with Microsoft XML Parser

What is an XML parser?
In simplest we can say that “XML Parser is the software that reads an XML document, identifies all the XML tags and passes the data to the application”. The work of XML parser is to do syntactic analysis of the given XML document.
Parsing XML Documents
To manipulate an XML document, you need an XML parser. The parser loads the document into your computer’s memory. Once the document is loaded, its data can be manipulated using the DOM. The DOM treats the XML document as a tree. You can understand this tree as the XML document tree shown when you the XML document with any browser such as Firefox etc.
There are some differences between Microsoft’s XML parser and the XML parser used in Mozilla and Opera browsers. In this tutorial we will show you how to create scripts that will work only in Internet Explorer browsers.
Working with Microsoft XML Parser
Microsoft’s XML parser is a COM component that comes with Internet Explorer 5 and higher. Once you have installed Internet Explorer, the parser is available to scripts. If you are using Internet Explorer version lower then IE 5, examples in this chapter may not work.
Microsoft’s XML parser supports all the necessary functions to traverse the node tree, access the nodes and their attribute values, insert and delete nodes, and convert the node tree back to XML.
Creating an instance of MS XML Parser :
var xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”)
Loading an XML document into parser:
var xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”)
The first line of the script above creates an instance of the XML parser. 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. The third line tells the parser to load an XML document called “simple_xml.xml”.
XML Validation
Validating an XML file against specified DTD through MS XML Parser:
Source code of “xml_parser_validation.php”
<script language=”JavaScript”>
    var xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”)
        document.write(“<br>Error Code: “)
        document.write(“<br>Error Reason: “)
        document.write(“<br>Error Line: “)
        document.write(“<B>Valid XML Document</b><br />”)
Source code of “simple_xml.xml”
<?xml version=”1.0″ encoding=”UTF-7″?>
    <!DOCTYPE address SYSTEM “simple_xml_dtd.dtd”>
        <name>Dharmendra Das</name>
        <address_str>D 210, sector 11, Rohni</address_str>
        <city>New Delhi</city>
Source code of DTD declaration:
<?xml version=”1.0″ encoding=”UTF-7″?>
<!ELEMENT address (name,address_str+,city,state,pin,company_info?)>
<!ELEMENT address_str (#PCDATA)>
<!ELEMENT state (#PCDATA)>
<!ELEMENT company_info (#PCDATA)>

<!ENTITY copy “©”>

<!ENTITY copyright “2007, all rights reserved”>

Scroll to Top