Weave Code
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
Xml Wrangler

Xml Wrangler Laravel Package

saloonphp/xml-wrangler

XML Wrangler is a lightweight SaloonPHP plugin for working with XML in HTTP requests and responses. Easily build XML bodies, set the right headers, and parse XML responses into usable data for your Laravel or PHP API integrations.

View on GitHub
Deep Wiki
Context7

🌵 XML Wrangler - Easily Read & Write XML in PHP

Frequently asked questions about Xml Wrangler
How does Saloon XML Wrangler integrate with Laravel’s existing XML handling (e.g., SimpleXML or DOMDocument)?
XmlWrangler is designed to replace ad-hoc SimpleXML/DOMDocument code by providing a cleaner, type-safe API. It integrates seamlessly with Laravel’s service container, so you can swap out legacy XML logic without breaking existing workflows. For Saloon users, it fits directly into the request/response pipeline, reducing boilerplate for XML-heavy APIs.
What Laravel versions and PHP requirements does this package support?
XmlWrangler supports PHP 8.3+ and is compatible with Laravel 10+. It’s framework-agnostic but leverages Laravel’s DI container for easy integration. No Laravel-specific dependencies mean it works in any PHP 8.3+ environment, including Laravel 11 when released.
Can I use this package without Saloon, or is it strictly tied to Saloon’s HTTP client?
While XmlWrangler is optimized for Saloon, its core XML parsing/writing tools (XmlReader/XmlWriter) are standalone and can be used independently. If you’re not using Saloon, you’ll still benefit from its type-safe DTO conversion and namespace handling, but you’ll miss Saloon-specific integrations like automatic request/response XML conversion.
How do I handle complex XML schemas with namespaces in Saloon XML Wrangler?
Use the `withNamespaces()` method to register namespaces upfront. For SOAP or heavily namespaced XML, define a configuration array mapping prefixes to URIs. XmlWrangler then handles namespace-aware traversal and serialization. Test with real schemas early—some edge cases (e.g., default namespaces) may require custom XPath queries.
What’s the performance impact of using XmlWrangler vs. SimpleXML or DOMDocument for large XML files?
XmlWrangler supports streaming for large files, but memory usage depends on your XML structure. For deeply nested XML (>10MB), benchmark with your payloads—SimpleXML/DOMDocument may be more memory-efficient for one-off parsing. XmlWrangler shines for repeated transformations (e.g., API responses) due to its type safety and Saloon integration.
How do I test XML parsing/writing logic in Laravel with this package?
Use Pest or PHPUnit for unit tests, focusing on DTO conversion and XPath queries. For XML generation, snapshot testing (e.g., with `pest-plugin-snapshots`) ensures consistency. Mock Saloon connectors to isolate XML logic. Avoid testing against live APIs—use static XML files or factories to generate test payloads.
Are there alternatives to Saloon XML Wrangler for XML handling in Laravel?
For Saloon users, XmlWrangler is the most integrated option. Alternatives include standalone packages like `spatie/xml-to-array` (simpler but less type-safe) or `ext-simplexml` (built-in but verbose). If you’re not using Saloon, consider `league/xml-to-array` or `masterminds/html5` for broader XML/HTML support.
How do I serialize a Laravel Eloquent model or Collection to XML using XmlWrangler?
Use the `XmlWriter` class to manually serialize model attributes or Collection data. Map Eloquent relationships to nested XML nodes with `addChild()`. For complex structures, create a custom `XmlSerializable` interface or use Saloon’s DTOs to shape the output. Example: `$writer->addChild('user', $user->toArray())->write();`
What should I do if XmlWrangler fails to parse a malformed XML payload?
Enable strict parsing with `XmlReader::withStrictMode()` to throw exceptions on errors. For production, wrap parsing in a try-catch block and log the raw XML for debugging. Consider falling back to `libxml_use_internal_errors()` for graceful degradation if needed. Define SLAs for retries or fallback to raw XML in critical paths.
Can I extend XmlWrangler to handle custom XML formats (e.g., payment-specific schemas)?
Yes, create custom reader/writer classes extending `XmlReader`/`XmlWriter` and override methods like `parseNode()`. Register your classes in Saloon’s connector or Laravel’s service container. Document these extensions as internal packages to avoid vendor lock-in. Example: `class PaymentXmlReader extends XmlReader { protected function parsePaymentNode() { ... } }`
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai