Download the PHP package bluem/xmltransformer without Composer

On this page you can find all versions of the php package bluem/xmltransformer. 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 xmltransformer

Build status

Overview

XMLTransformer is a PHP library for transforming any kind of input XML into an output string. This output string does not have to be XML, but can also be, for instance, HTML or plain text.

It has no dependencies besides PHP itself, no known bugs and 100% test coverage.

Transformations

XMLTransformer is able to …

When to use

In my opinion, XMLTransformer performs very well if the input XML and the output to be produced are similarly structured. Moreover, if data from the input XML has to be processed by an existing PHP codebase, it is possibly cleaner and simpler to use XMLTransformer instead of XSL-T.

When not to use

When the input data has to be re-arranged, you are probably better off with XSL-T, as this is something that XMLTransformer does not provide. (Although to some extent it can be done with appropriate callback code.) Of course you are free to combine XSL-T with XMLTransformer to get the best of both worlds, if one is not enough.

Installation

The recommended way to install this library is through Composer: composer require bluem/xmltransformer. As the library uses semantic versioning, you can define version constraints in composer.json so that any non-major updates are allowed.

Alternatively, you can clone the repository using git or download an archived release.

Usage

You pass the input XML and the name of a callback function or a callback method (specified as usual, using [$object, 'methodName'] syntax) or an anonymous function / closure to XMLTransformer.

For each tag (opening, closing or empty) the callback function will be called with the tag’s name, its attributes and information on whether it is an opening, empty or closing tag. Now, your function / method / closure can return one of three things:

Callback function arguments

The callback function / method / closure is called with three arguments:

Please note that the attributes will always be given, even for a closing tag.

The transformation description array

When you wish to perform a transformation, you must return an associative array. In this case, the following keys can be used:

Additionally, for handling attributes, array keys in the form of “@” can be used, where is the attribute name (with namespaces, if not from the default namespace). The value of such an array key can be one of:

For instance, this return array …

… means:

Please note that (as XMLTransformer is not restricted to produce XML) no automatic escaping is done to values returned by the array. Only exception: attribute values, as XMLTransformer assumes that if you set attribute values, you want XML or HTML output.

Passing attributes by reference

The callback can accept the arguments’ array by reference, therefore allowing direct manipulation of the attributes. This can be handy when changing or removing a large number of attributes or when only a prefix or suffix (or namespace) of attributes’ names is known in advance.

See below for an example.

Examples

All of the examples below assume that your code includes the usual boilerplate code for Composer autoloading:

Hello world

Multilingual Hello world

Removing tags including all of their content

Changing attribute values

Adding, renaming and removing attributes

Modifying attributes by reference

Author & License

This code was written by Carsten Blüm (www.bluem.net) and licensed under the BSD2 license.

Version history

3.0 (2024-10-27)

2.0.1 (2020-12-02)

2.0 (2018-02-12)

1.2 (2015-12-05)

1.1 (2015-08-15)

1.0 (2012-12-12)


All versions of xmltransformer with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-xmlreader 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 bluem/xmltransformer contains the following files

Loading the files please wait ....