Download the PHP package dcarbone/xml-writer-plus without Composer
On this page you can find all versions of the php package dcarbone/xml-writer-plus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download dcarbone/xml-writer-plus
More information about dcarbone/xml-writer-plus
Files in dcarbone/xml-writer-plus
Package xml-writer-plus
Short Description Simple XML Writer library for PHP 5.4+
License Apache-2.0
Homepage https://github.com/dcarbone/xml-writer-plus
Informations about the package xml-writer-plus
xml-writer-plus
Simple XML Writer library for PHP 5.4+
The goal of this library is to provide some added functionality to the built-in PHP XMLWriter class.
Inclusion in your Composer app
Add
To your application's file.
Learn more about Composer here: https://getcomposer.org/
Basic usage
To get started creating your own XML document:
The above will output:
Or, more legibly,
Namespaces
One of the features of the core XMLWriter class is the ability to add namespace prefixes and URI's to individual elements. It is also one of the more annoying features, as you have to manually define the NS and URI for each element.
To address this, I have added the following methods:
These methods interact with an internal associative array of . The methods:
Have all been modified to update this internal array. So if you do:
You will see:
This can then be used with:
Which will result in:
If you execute a call with a previously undefined namespace URI, NULL will be used (no xmlns attribute will be output).
Fun stuff
Lets say you have a XMLWriterPlus instance already open and an array already constructed, and you wish to just append the entire thing to the XML output without looping through and manually performing actions. Well, good sir/ma'am/fish, you can!
The above will output:
Expanded:
You may pass in objects as well:
The above will output:
Expanded:
Hash Key Notes:
- As seen above, you may pass in a hash key with a colon ('h:HashKey2', for instance) and XMLWriterPlus will automatically create a namespaced element.
- You may pass in an object instance of a custom class as long as the class implements some form of PHP's Iterator interface
- If you wish to have multiple elements with the same name at the same level, you must pass in an array as such:
All versions of xml-writer-plus with dependencies
ext-libxml Version *
ext-xmlwriter Version *
ext-mbstring Version *