Download the PHP package mehr-it/easy-xml without Composer

On this page you can find all versions of the php package mehr-it/easy-xml. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package easy-xml

Easy-XML

Writing XML files

The XMLBuilder class offers a similar API as the PHP's XMLWriter. In fact it utilizes it internally. But most of the time this way of generating XML is not very intuitive and your source code does not reveal the XML structure clearly.

Therefore the XMLBuilder offers a powerful array based interface which reveals the XML structure in your PHP code. It's always a good idea if your source code reveals it's purpose at first glance.

Getting started

The following example demonstrates how to create a basic XML with nested nodes:

$builder = new XMLBuilder();
$builder
    ->beginDocument()
    ->write([
        'root' => [
            'child'        => 'content',
            'anotherChild' => 15
    ]);

The tag name is represented by the array key. The content is determined by the array value:

<?xml version="1.0" encoding="UTF-8"?>
<root>
    <child>content</child>
    <anotherChild>15</anotherChild>
</root>     

Adding attributes

To add attributes to our XML nodes, we prefix the key with an open XML bracket ("<") and pass an array with attribute names as keys prefixed with "@". The content is defined by the item simply named "@". Or you use an numeric array and specify the the tag name inside using the ">" key:

$builder->write([
    '<root' => [
        '@author' => 'Paul'
        '@age'    => 40,
        '@'       => [
            '<child' => [
                '@age' => '4'
                '@'    => 'Lukas'
            ],

            // alternative syntax:

            [
                '>'    => 'wife',
                '@age' => 36,
                '@'    => 'Lisa'
            ]
        ]
    ]
]);

As you see, you even can mix the different methods of defining XML nodes. The resulting XML would look like this:

<?xml version="1.0" encoding="UTF-8"?>
<root author="Paul" age="40">
    <child age="4">content</child>
    <wife age="36">Lisa</wife>
</root>

Multiple nodes with same name

Sometimes you need to define multiple siblings with the same name. There are two ways to do so. Either you wrap each node in an array or you use the ">" key to define the tag name:

$builder->write([
    'root' => [
        ['child' => 'Lukas'],
        ['child' => 'Sophie'],

        // alternative syntax:

        [
            '>' => 'child',
            '@' => 'Michael'
        ],
        [
            '>' => 'child',
            '@' => 'Zoe'
        ]
    ]
]);

Passing closures

Often the XML structure depends on the data to write. To keep a fluent interface and a visual structure of the XML in your source, you may pass a Closure to generate dynamic parts of your XML:

$builder->write([
    'root' => function(XMLBuilder $bld) use ($person) {
        if ($person instanceof Child)
            $bld->write(['child' => $person->getName()];
        else
            $bld->write(['adult' => $person->getName()];
    });

Upgrade notes

2.x


All versions of easy-xml with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1.0
ext-xmlwriter Version *
ext-mbstring Version *
ext-xmlreader Version *
ext-libxml Version *
mehr-it/php-decimals Version ^2.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mehr-it/easy-xml contains the following files

Loading the files please wait ....