XML extensions

There are several ways to read and write XML documents in PHP, including regular expressions and specialized classes and methods. The regex approach is error-prone, especially with complex XML documents, which is why the use of extensions is advised. PHP provides several extensions for this purpose, the most common ones being as follows:

  • XMLWriter: This allows us to generate streams or files of XML data
  • XMLReader: This allows to read the XML data 
  • SimpleXML: This converts XML to an object and allows for an object to be processed with normal property selectors and array iterators
  • DOM: This allows us to operate on XML documents through the DOM API

The basics of dealing with an XML document are about proper reading and writing ...

Get Mastering PHP 7 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.