i

PHP Tutorial

PHP XML Parsers

XML stands for Extensible Markup language and it defines a set of rules to encode a document in a human readable and machine-readable format. XML parsers are designed to read XML language and to create a way so that programs can use XML.  Many of the web technologies like RSS feeds or podcasts are commonly written in XML as it is easy to create. You can make your own tags in XML.

To update, read, create or manipulate an XML document, XML parser is very useful. There are two types of parsers in PHP.

  • Tree Based Parsers – It holds the entire document in memory and transforms it into a tree structure by providing access to tree elements(DOM). It is useful for small XML documents as it causes performance issues for large XML files. Example of tree-based parsers are SimpleXML and DOM.

  • Event Based Parsers – It doesn’t hold the entire document in the memory and read one node at a time. It allows you to interact in real time and once you go to another node, the old one is removed from memory. It is good for large XML documents. Example are XML Reader and XML Expat Reader.