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. Includes DOM helpers, safe error handling, memory-safe reader/writer, XML encode/decode, plus XSD and XSLT utilities. Spec-compliance ready for PHP 8.4+, with maintained v3 for older PHP.

View on GitHub
Deep Wiki
Context7

veewee/xml is a type-safe, declarative PHP toolkit for working with XML “without worries”. It wraps common XML tasks with consistent APIs and built-in error handling, helping you parse, validate, transform, and stream XML safely.

Designed for modern PHP, it also tracks evolving DOM spec compliance (v4 targets PHP 8.4+), while v3 remains maintained to ease upgrades.

  • DOM utilities to inspect and manipulate XML documents
  • xml_encode() / xml_decode() for JSON-like XML serialization
  • Robust ErrorHandling helpers for safe XML operations
  • Memory-safe Reader and Writer for streaming XML
  • XSD validation tools and XSLT transformations
Frequently asked questions about Xml
How do I install veewee/xml in a Laravel project?
Run `composer require veewee/xml` in your project root. The package integrates with Laravel’s service container, so you can bind components (e.g., `XmlWriterInterface`) in `AppServiceProvider` or use facades for Blade/console access. No additional Laravel-specific setup is required for basic usage.
Does veewee/xml work with Laravel’s Eloquent models for XML exports?
Yes. Use the `XmlWriter` component to serialize Eloquent models to XML. For example, create a `toXml()` method on your model or use a response macro like `Response::macro('xml', fn($model) => Xml::writer()->write($model->toArray()))` for API responses.
What’s the difference between v3 and v4 of veewee/xml?
v3 supports PHP 8.1–8.3 and lacks PHP 8.4’s DOM spec compliance, while v4+ requires PHP 8.4+ for stricter, future-proof XML handling. v3 remains actively maintained for legacy Laravel apps (e.g., PHP 8.1 LTS). Check the [support table](https://github.com/veewee/xml#support-table) for your PHP version.
Can I use veewee/xml to parse XML API requests in Laravel?
Absolutely. The `XmlReader` component handles memory-safe streaming of large XML payloads. Register a middleware (e.g., `XmlRequestMiddleware`) to parse incoming XML requests into arrays or objects, then process them like JSON requests. Example: `Xml::reader()->read($request->getContent())`.
How does veewee/xml handle XSD validation in Laravel?
The `XSD` component validates XML against schemas. Integrate it with Laravel’s validator by creating a custom rule (e.g., `XmlSchemaValidator`) or use it in middleware to validate XML requests before processing. For responses, validate XML output before sending to ensure compliance with third-party schemas.
Is veewee/xml compatible with Laravel’s caching system?
Yes. Cache XML transformations (e.g., XSLT or XSD-validated outputs) using Laravel’s cache drivers. For example, cache the result of `Xml::xslt()->transform($xml)` with `Cache::remember('xml_transformed', now()->addHour(), fn() => ...)`. This avoids reprocessing large XML files repeatedly.
What are the alternatives to veewee/xml for XML in Laravel?
For simple XML parsing, `SimpleXMLElement` (PHP’s built-in extension) or `spatie/xml-to-array` (for converting XML to arrays) may suffice. For advanced use cases, consider `DOMDocument` with custom wrappers. However, veewee/xml stands out with its type-safe API, memory-safe streaming, and Laravel-specific integrations (e.g., facades, validation).
How do I handle malformed XML errors in veewee/xml?
The package includes robust error handling helpers (e.g., `XmlErrorHandler`). Wrap XML operations in try-catch blocks or use the `Xml::errorHandler()` to log or rethrow errors. For APIs, return structured error responses (e.g., `response()->json(['error' => 'Invalid XML'], 400)`) when parsing fails.
Can veewee/xml replace SimpleXMLElement in Laravel?
Yes, but incrementally. Start by replacing `SimpleXMLElement` for XML generation with `XmlWriter` (more type-safe and memory-efficient). For parsing, use `XmlReader` instead of `simplexml_load_string()`. Test performance and memory usage in your Laravel app before full migration, especially for large XML files.
What’s the roadmap for XSLT/XSD in veewee/xml?
The roadmap includes integrating Saxon/C for XSLT 3.0/XPath 3.1 and advanced schema validation, but this depends on PHP 8+ support from Saxon/C (track [issue #4842](https://saxonica.plan.io/issues/4842)). Current XSD/XSLT features use PHP’s built-in extensions. For now, use the existing components for basic transformations and validation.
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.
croct/coding-standard
croct/plug-php
nqxcode/phpmorphy
boundwize/pyrameter
testo/facade
headercat/phpstan-extension-ide-helper
yosymfony/parser-utils
innmind/black-box
babenkoivan/elastic-migrations
babenkoivan/elastic-adapter
develia/commons
dmstr/symfony-system-resources-bundle
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
renatomarinho/laravel-page-speed
develia/geo-bundle
austinheap/laravel-database-encryption
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle