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 helper for Saloon: parse XML responses into arrays/objects, map nodes to data, handle namespaces, attributes and CDATA, and build or transform XML payloads cleanly. Great for SOAP-style APIs and legacy XML integrations in Laravel/PHP.

View on GitHub
Deep Wiki
Context7

saloonphp/xml-wrangler is a lightweight XML toolkit built to pair neatly with Saloon, helping you parse, traverse, and transform XML responses without the usual boilerplate. It provides a clean, fluent API for working with XML in PHP while keeping integrations predictable and testable.

Use it to normalize third‑party XML APIs, extract values safely, and convert structures into arrays/objects your application can consume.

  • Fluent XML parsing and traversal with an ergonomic API
  • Easy value extraction with sensible defaults and helpers
  • Convert XML to arrays/collections for downstream processing
  • Utilities for namespaces/attributes and common XML edge cases
  • Designed for smooth use alongside Saloon request/response flows
Frequently asked questions about Xml Wrangler
How do I integrate **xml-wrangler** with Saloon for SOAP API responses?
Use the `XmlApiConnector` trait in your Saloon connector. Override the `resolve()` method to parse XML responses with `XmlReader::load($response->body())->query('//desiredNode')->map()`. The package handles namespaces and attributes automatically if configured in the reader.
Does **xml-wrangler** support PHP 8.3, or is PHP 8.4+ required for generics?
The package works on PHP 8.3+, but generics (e.g., `Query::fromArray<ProductDto>`) require PHP 8.4+. If you’re on 8.3, you’ll lose type safety for mapped results but can still use the core parsing and traversal methods without issues.
Can I safely parse large XML files (e.g., 100MB+) without memory issues?
Yes, use the `each()` method for lazy evaluation or stream the XML with `XmlReader::load($stream)->rewindable()`. Avoid `all()` for large files, as it loads everything into memory. The package is designed to handle streaming with minimal overhead.
How do I handle XML namespaces, especially for SOAP APIs?
Pass the namespace prefixes and URIs to `XmlReader::withNamespaces(['soap' => 'http://example.com/soap'])` before parsing. For SOAP, chain this with `query('//soap:Envelope/soap:Body')` to target namespaced nodes. The package validates namespace declarations during parsing.
Is there a way to convert XML to Eloquent models or Laravel Collections?
Yes, use `XmlReader::load()->map()` to convert XML nodes to arrays, then hydrate Eloquent models with `Model::hydrate()` or wrap in a `Collection` via `collect($reader->query()->map()->all())`. For bulk operations, chain `each()` with a closure to process nodes incrementally.
What’s the performance difference between **xml-wrangler** and SimpleXML/DOMDocument?
For small to medium XML files, **xml-wrangler** is comparable to SimpleXML but offers a more fluent API. DOMDocument is slower for parsing but more feature-rich for complex transformations. Benchmark your use case—**xml-wrangler** excels in Saloon integrations and type safety.
How do I test XML parsing logic in Laravel/Pest or PHPUnit?
Use `XmlReader::load($xmlString)->query()->map()` in tests, then assert results with `assertEquals()` or Pest’s `expect()`. For snapshot testing, serialize the parsed structure with `json_encode($reader->toArray())` and compare against a baseline file.
Can I generate XML dynamically from Laravel Collections or Eloquent models?
Yes, use `XmlGenerator::create()->root('response')->node('items', $collection->map(fn($item) => $item->toArray()))`. The generator supports nested structures, attributes, and CDATA. For Eloquent, chain `->node('user', $user->toArray())` directly on the generator.
What alternatives should I consider if **xml-wrangler** lacks a specific feature?
For XPath-heavy workflows, consider **Extenso/XML** or **XMLReader** (PHP’s built-in extension). If you need DOM manipulation, **DOMDocument** is more powerful but verbose. For Saloon users, **xml-wrangler** is the most integrated option—evaluate if its abstractions justify the trade-offs.
How do I debug XML parsing errors or malformed responses?
Use `XmlReader::load()->toXmlString()` to inspect the parsed structure or `->debug()` to log raw XML. For XPath issues, validate queries with `->query('//node')->first()` and check if the node exists. The package throws descriptive exceptions for malformed XML or missing nodes.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport