XML PARSERS
Learning Objectives
By
the end of this topic, you will be able to:
- Identify the XPATH operators
- Explain what is an XML transformation language
- Identify XSLT as an XML transformation language
XML Parsing
- All modern browsers have a built-in XML parser to read and manipulate XML
- Built-in XML parser reads XML into memory and converts it into an XML DOM object that can be accessed with JavaScript
Browser Differences in XML Parsing
- Microsoft XML parser is different from other browsers
- Single Microsoft parser supports loading of both XML files and XML strings (text)
- Other browsers use separate parsers
- However, all parsers contain functions to traverse XML trees, access, insert, and delete nodes (elements) and their attributes
- Note: 'Nodes' is the term used to refer XML elements
Loading XML with Microsoft's XML Parser
- Microsoft's XML parser is built into Internet Explorer 5 and higher
- Parsing XML File
- JParsing XML String
Parsing XML File
The
following JavaScript fragment loads an XML document ("note.xml") into
the parser:
var
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.load("note.xml");
In the script above:
- Line 1 - creates an empty Microsoft XML document object
- Line 2 - turns off asynchronous loading, to ensure that the parser is not execution until the document is fully loaded.
- Load is used to load an XML document called "note.xml"
Parsing XML String
The
following JavaScript fragment loads a string called txt into the parser:
var
xmlDoc=new;
ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(txt);
In the script above:
- Line 1 - creates an empty Microsoft XML document object
- Line 2 - turns off asynchronous loading, to ensure that the parser is not execution until the document is fully loaded
- LoadXML is used to load an XML string