Download the PHP package drmad/semeele without Composer
On this page you can find all versions of the php package drmad/semeele. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download drmad/semeele
More information about drmad/semeele
Files in drmad/semeele
Informations about the package semeele
Semeele
Extremely simple and minimalistic XML generator for PHP. Really, very simple.
I was using the native XML libraries to create an... XML document. But they are extremely verbose. So I coded this initially in about four hours.
It works with PHP 5.6 and newer versions, with mbstring
extension enabled.
Examples
And that's it. That prints:
A more complex, real-life example, used in signed UBL documents:
Outputs:
Installation and basic usage
Semeele
is available via Composer:
Alternatively, you can git clone
or download the ZIP from GitHub, and use this simple autoloader function (update constant SEMEELE_PATH
with the correct path as needed):
Drmad\Semeele\Node
Base class for all nodes. Its constructor has these parameters:
$nodeName
: Required.$content
: Optional. This is the node content. If an array is passed, it's used instead the$attribute
parameter.$attributes
: Optional. Array with['attribute name' => 'attribute value']
structure.$encoding
: Optional. Defaults to 'UTF-8'. Used to reencode$content
, and it's passed to child nodes created withchild()
andadd()
methods.
This class has two main methods for adding new child nodes: child()
and add()
. Both returns a Node
object, but child()
returns the newly created node, and add()
returns the current node, so you can keep adding new children to the same node.
All the arguments of both methods are passed to the Node
constructor.
Other methods are (except otherwise noted, all methods returns the affected Node
object):
parent()
: Returns the parent node. Used for 'going up the chain', perhaps after finished a run ofadd()
methods (take a look at the examples above).append(Node $node)
: Adds an already created node and its children to this node child tree.save(&$node)
: Saves the node in$node
. Useful for "returning" from a deep nested node.attr($name, $value)
: Adds new properties to this node. You can specify both arguments, or pass an associative array with multiple properties and values as first argument.comment($text)
: Adds a newDrmad\Semeele\Comment
node.
The final XML is generated with the getXML()
method, or just using the object in a string
context.
Drmad\Semeele\Document
This class extends Node
, and adds an XML declaration (using a Drmad\Semeele\ProcessingInstruction
class) before the node content. Its constructor has these parameters:
$rootNodeName
: Required. It will be the name of the mainNode
in the XML document.$version
: Optional. XML version, defaults to1.0
.$encoding
: Optional. XML encoding, defaults toUTF-8
.
You can obtain the XML declaration node with getDeclaration()
, perhaps to add new attributes, etc.
Drmad\Semeele\Cdata
Creates a CDATA value for escaping strings. Only useful if a human needs to read the XML, because all strings are always converted to XML entities when needed. E.g.:
Outputs:
All versions of semeele with dependencies
ext-mbstring Version *