PHPackages                             ls-a/xsd-generator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. ls-a/xsd-generator

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

ls-a/xsd-generator
==================

Generate an XSD file based on PHP classes.

1.0.0(6mo ago)0251GPL-3.0-or-laterPHPPHP ^8.0.0

Since Nov 13Pushed 5mo agoCompare

[ Source](https://github.com/ls-a-fr/xsd-generator-php)[ Packagist](https://packagist.org/packages/ls-a/xsd-generator)[ RSS](/packages/ls-a-xsd-generator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (1)

XSD Generator
=============

[](#xsd-generator)

This documentation is also available in these languages:

- [Français](docs/LISEZMOI.md)

This library provides a simple and readable interface to create and manipulate XSD with ease. This library provides many features that aren't available out there in Composer (yet?).

First, this library revolves around Profiles, classes that:

- Fetches any meaningful classes based on library [XML-Utils](https://github.com/ls-a-fr/xml-utils)
- Configure any XSD element for perfect rendering: complexType, sequence, choice, restriction
- Allows to build on other Profiles to rename, replace, remove, add specific types you wish to
- Allows to export Profile as a callable action, to use it in a Validator later

Example 1: Rename a type
------------------------

[](#example-1-rename-a-type)

Suppose you have a specific Type declared as:

```
class SomeStringType extends Type implements Validator
{
    public function getValidator(): Validator
    {
        return new RegexValidator('xxx');
    }
}
```

And you wish to achieve this result. Note the `name` attribute on ``:

```

```

You need to:

1. Create a Finder subclass, to get this SomeStringType type:

```
class MyFinder extends Finder
{
    public function getResults(): array|NodeCollection
    {
        return [
            new Type(new SomeStringType()),
        ];
    }
}
```

2. Create a Profile subclass, with builtin transformers, and execute your operation on Finder results:

```
class MyCustomProfile extends Profile
{
    public function getFinders(): InheritableConfiguration
    {
        // Which class you wish to include in your XSD
        return new InheritableConfiguration(__FUNCTION__, [
            MyFinder::class,
        ]);
    }

    public function getTransformers(): InheritableConfiguration
    {
        // Which transformers you wish to use:
        // - Type: `` tags
        // - Restriction: `` tags
        // Other transformers are included in this package
        return (new InheritableConfiguration(__FUNCTION__))
            ->rule(Type::class, [
                'evaluate' => [TypeTransformer::class],
            ])
            ->rule(Restriction::class, [
                'evaluate' => [RegexNmTokenTransformer::class],
            ]);
    }

    public function execute(): void
    {
        if ($this->isExecuted === true) {
            return;
        }
        parent::execute();
        // Rename "some-string" to "xxx-string"
        $this->rename(SomeStringType::class, 'xxx-string');

        $this->isExecuted = true;
    }
}
```

Example 2: Change XSD structure based on another Profile
--------------------------------------------------------

[](#example-2-change-xsd-structure-based-on-another-profile)

Suppose you already have a valid Profile, then you need to tweak it for a specific business case.
Your Profile already contains every tag, attribute and restriction you wish to, but for conformance, you want to create a "sub-profile" based on first.

This example suppose you override your Profile with a second one, and only shows the `execute()` method:

```
public function execute(): void
{
    if ($this->isExecuted === true) {
        return;
    }

    parent::execute();

    // Targets any tag (Definition)
    $this->target(Definition::class)
        // For a specific tag...
        ->for(
            PersonTag::class,
            fn ($self) => $self
                // Denies attributes based on name
                ->denies('attr-1', 'attr-2')
                // Deny an element based on its TypedAttribute class name
                ->denyElement(FullName::class)
        )
        // For a specific tag...
        ->for(
            Customer::class,
            fn ($self) => $self
                // Deny a single attribute based on name
                ->deny('attr-1')
                // Remove any `attributeGroup`
                ->removeGroups()
                // Merge a group into this Definition
                ->mergeGroup(CustomProperties::class)
        )
        // For these tags
        ->for(
            [
                Company::class,
                Warehouse::class,
            ],
            fn ($self) => $self
                // Allow a specific attribute "attr-x" with validation "StubString"
                ->allow(new TypedAttribute('attr-x', StubString::class))
        );

    $this->isExecuted = true;
}
```

Features
--------

[](#features)

This library supports:

- Full XSD definition of Choice and Sequence, with minOccurs and maxOccurs
- Attribute Groups with duplicates management
- Attributes with name and type
- Valid rendering of complex validations provided by XML-Utils library
- Fine-tuning of every element: names, references, types, attributes added or removed at runtime...

If you wish to see this library in action, please see Apache FOP profile compared to XSL-FO profile:

- [XSL-FO profile](https://github.com/ls-a-fr/xsl-core-php/blob/main/src/Xsd/Xsl/XslProfile.php)
- [Apache FOP Profile](https://github.com/ls-a-fr/xsl-core-php/blob/main/src/Xsd/Fop/FopProfile.php)
- [Apache FOP Extension Profile](https://github.com/ls-a-fr/xsl-core-php/blob/main/src/Xsd/Fop/FopExtensionProfile.php)

Why?
----

[](#why)

First, we could not find an XSD library that provides every aspect we needed:

- `davidbadura/xsd-builder` provides XSD build, but does not support choice, ability to fine-tune an existing XSD, or complex validations.
- `typo3/fluid-schema-generator` is abandoned and is dedicated to Fluid ViewHelpers.

As XSD isn't exactly fashionable these days, that's understandable. However, we believe strong structure validation of properties and inner elements in an Object-Oriented programming is (and always will be) an important part of validation. This library, built on top on XML-Utils, allows this validation layer.

Finally, for a bit of context, this package is used in [XSL-Core package](https://github.com/ls-a-fr/xsl-core-php), to ensure conformance on XSL-FO and Apache FOP XSD.

Installation
------------

[](#installation)

This library is available on Composer. Install it with:

```
composer require ls-a/xsd-generator
```

Changelog
---------

[](#changelog)

Please refer to the [CHANGELOG](CHANGELOG.md) file to see the latest changes.

Support
-------

[](#support)

We put our heart into delivering high-quality products that are accessible to everyone. If you like our work, don’t hesitate to reach out to us for your next project!

Contributing
------------

[](#contributing)

Contributions are governed by the [CONTRIBUTING](https://github.com/ls-a-fr/.github/CONTRIBUTING.md) file.

Security
--------

[](#security)

If you’ve found a bug or vulnerability, please contact us by email at  instead of opening an issue, in order to protect the security of other users.

Credits
-------

[](#credits)

- Renaud Berthier

License
-------

[](#license)

The MIT License (MIT). Please see License File for more information.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance70

Regular maintenance activity

Popularity8

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

185d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/190fe5341e199139e5f0a048b4b10e5cd07355c6b55ecaf6ca7ba41b65e97852?d=identicon)[renaudberthier](/maintainers/renaudberthier)

---

Top Contributors

[![renaudberthier](https://avatars.githubusercontent.com/u/1874017?v=4)](https://github.com/renaudberthier "renaudberthier (1 commits)")

---

Tags

xmlspecificationgeneratorxsdclassesW3C

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ls-a-xsd-generator/health.svg)

```
[![Health](https://phpackages.com/badges/ls-a-xsd-generator/health.svg)](https://phpackages.com/packages/ls-a-xsd-generator)
```

###  Alternatives

[veewee/xml

XML without worries

1835.9M29](/packages/veewee-xml)[goetas-webservices/xsd2php

Convert XSD (XML Schema) definitions into PHP classes and JMS metadata

2411.6M37](/packages/goetas-webservices-xsd2php)[goetas-webservices/xsd2php-runtime

Convert XSD (XML Schema) definitions into PHP classes

4910.9M36](/packages/goetas-webservices-xsd2php-runtime)[rumenx/php-sitemap

Framework-agnostic Sitemap generator for PHP, Laravel, and Symfony.

1.3k15.1k1](/packages/rumenx-php-sitemap)[goetas-webservices/xsd-reader

Read any XML Schema (XSD) programmatically with PHP

624.7M15](/packages/goetas-webservices-xsd-reader)[ultrono/laravel-sitemap

Sitemap generator for Laravel 11, 12 and 13

36412.6k6](/packages/ultrono-laravel-sitemap)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
