sabre/xml
sabre/xml is a lightweight, specialized XML reader and writer for PHP. It makes it easy to parse XML into structured data and generate XML output with namespace support. Version 3 adds strict type declarations and supports PHP 7.4+ and PHP 8.
XmlService for parsing/generating XML). Can be integrated as a Laravel package (via ServiceProvider) or standalone utility.XmlServiceProvider) for reuse across modules.sabre/vobject, sabre/event), this library provides consistent XML handling across tools.composer require sabre/xml. No Laravel-specific dependencies.Xml::parse()) for consistency with Laravel’s conventions.$this->app->bind('xml.service', function () {
return new \Sabre\Xml\Service();
});
libxml extension (enabled by default in Laravel). No risk if using standard Laravel deployments.XMLReader. Benchmark for large XML files (e.g., >100MB).sabre/xml throws exceptions; Laravel’s exception handling (e.g., App\Exceptions\Handler) must be configured.sabre/vobject)? This library provides consistent XML handling.Xml facade for fluent syntax (e.g., Xml::parse($xml)).symfony/serializer or symfony/yaml for hybrid data formats.SimpleXML, DOMDocument).sabre/xml incrementally.laravel-xml-service) to abstract sabre/xml:
// Example: XmlServiceProvider.php
public function register()
{
$this->app->singleton('xml', function () {
return new \Sabre\Xml\Service();
});
}
$xml = <<<XML
<root>
<item id="1">Test</item>
</root>
XML;
composer.json:
"require": {
"sabre/xml": "^4.0"
}
composer update and test in staging.libxml (enabled by default). No other extensions needed.\Sabre\Xml\Service) to avoid collisions.sabre/xml in service layers.PaymentGateway class from regex parsing to Xml::parse().Accept: application/xml).public function handle($request, Closure $next)
{
if ($request->isXml()) {
$request->merge(['xml' => Xml::parse($request->getContent())]);
}
return $next($request);
}
public function handle()
{
$xml = Xml::parse($this->file->get());
// Process data...
}
xmlschema/xmlschema).XMLReader).sabre/xml follows semver. Plan for:
composer update).sabre/uri (a dependency) for breaking changes.composer why sabre/xml to track dependencies.laravel-xml).sabre/xml docs.App\Exceptions\Handler to log XML parsing errors:
public function render($request, Throwable $exception)
{
if ($exception instanceof \Sabre\Xml\Exception) {
return response()->json(['error' => 'XML parsing failed'], 400);
}
return parent::render($request, $exception);
}
XMLReader directly or stream responses:How can I help you explore Laravel packages today?