2017 © Pedro Peláez
 

library exemel

Easyer reading and writing of XML documents

image

moccalotto/exemel

Easyer reading and writing of XML documents

  • Thursday, August 11, 2016
  • by moccalotto
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1,541 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

Exemel

Build Status, (*1)

Easily construct and modify XML documents using fluint API., (*2)

Installation

To add this package as a local, per-project dependency to your project, simply add a dependency on moccalotto/exemel to your project's composer.json file like so:, (*3)

{
    "require": {
        "moccalotto/exemel": "~0.1"
    }
}

Alternatively simply call composer require moccalotto/exemel, (*4)

Demo

<?php

require 'vendor/autoload.php';

function ensure($condition)
{
    if (!$condition) {
        throw new RuntimeException('Condition failed');
    }
}

$xml = new Moccalotto\Exemel\Xml(new SimpleXmlElement('<root/>'));
// <root />


/*
 * Add attr="attr0" to the root element
 */
$xml->set('[attr]', 'attr0');
ensure($xml->get('[attr]') == 'attr0');
ensure($xml->root()['attr'] == 'attr0');
// <root attr="attr0" />



/*
 * Add an element called <foo>
 * Inside that, add an element called <bar>
 * Set the contents of <bar> to "el1"
 */
$xml->set('foo/bar', 'el1');
ensure($xml->get('foo/bar') == 'el1');
ensure((string) $xml->root()->foo->bar == 'el1');
// <root attr="attr0">
//   <foo>
//     <bar>el1</bar>
//   </foo>
// </root>



/*
 * Add attr="attr1" to the newly added <bar> element
 */
$xml->set('foo/bar[ding]', 'attr1');
ensure($xml->get('foo/bar[ding]') == 'attr1');
ensure((string) $xml->root()->foo->bar['ding'] == 'attr1');
// <root attr="attr0">
//   <foo>
//     <bar ding="attr1">el1</bar>
//   </foo>
// </root>



/*
 * Add a new <foo> element to the root.
 * Inside that, add a <bar> element with the contents "el2"
 */
$xml->set('foo[]/bar', 'el2');
ensure($xml->get('foo[1]/bar') == 'el2');
ensure((string) $xml->root()->foo[1]->bar == 'el2');
// <root attr="attr0">
//   <foo>
//     <bar ding="attr1">el1</bar>
//   </foo>
//   <foo>
//     <bar>el2</bar>
//   </foo>
// </root>

echo $xml->formatted();

The Versions

11/08 2016

dev-master

9999999-dev

Easyer reading and writing of XML documents

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

xml

30/07 2016

0.4.1

0.4.1.0

Easyer reading and writing of XML documents

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

xml

28/06 2016

0.4.0

0.4.0.0

Easyer reading and writing of XML documents

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

xml

23/06 2016

0.3.0

0.3.0.0

Easyer reading and writing of XML documents

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

xml

22/06 2016

0.1.0

0.1.0.0

Easyer reading and writing of XML documents

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

xml

22/06 2016

0.0.1

0.0.1.0

Easyer reading and writing of XML documents

  Sources   Download

The Requires

  • php >=5.5.0

 

The Development Requires

xml