XML Module
Read XML rows securely with a forward-only parser, map arbitrary schemas, and write configurable XML output.
Updated
Xml::read()Xml::write()XmlSchemaMapping::from()XmlWriter::payloadToString()What you will learn
- Install the XML module and understand its secure defaults.
- Read simple row XML or map external schemas into canonical columns.
- Write row or workbook XML with configurable element names.
Install the XML package#
composer require mnb/mnb-phpexcel:^2.0ext-xmlreader is recommended for native streaming. The package includes a portable XML reader fallback through Core.
Read and write the default row shape#
use Mnb\PHPExcel\Format\Xml;
$rows = Xml::read('customers.xml', [
'row_tag' => 'customer',
])->withHeaderRow(1)->rows();use Mnb\PHPExcel\Format\Xml;
Xml::write($customers, 'customers.xml', [
'root' => 'customers',
'row_tag' => 'customer',
'pretty' => true,
]);Secure parser defaults#
- External network access is disabled through non-network parser flags.
- Document type declarations are rejected unless
allow_doctypeis explicitly enabled. - File size, row count, and nesting depth can be bounded.
- Element names emitted by the writer are sanitized into valid XML tags.
Was this guide useful?Use GitHub issues for corrections, missing examples, or unclear behavior.
Open an issue