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 Laravel Package

veewee/xml

Type-safe, declarative XML toolkit for PHP. Work with DOM safely, encode/decode XML like JSON, handle errors, and stream large files with memory-safe reader/writer. Includes XSD schema tools and XSLT transformations. Spec-compliant from v4 (PHP 8.4+).

View on GitHub
Deep Wiki
Context7

veewee/xml is a type-safe, declarative toolkit for working with XML in PHP—designed to reduce footguns and handle errors predictably. It bundles practical building blocks for reading, writing, transforming, validating, and encoding XML with a “no worries” API.

From v4 it opts into PHP 8.4’s DOM spec compliance mode (with an actively maintained v3 line for older PHP versions), helping you move toward a more stable and standards-aligned XML stack.

  • DOM utilities to operate on XML documents safely
  • Encoding helpers: xml_encode() / xml_decode() (JSON-like ergonomics)
  • ErrorHandling tools for reliable parsing and failures
  • Memory-safe Reader and Writer components
  • XSD validation and XSLT transformations
Frequently asked questions about Xml
How do I use veewee/xml to generate XML responses in a Laravel API?
Use the `Writer` component to declaratively build XML responses. For example, create a route handler that constructs XML with `Writer::forString()->root('response')->child('data', $data)` and return it as a response. This works seamlessly with Laravel’s HTTP layer, including middleware for content-type headers. The memory-safe design ensures large payloads (e.g., reports) won’t overload your server.
Does veewee/xml support Laravel’s service container or facades?
No, the package is framework-agnostic. You’ll need to manually bind it to Laravel’s service container (e.g., `app()->bind('xml.writer', fn() => new Writer())`) or wrap components in facades. This aligns with Laravel’s flexibility but requires minor setup. For queue jobs, inject the `Writer` directly into job classes.
Can I parse XML feeds or SOAP responses with this package?
The `Reader` component handles parsing, but it’s less documented than the `Writer`. For complex parsing (e.g., SOAP), consider pairing it with Laravel’s HTTP client or SimpleXML for validation. The package focuses on generation, so if parsing is your primary need, evaluate alternatives like `simplexml` or `xml` extensions. For XSD validation, the `XSD` component is in early stages.
What’s the difference between v3 and v4 of veewee/xml?
v3 supports PHP 8.1–8.3 and prioritizes stability, while v4 requires PHP 8.4+ and enables opt-in DOM spec compliance (fixing historical PHP quirks). v4 is future-proof but may break compatibility with older Laravel projects. Use v3.x if you’re stuck on PHP 8.1–8.3, or plan a PHP upgrade to leverage v4’s compliance. Both versions receive active maintenance.
How do I validate XML output in Laravel tests?
Use PHPUnit’s `assertXmlStringEqualsXmlString()` or third-party libraries like `phpunit/xml` for assertions. For custom validation, combine the `ErrorHandling` component with Laravel’s testing helpers (e.g., `assertMatchesRegularExpression`). Example: `assertXmlStringEqualsXmlString($expected, $writer->render())`. Document expected XML structures in your test suite.
Is veewee/xml memory-safe for large XML files (e.g., 100MB+)?
Yes, the `Writer` component streams output by default, avoiding memory overload. For even larger files, use `Writer::forStream()` to write directly to a file handle or network stream. Benchmark with your dataset—if performance lags, optimize by reducing nested elements or using generators (e.g., `children()` with `yield`). This makes it ideal for Laravel queue jobs processing bulk exports.
Can I use veewee/xml with Laravel’s Eloquent to generate XML exports?
Absolutely. Use Eloquent’s generators with the `Writer`’s `children()` method to lazily build XML from database records. Example: `Writer::forString()->root('users')->children(fn() => yield from User::all())`. This pairs well with Laravel’s query builder for dynamic XML generation, like filtering or paginating results before export.
What are the alternatives to veewee/xml for XML in Laravel?
For generation, consider `SimpleXMLElement` (built-in) or `spatie/xml` (Laravel-focused). For parsing, `SimpleXML` or `DOMDocument` are robust. If you need XSD validation, `ext/xsd` or `saxon/c` (via veewee/xml’s future XSLT component) are options. veewee/xml stands out for its type safety, memory efficiency, and declarative API, but trade-offs include no Laravel-specific integrations and a steeper learning curve.
How do I handle errors when generating XML with veewee/xml?
Wrap XML generation in `try-catch` blocks to catch `XmlException` or `InvalidArgumentException`. The `ErrorHandling` component provides tools like `XmlErrorHandler` to customize error responses. For Laravel APIs, return HTTP 500 errors with JSON error details if XML generation fails. Example: `try { $xml = $writer->render(); } catch (XmlException $e) { return response()->json(['error' => $e->getMessage()], 500); }`
Does veewee/xml support XSLT transformations in Laravel?
The `XSLT` component is available but relies on external libraries like `saxon/c` (awaiting PHP 8 support). For now, use PHP’s built-in `ext/xsl` or integrate `saxon/c` manually. This is a future-proof feature—check the roadmap for updates. For simple transformations, consider Laravel’s `Str::of()` or Blade templates combined with `DOMDocument` for lightweight use cases.
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