mtownsend/xml-to-array
Easily convert XML into a clean, traversable PHP array and back again. This lightweight package handles nested elements, attributes, and namespaces, so you can consume XML feeds or APIs in Laravel and plain PHP projects without writing repetitive parsing code.
Architecture fit
ext-simplexml. No service container requirements, no event/queue/cache coupling, no persistence, no global state. It can live at the edge of an ingestion pipeline and be discarded without architectural debt.array, it is a parsing utility, not a modeling utility. It should feed a mapper/DTO layer, never your domain objects directly.Integration feasibility
composer require mtownsend/xml-to-array; Laravel package auto-discovery handles the service provider. Plain-PHP usage via a static call works without the framework.ext-simplexml, which ships enabled in virtually all PHP builds. No database, no queue, no published config required.Technical risk
@attributes, @value, and similar). A real XML element literally named @attributes (rare but legal) collides. Namespace handling is partial and easy to get wrong.LIBXML_NOENT and does pass LIBXML_NONET. Modern libxml disables network entity loading by default, but "default" is not a control — read the code. Entity-expansion ("billion laughs") protection depends on libxml_disable_entity_loader/libxml version behavior, so cap input size upstream regardless.Exception rather than a typed exception means callers must catch narrowly or wrap defensively.<a/>, <a></a>, and a missing <a> are not reliably distinguishable in the resulting array. If your downstream logic cares, this package is the wrong layer.Key questions
LIBXML_NONET set and LIBXML_NOENT absent? Can libxml options be passed through by the caller?@attributes key name configurable, and is there a documented escaping rule for collisions?illuminate/support constraints) and does it match our app?xsi:nil, CDATA sections, and repeated siblings with differing attributes?Stack fit
spatie/laravel-data, Symfony Serializer, or a hand-written mapper) that owns shape normalization.Migration path
XmlParser interface with one method returning a typed DTO. Implement it with this package. No call site ever references the package by name. This is the whole migration strategy and it costs an hour.simplexml_load_string call sites behind the same interface, run both implementations against a golden-file corpus, diff the outputs, cut over call site by call site. Expect diffs in attribute representation and single-child shapes; resolve them in the mapper, not by patching the package.DOMDocument or XMLReader. Budget the fork, not a rewrite.Compatibility
composer.json constraints against your matrix before merging. The most common integration failure here is an illuminate/support version pin that lags your framework major by one release.Sequencing
Maintenance
Support
Scaling
XMLReader streaming or a SAX approach; this package has no streaming mode.Failure modes
catch and surfaces as a 500.<item> elements instead of one — the highest-probability production incident with this package.Ramp-up
How can I help you explore Laravel packages today?