PHP XML

PHP XML


                                 

XML is Extensible Markup Language. It is a markup language - much like HTML - and was designed to describe data. XML uses tags but these tags are not predefined as in HTML. In XML you define your own tags. All XML documents have 3 types of components: Elements, attributes and data.

XML is very strict when it comes to document structure. HTML lets you play fast and loose with some opening and closing tags. But this is not the case with XML.

Why Study XML?

XML plays an important role in many different IT systems.

XML is often used for distributing data over the Internet.

It is important (for all types of software developers!) to have a good understanding of XML.

In this tutorial we have to learn XML topics :

  1. PHP XML Parsers
  2. PHP Simple XML Parsers
  3. PHP Simple XML - Get
  4. PHP XML Expat
  5. PHP XML DOM

There are two major types of XML parsers:

  • Tree-Based Parsers
  • Event-Based Parsers
Tree-Based Parsers

Tree-based parsers holds the entire document in Memory and transforms the XML document into a Tree structure. It analyzes the whole document, and provides access to the Tree elements (DOM).

This type of parser is a better option for smaller XML documents, but not for large XML document as it causes major performance issues.

Example of tree-based parsers:

  • SimpleXML
  • DOM
Event-Based Parsers

Event-based parsers do not hold the entire document in Memory, instead, they read in one node at a time and allow you to interact with in real time. Once you move onto the next node, the old one is thrown away.

This type of parser is well suited for large XML documents. It parses faster and consumes less memory.

Example of event-based parsers:

  • XMLReader
  • XML Expat Parser