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

XSD Components

Tools for working with XSD schemas.

Example

use VeeWee\XML\DOM\Document;
use VeeWee\Xml\Xsd\Schema\Manipulator;
use function VeeWee\Xml\Dom\Locator\Xsd\locate_all_xsd_schemas;

$doc = Document::fromXmlFile('some.xml');
$schemas = $doc->map(locate_all_xsd_schemas(...))
    ->manipulate(Manipulator\base_path('/var/www'))
    ->manipulate(Manipulator\overwrite_with_local_files([
        'http://www.w3.org/2001/XMLSchema' => '/local/XMLSchema.xsd'
    ]));

It consists out of following components:

  • Schemas: Can be used to create a list of one or multiple XSD schemas.

Schemas

Can be used to keep track of the detected schema's inside a XML document.

This is what a schema looks like:

namespace VeeWee\Xml\Xsd\Schema;

#[Immutable]
final class Schema
{
    public static function withoutNamespace(string $location): self;
    public static function withNamespace(string $namespace, string $location): self;

    public function namespace(): ?string;
    public function location(): string;

    public function withLocation(string $location): self;
}

In XML, you'll often have a collection of schema's to work with:

namespace VeeWee\Xml\Xsd\Schema;

#[Extends iterable<Schema>]
#[Immutable]
final class SchemaCollection implements Countable, IteratorAggregate
{
    // Check the source code for a list of all functions you can use on this collection! 
}

This package provides some tools to work with schema's:

  • Manipulators: Can be used to manipulate a list of detected XSD schemas.

Schema Manipulators

Manipulators

Can be used to manipulate a list of detected XSD schemas.

base_path

If your XML document contains relative paths, you need to determine a base path. This base path can be a path on the server or a URL.

use VeeWee\Xml\Xsd\Schema\Manipulator;

$schemas = $schemas->manipulate(
    Manipulator\base_path('/var/www')
);

overwrite_with_local_files

Some files on e.g. W3.org can take forever to download over the internet. They put a sleep in place so that packages like this won't spam them every second. You can however, locally download the files and map their namespace to the local file like this the snippet below.

That way, you won't have to wait forever in order to validate your XML file!

use VeeWee\Xml\Xsd\Schema\Manipulator;

$schemas = $schemas->manipulate(Manipulator\overwrite_with_local_files([
    'http://www.w3.org/2001/XMLSchema' => '/local/XMLSchema.xsd'
]));

Writing your own manipulator

A manipulator can be any callable that takes a SchemaCollection and manipulates it into a new SchemaCollection.

namespace VeeWee\Xml\Xsd\Schema\Manipulator;

use VeeWee\Xml\Xsd\Schema\SchemaCollection;

interface Manipulator
{
    public function __invoke(SchemaCollection $schemaCollection): SchemaCollection;
}
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.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor