Download the PHP package stein197/xml-builder without Composer
On this page you can find all versions of the php package stein197/xml-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package xml-builder
PHP XML Builder
About
This package helps to create XML/HTML output directly from PHP code. The package generates very simplified node tree. Output can be generated by the tree in two ways - beautified output (all indentations and line feeds are present) and minified (without any intentations and line feeds). Also output can be generaten in two modes - HTML and XML mode (all tags are closed). The package generates valid HTML/XML markup and if you need - creates minified output on the fly.
To start using it include it via composer:
Examples
Simple example:
outputs:
Any method call on Builder
is proxied through __call()
method, so the name of the method == tag name. To create dashed tag name, call a method in camelCase:
To create namespaced element, call a method in snake_case:
If you need to place underscore, double the _
sign:
If you need tag which name contains invalid characters for PHP method, or if it points to already existing method, call tag()
method. The first argument is tag name others could be callbacks, attributes etc.:
All tag names are lowercased. To create CDATA section and XML comment call these methods respectively:
Comments are cut out in minified output.
To create <?xml?>
element, pass an array of attributes to the constructor:
__toString()
outputs minified HTML version by default. You can change the behaviour by calling stringify()
method directly:
Output of the second line:
Of course the level of nesting could be infinite:
You can create attributes and content of an element, by passing an array and arbitrary data as arguments to tag method:
Also you can pass another builder later if you need one:
In case if you need custom content for a tag, you should return non-null value from callback. Method calls on callback argument do not affect the tree, only returned value:
The order of arguments does not matter. Arrays are always attributes, while everything else is content. Multiple content arguments are concatenated, while only last array considered as attributes.
If an output is minified and a mode is HTML, then the empty elements do not have closing slash. List of self-clising HTML tags:
- area
- base
- br
- col
- embed
- hr
- img
- input
- link
- meta
- param
- source
- track
- wbr
- command
- keygen
- menuitem