PHP XML Expat Parser

PHP XML Expat Parser tutorial will explain you What is PHP XML Expat and What is XML File?

What is XML?

XML stands for eXtensible Markup Language, and it is a data format for structured document interchange on the Web.

What is XML Expat?

To play around with an XML document, you will need an XML parser.
There are two basic types of XML parsers:

  • Tree-based parser
  • Event-based parser

The Expat parser is an event-based parser.

The Expat parser is a non-validating, ‘event-based’ parser.XML content, not on structure (as tree-based parsers do).

A XML record is examined as a list of events: when an event happens, a particular function is called for taking care of it

Look at the following XML fraction:
<game>Cricket</game>

The code above implies 3 events:

  • Start element: game
  • Start CDATA section, value: Cricket
  • Close element: game

In this example there is no Document Type Definition (DTD) associated to it and hence, the example is not valid XML.

This is not a problem when using the Expat parser, since Expat is a non-validating parser, and ignores any DTDs.
Even if Expat is a non-validating parser, xml document must be well formed.

Note: The XML Expat parser functions are part of the PHP core. There is no installation needed to use these functions.

What is XML file?

In php, Expat is initialized as,
Parser = xml_parser_create();

Then, functions for handling XML file events are created.

Define which elements (events) should be parsed when parser encounter them into XML document and which not.

An XML file is loaded for parsing
$fp = fopen(“file.xml”,”r”);

xml_parser_free() function is called to release the memory allocated with the xml_parser_create() function
Then, Expat parser produces a human readable output.

SHARE
Previous articlePHP Filter
Next articlePHP XML DOM
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!