2017 © Pedro Peláez
 

library php-to-xml

Simple class to convert PHP objects to XML, with tests.

image

salernolabs/php-to-xml

Simple class to convert PHP objects to XML, with tests.

  • Friday, April 28, 2017
  • by ericsalerno
  • Repository
  • 1 Watchers
  • 0 Stars
  • 20 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 11 % Grown

The README.md

salernolabs/php-to-xml

Latest Stable Version License Build Status, (*1)

Just a simple class that converts a PHP object to XML, with tests, and no SimpleXML requirement., (*2)

Yes, I'm fully aware of the existence of SimpleXMLElement::asXML() and solutions that use it., (*3)

Usage

First include the package in your project via composer., (*4)

composer require salernolabs/php-to-xml

An example usage would be something like this:, (*5)

$object = new \stdClass();
$object->hello = 'world';
$object->items = ['one', 'two', 'three'];
$object->samples = ['sample1'=>true, 'sample2'=>false, 'sample3'=>'I dunno!'];

$converter = new \SalernoLabs\PHPToXML\Convert();
$xml = $converter
    ->setObjectData($object)
    ->convert();

At this point, the value of $xml is expected to be a string with the following contents:, (*6)

<?xml version="1.0" encoding="utf-8"?>
<data>
    <hello>world</hello>
    <items>one</items>
    <items>two</items>
    <items>three</items>
    <samples>
        <sample1>1</sample1>
        <sample2></sample2>
        <sample3>I dunno!</sample3>
    </samples>
</data>

The converter is currently setup so multiple calls to convert() will return the last created data. Calls to setObjectData will clear the cache., (*7)

Limitations

I haven't added attribute or CDATA support in yet. It also doesn't collapse/remove empty nodes. Maybe later, pull requests welcome!, (*8)

The Versions

28/04 2017

dev-master

9999999-dev http://www.salernolabs.com/

Simple class to convert PHP objects to XML, with tests.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

php xml

28/04 2017

0.1.3

0.1.3.0 http://www.salernolabs.com/

Simple class to convert PHP objects to XML, with tests.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

php xml

14/04 2017

0.1.2

0.1.2.0 http://www.salernolabs.com/

Simple class to convert PHP objects to XML, with tests.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

php xml

14/04 2017

0.1.1

0.1.1.0 http://www.salernolabs.com/

Simple class to convert PHP objects to XML, with tests.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

php xml

14/04 2017

0.1.0

0.1.0.0 http://www.salernolabs.com/

Simple class to convert PHP objects to XML, with tests.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

php xml