PHP XML Parsers
What is an XML Parser?
An XML parser is a program that is designed to read, process and interpret XML documents.
Tip: If you want to learn more about XML, please visit our XML tutorial.
An XML parser translates the raw text in an XML file, and creates a way for programs to easily use and manipulate it.
There are two types of XML parsers:
1. Tree-based Parsers
A Tree-based Parser loads the entire document in memory as a tree structure. It analyzes the whole document, and provides access to the tree elements (DOM).
A tree-based parser is an ideal option for smaller XML documents, but not for large XML documents (as it causes major performance issues).
Examples of tree-based parsers: SimpleXML Parser and DOM Parser.
2. Event-based Parsers
An Event-based Parser does not load the entire document in memory, instead, it reads in one node at a time and allows you to interact with it. Once you move onto the next node, the old one is thrown away.
An event-based parser is well suited for large XML documents. It parses faster and consumes less memory.
Examples of event-based parsers: XMLReader and XML Expat Parser.