Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Xml

Laravel Xml Laravel Package

bmatovu/laravel-xml

A Laravel package for working with XML. It converts XML requests and responses into arrays, adds XML response helpers and middleware, and lets your APIs accept and return XML alongside JSON, with configurable parsing and validation support.

View on GitHub
Deep Wiki
Context7

bmatovu/laravel-xml adds simple XML response support and array-to-XML conversion to Laravel applications. It provides a fluent builder for composing XML documents and integrates with Laravel’s response system, making it easy to return XML from controllers and APIs without manual string handling.

  • Fluent XML builder for nested elements and attributes
  • Convert PHP arrays directly to XML
  • Return XML through familiar Laravel responses
  • Lightweight, framework-native integration
  • Useful for APIs and legacy XML endpoints
Frequently asked questions about Laravel Xml
How do I install bmatovu/laravel-xml in a Laravel application?
Install it with composer require bmatovu/laravel-xml. The service provider is registered through Laravel package auto-discovery, so no manual provider entry is usually needed. Publish the config file with php artisan vendor:publish and then add your first XML route. Before pinning, read the composer.json illuminate/support constraint to confirm it covers your Laravel major.
Which Laravel and PHP versions does laravel-xml support?
Check the illuminate/support constraint and the PHP requirement in the package composer.json; the package targets modern Laravel releases on PHP 8.x. The important unknown is how quickly it tracks new Laravel majors, because a package that lags a major version becomes a release blocker. Confirm tags, green CI, and recent commit history before committing to it.
How do I return an XML response from a Laravel controller with this package?
The package exposes response helpers and macros so you can return XML directly from a route or controller, for example by passing an array to the XML response macro. Keep those call sites behind a small responder or presenter class instead of scattering inline response to XML calls through controllers. That keeps the vendor surface to two or three places and makes it trivial to swap serializers later.
Can laravel-xml convert an Eloquent model to XML?
Yes, the workflow is to serialize the model to an array and then convert that array to XML. Do not pass a full toArray() result, because that exposes every column and couples responses to the database schema. Use explicit field allow-lists with only() or a dedicated resource array, and be deliberate about relations, dates, and hidden attributes.
Does laravel-xml handle XML namespaces, attributes, CDATA, and XSD validation?
It is a generic array-to-XML serializer, so it handles the XML envelope but not a partner-specific schema contract. Attributes versus elements, namespace declarations, CDATA sections, and element ordering generally cannot be expressed by a plain array without extra care. XSD validation is out of scope, so if a partner enforces a schema you need schema-aware generation and validation on your side.
Does laravel-xml support Accept header content negotiation, or only explicit XML routes?
Prefer explicit XML routes and let JSON routes stay JSON; that is the predictable design and avoids surprising API clients. Content negotiation adds complexity and is best confirmed in the source before you rely on it. If you do need negotiation, test it yourself against real Accept headers rather than assuming it works.
Is laravel-xml a good fit for sitemaps and RSS or Atom feeds?
Yes, feed and sitemap generation is one of the strongest use cases because those documents are simple, schema-stable, and rarely need attributes or namespaces beyond the standard set. Build the items as an array and return them through the XML response helper. For very large sitemaps, stream the output instead of building the whole document in memory, and verify the Content-Type header your clients receive.
How should I test XML responses from a Laravel API built with this package?
Use DOM-based assertions rather than string comparison, otherwise whitespace and attribute ordering changes will make the suite brittle and developers will start skipping it. Laravel's assertXmlStringEqualsXmlString or a SimpleXMLElement comparison against a fixture works well. Also assert the Content-Type header, and add contract tests against real partner payloads or an XSD when a schema is involved.
Is laravel-xml safe, and does it parse inbound XML (XXE risk)?
The package is focused on emitting XML, so if it only serializes output the XXE attack surface largely disappears. If you accept inbound XML anywhere in your stack, harden the parser by disabling external entity loading and avoiding flags like LIBXML_NOENT. Also verify entity escaping and the charset and Content-Type headers, and never auto-serialize whole models into responses.
What are the alternatives to laravel-xml, and is it worth adopting in production?
The main alternative is adopting an array-to-XML library such as spatie/array-to-xml directly, or writing a thin internal responder if your needs are narrow. bmatovu/laravel-xml is a small, readable wrapper with a genuine but narrow use case for legacy B2B partner endpoints and feeds. Weigh the technical risk accordingly: the code is low risk, but 88 stars, zero dependents, and a single maintainer mean bus factor 1, so assume you may inherit maintenance and plan to wrap it behind your own interface.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings