Download the PHP package spatie/array-to-xml without Composer

On this page you can find all versions of the php package spatie/array-to-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 array-to-xml

Convert an array to xml

Latest Version Tests Total Downloads

This package provides a very simple class to convert an array to an xml string.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Install

You can install this package via composer.

Usage

After running this piece of code $result will contain:

Setting the name of the root element

Optionally you can set the name of the rootElement by passing it as the second argument. If you don't specify this argument (or set it to an empty string) "root" will be used.

Handling key names

By default all spaces in the key names of your array will be converted to underscores. If you want to opt out of this behaviour you can set the third argument to false. We'll leave all keynames alone.

Adding attributes

You can use a key named _attributes to add attributes to a node, and _value to specify the value.

This code will result in:

Note, that the value of the _value field must be a string. (More)

Using reserved characters

It is also possible to wrap the value of a node into a CDATA section. This allows you to use reserved characters.

This code will result in:

If your input contains something that cannot be parsed a DOMException will be thrown.

Customize the XML declaration

You could specify specific values in for:

This will result in:

Adding attributes to the root element

To add attributes to the root element provide an array with an _attributes key as the second argument. The root element name can then be set using the rootElementName key.

Using a multi-dimensional array

Use a multi-dimensional array to create a collection of elements.

This will result in:

Using Closure values

The package can use Closure values:

This will result in:

Handling numeric keys

The package can also can handle numeric keys:

This will result in:

You can change key prefix with setter method called setNumericTagNamePrefix().

Using custom keys

The package can also can handle custom keys:

This will result in:

A custom key contains three, colon-separated parts: "__custom:[custom-tag]:[unique-string]".

a colon character can be included within the custom-tag portion by escaping it with a backslash:

This will result in:

Setting DOMDocument properties

To set properties of the internal DOMDocument object just pass an array consisting of keys and values. For a full list of valid properties consult https://www.php.net/manual/en/class.domdocument.php.

You can use the constructor to set DOMDocument properties.

Alternatively you can use setDomProperties

XML Prettification

Call $arrayToXml->prettify() method on ArrayToXml to set XML in pretty form.

Example:

With prettification:

will result in:

Without prettification:

will result in:

Dropping XML declaration

Call $arrayToXml->dropXmlDeclaration() method on ArrayToXml object to omit default XML declaration on top of the generated XML.

Example:

This will result in:

Adding processing instructions

Call $arrayToXml->addProcessingInstruction($target, $data) method on ArrayToXml object to prepend a processing instruction before the root element.

Example:

This will result in:

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

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


All versions of array-to-xml with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-dom Version *
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 spatie/array-to-xml contains the following files

Loading the files please wait ....