PHPackages                             danmichaelo/quitesimplexmlelement - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. danmichaelo/quitesimplexmlelement

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

danmichaelo/quitesimplexmlelement
=================================

Wrapper that adds easier namespace handling and some helper methods to SimpleXML.

v1.0.2(7y ago)69.8k↓33.3%6MITPHPPHP &gt;=5.6

Since Aug 17Pushed 7y ago3 watchersCompare

[ Source](https://github.com/danmichaelo/quitesimplexmlelement)[ Packagist](https://packagist.org/packages/danmichaelo/quitesimplexmlelement)[ RSS](/packages/danmichaelo-quitesimplexmlelement/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (7)Dependencies (3)Versions (17)Used By (6)

QuiteSimpleXMLElement
=====================

[](#quitesimplexmlelement)

[![Build Status](https://camo.githubusercontent.com/1334338280bc46501c82ece4e6deb2449594b0ac7bc77257a299c27dbeaecefc/687474703a2f2f696d672e736869656c64732e696f2f7472617669732f64616e6d69636861656c6f2f717569746573696d706c65786d6c656c656d656e742e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/danmichaelo/quitesimplexmlelement)[![Coverage Status](https://camo.githubusercontent.com/03097eaef6e2d2b6031b9334b1a70400d3cc46debc73d6d20d003e64e179bde0/687474703a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f64616e6d69636861656c6f2f717569746573696d706c65786d6c656c656d656e742e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/danmichaelo/quitesimplexmlelement?branch=master)[![Code Quality](https://camo.githubusercontent.com/f545113778c1fdbf28bb855d3adf2d71212e3842d0bac06bc58a6990cee67211/687474703a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f64616e6d69636861656c6f2f717569746573696d706c65786d6c656c656d656e742f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/danmichaelo/quitesimplexmlelement/?branch=master)[![SensioLabsInsight](https://camo.githubusercontent.com/130fc2f3b3ae22c34714f404399bc07dad9ae26788b744bd90cf295abce16b4f/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f32363534333133642d653465612d343864642d393063302d6331333836336431306333612f6d696e692e706e67)](https://insight.sensiolabs.com/projects/2654313d-e4ea-48dd-90c0-c13863d10c3a)[![Latest Stable Version](https://camo.githubusercontent.com/b02df4ea3921546f23c70435c95731d51793b460aaf92ac571b541bd49ec27f2/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64616e6d69636861656c6f2f717569746573696d706c65786d6c656c656d656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danmichaelo/quitesimplexmlelement)[![Total Downloads](https://camo.githubusercontent.com/9d99ad87d4da6eba06c937ec1598b30600149b1a6f097128786b8566b51752f4/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64616e6d69636861656c6f2f717569746573696d706c65786d6c656c656d656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/danmichaelo/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
------------------------------

[](#why-this-library-was-developed)

Taking an example document,

```
$xml = '

        1.9

  ';
```

Using SimpleXMLElement I found myself having to register namespaces over and over again:

```
$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.

```
$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`:

```
$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.

Helper methods
--------------

[](#helper-methods)

The library defines some new methods to support less typing and cleaner code.

### attr($name)

[](#attrname)

Returns the value of an attribute as a string. Namespace prefixes are supported.

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

### text($xpath)

[](#textxpath)

Returns the text content of the node

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

### first($xpath)

[](#firstxpath)

Returns the first node that matches the given path, or null if none.

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

#### all($xpath)

[](#allxpath)

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

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

### has($xpath)

[](#hasxpath)

Returns true if the node exists, false if not

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

### setValue($value)

[](#setvaluevalue)

Sets the value of a node

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

### replace($newNode)

[](#replacenewnode)

Replaces the current node with a new one. Example:

```
$book = new QuiteSimpleXMLElement('

		Chapter one

		Chapter two

');

$introduction = new QuiteSimpleXMLElement('

		Introduction

');

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

gives

```

        Introduction

        Chapter two

```

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.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community17

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 98.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~120 days

Recently: every ~179 days

Total

16

Last Release

2851d ago

Major Versions

v0.4.2 → v1.0.02017-07-01

PHP version history (3 changes)v0.1.0PHP &gt;=5.0.1

v0.4.0PHP &gt;=5.3

v1.0.0PHP &gt;=5.6

### Community

Maintainers

![](https://www.gravatar.com/avatar/87db1d80793d2adbeca18997c33acbb5cf1dec75ccc5c19f147d666dfbf2e990?d=identicon)[danmichaelo](/maintainers/danmichaelo)

---

Top Contributors

[![danmichaelo](https://avatars.githubusercontent.com/u/434495?v=4)](https://github.com/danmichaelo "danmichaelo (81 commits)")[![smoench](https://avatars.githubusercontent.com/u/183530?v=4)](https://github.com/smoench "smoench (1 commits)")

---

Tags

xml

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/danmichaelo-quitesimplexmlelement/health.svg)

```
[![Health](https://phpackages.com/badges/danmichaelo-quitesimplexmlelement/health.svg)](https://phpackages.com/packages/danmichaelo-quitesimplexmlelement)
```

###  Alternatives

[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[jms/serializer

Library for (de-)serializing data of any complexity; supports XML, and JSON.

2.3k135.8M851](/packages/jms-serializer)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)[jms/serializer-bundle

Allows you to easily serialize, and deserialize data of any complexity

1.8k89.3M627](/packages/jms-serializer-bundle)[hassankhan/config

Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files

97513.5M170](/packages/hassankhan-config)[sabre/xml

sabre/xml is an XML library that you may not hate.

52832.2M131](/packages/sabre-xml)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
