Download the PHP package danmichaelo/quitesimplexmlelement without Composer
On this page you can find all versions of the php package danmichaelo/quitesimplexmlelement. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download danmichaelo/quitesimplexmlelement
More information about danmichaelo/quitesimplexmlelement
Files in danmichaelo/quitesimplexmlelement
Package quitesimplexmlelement
Short Description QuiteSimpleXMLElement, formerly known as CustomXMLElement, is a simple wrapper around SimpleXmlElement for easier namespace handling
License MIT
Informations about the package quitesimplexmlelement
QuiteSimpleXMLElement
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
.
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.
The library is actively maintained and pull requests are welcome.
Why this library was developed
Taking an example document,
Using SimpleXMLElement I found myself having to register namespaces over and over again:
When using QuiteSimpleXMLElement, it should only be necessary to register the namespaces once and for all.
The namespaces can also be defined using the alternative constructor QuiteSimpleXMLElement::make
:
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.
Helper methods
The library defines some new methods to support less typing and cleaner code.
attr($name)
Returns the value of an attribute as a string. Namespace prefixes are supported.
text($xpath)
Returns the text content of the node
first($xpath)
Returns the first node that matches the given path, or null if none.
all($xpath)
Returns all nodes that matches the given path, or an empty array if none.
has($xpath)
Returns true if the node exists, false if not
setValue($value)
Sets the value of a node
replace($newNode)
Replaces the current node with a new one. Example:
gives
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.
All versions of quitesimplexmlelement with dependencies
ext-simplexml Version *