Use of Parser in XML

In this article I have described an XML parser used in parsing an XML document into an XML DOM object with the help of an example.
  • 2898

XML Parser

An XML parser is a parser that is designed to read XML and create a way for programs to use XML.

The main function of XML parser is to convert converts an XML document into an XML DOM object.

Then  XML DOM object is manipulated with JavaScript.

There is nothing there to write XML but every program must implement or call on an XML parser.

Type of XML Parser

XML parsers are available into two form

  • Standard parser

  • Validating parser

Parse an XML Document

Lets take an xml document and save it as "school.xml"

<?xml version="1.0" encoding="utf-8" ?>

<schoolInformation>

  <GeneralInformation>

    <School>parsering of XML document</School>

    <Department>Department of XML parsing</Department>

  </GeneralInformation>

 </schoolInformation>

 

The following code parses above XML document into an XML DOM object

 

if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","school.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML;

Difference between TXmlParser and TXmlScanner

TXmlParser is a Delphi CLASS for easy parsing of an XML file while TXmlScanner is a VCL wrapper for TXmlParser.  That means we should use TXmlParser for serious work and TXmlScanner for "quick hacks".

Further Readings

You may also want to read these related articles

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

© 2019 DotNetHeaven. All rights reserved.