2017 © Pedro PelĂĄez
 

library quitesimplexmlelement

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

image

danmichaelo/quitesimplexmlelement

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  • Sunday, July 2, 2017
  • by danmichaelo
  • Repository
  • 2 Watchers
  • 3 Stars
  • 3,291 Installations
  • PHP
  • 6 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 7 % Grown

The README.md

QuiteSimpleXMLElement

Build Status Coverage Status Code Quality SensioLabsInsight Latest Stable Version Total Downloads, (*1)

The QuiteSimpleXMLElement class is a small wrapper built around the SimpleXMLElement class that adds some convenience methods and makes it easier to work with namespaces. The main reason for developing the class was to let objects returned by the xpath() method inherit namespaces from the original object. The package was formerly known as CustomXMLElement., (*2)

QuiteSimpleXMLElement supports PHP 5.6 and 7.x. If you need PHP 5.3 support, use the 0.4.* version range as PHP 5.3 support was removed in version 0.5., (*3)

The library is actively maintained and pull requests are welcome., (*4)

Why this library was developed

Taking an example document,, (*5)

$xml = '<root xmlns:dc="http://purl.org/dc/elements/1.1/">
    <dc:a>
      <dc:b >
        1.9
      </dc:a>
    </dc:b>
  </root>';

Using SimpleXMLElement I found myself having to register namespaces over and over again:, (*6)

$root = new SimpleXMLElement($xml);
$root->registerXPathNamespace('d', 'http://purl.org/dc/elements/1.1/');
$a = $root->xpath('d:a');
$a[0]->registerXPathNamespace('d', 'http://purl.org/dc/elements/1.1/');
$b = $a[0]->xpath('d:b');

When using QuiteSimpleXMLElement, it should only be necessary to register the namespaces once and for all., (*7)

$node = new QuiteSimpleXMLElement($xml);
$node->registerXPathNamespace('d', 'http://purl.org/dc/elements/1.1/');
$a = $node->xpath('d:a');
$b = $a->xpath('d:b');

The namespaces can also be defined using the alternative constructor QuiteSimpleXMLElement::make:, (*8)

$node = QuiteSimpleXMLElement::make($xml, ['d' => 'http://purl.org/dc/elements/1.1/']);
$a = $node->xpath('d:a');
$b = $a->xpath('d:b');

A note on the design: I would have preferred to extend the original SimpleXMLElement class, but the constructor is static, which is why I wrote a wrapper instead., (*9)

Helper methods

The library defines some new methods to support less typing and cleaner code., (*10)

attr($name)

Returns the value of an attribute as a string. Namespace prefixes are supported., (*11)

echo $node->attr('id');

text($xpath)

Returns the text content of the node, (*12)

echo $node->text('d:a/d:b');

first($xpath)

Returns the first node that matches the given path, or null if none., (*13)

$node = $node->first('d:a/d:b');

all($xpath)

Returns all nodes that matches the given path, or an empty array if none., (*14)

$node = $node->all('d:a/d:b');

has($xpath)

Returns true if the node exists, false if not, (*15)

if ($node->has('d:a/d:b') {
    …
}

setValue($value)

Sets the value of a node, (*16)

$node->setValue('Hello world');

replace($newNode)

Replaces the current node with a new one. Example:, (*17)

$book = new QuiteSimpleXMLElement('
<book>
    <chapter>
        <title>Chapter one</title>
    </chapter>
    <chapter>
        <title>Chapter two</title>
    </chapter>
</book>
');

$introduction = new QuiteSimpleXMLElement('
    <introduction>
        <title>Introduction</title>
    </introduction>
');

$firstChapter = $book->first('chapter');
$firstChapter->replace($introduction);

gives, (*18)

<?xml version="1.0"?>
<book>
    <introduction>
        <title>Introduction</title>
    </introduction>
    <chapter>
        <title>Chapter two</title>
    </chapter>
</book>

Works with namespaces as well, but any namespaces used in the replacement node must be specified in that document as well. See QuiteSimpleXMLElementTest.php for an example., (*19)

The Versions

02/07 2017

dev-master

9999999-dev

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • ext-simplexml *
  • php >=5.6

 

The Development Requires

by Dan Michael O. Heggø

xml

02/07 2017

v1.0.1

1.0.1.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-simplexml *

 

The Development Requires

by Dan Michael O. Heggø

xml

01/07 2017

v1.0.0

1.0.0.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.6
  • ext-simplexml *

 

The Development Requires

by Dan Michael O. Heggø

xml

11/08 2016

v0.4.2

0.4.2.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-simplexml *

 

The Development Requires

by Dan Michael O. Heggø

xml

11/08 2016

v0.4.1

0.4.1.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-simplexml *

 

The Development Requires

by Dan Michael O. Heggø

xml

11/08 2016

v0.4.0

0.4.0.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-simplexml *

 

The Development Requires

by Dan Michael O. Heggø

xml

07/01 2016

v0.3.0

0.3.0.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1
  • ext-simplexml *

 

The Development Requires

by Dan Michael O. Heggø

xml

14/05 2015

v0.2.5

0.2.5.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1
  • ext-simplexml *

 

The Development Requires

by Dan Michael O. Heggø

xml

16/12 2014

v0.2.4

0.2.4.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1
  • ext-simplexml *

 

The Development Requires

by Dan Michael O. Heggø

xml

06/07 2014

v0.2.3

0.2.3.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1
  • ext-simplexml *

 

The Development Requires

by Dan Michael O. Heggø

xml

17/05 2014

v0.2.1

0.2.1.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1

 

The Development Requires

by Dan Michael O. Heggø

xml

10/02 2014

v0.2.0

0.2.0.0

QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1

 

The Development Requires

by Dan Michael O. Heggø

xml

02/10 2013

v0.1.3

0.1.3.0

Simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1

 

The Development Requires

by Dan Michael O. Heggø

xml

31/08 2013

v0.1.2

0.1.2.0

Simple wrapper around SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1

 

The Development Requires

by Dan Michael O. Heggø

xml

17/08 2013

v0.1.1

0.1.1.0

Simple extension to SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1

 

by Dan Michael O. Heggø

17/08 2013

v0.1.0

0.1.0.0

Simple extension to SimpleXmlElement for easier namespace handling

  Sources   Download

MIT

The Requires

  • php >=5.0.1

 

by Dan Michael O. Heggø