{"id":15696801,"url":"https://github.com/danmichaelo/quitesimplexmlelement","last_synced_at":"2025-10-28T15:05:46.659Z","repository":{"id":56962099,"uuid":"11175084","full_name":"danmichaelo/quitesimplexmlelement","owner":"danmichaelo","description":"Small wrapper around PHP's SimpleXMLElement","archived":false,"fork":false,"pushed_at":"2018-07-29T15:27:07.000Z","size":70,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-05-06T07:03:59.673Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danmichaelo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-04T11:31:57.000Z","updated_at":"2025-03-27T09:33:33.000Z","dependencies_parsed_at":"2022-08-21T10:20:45.967Z","dependency_job_id":null,"html_url":"https://github.com/danmichaelo/quitesimplexmlelement","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmichaelo%2Fquitesimplexmlelement","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmichaelo%2Fquitesimplexmlelement/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmichaelo%2Fquitesimplexmlelement/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmichaelo%2Fquitesimplexmlelement/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danmichaelo","download_url":"https://codeload.github.com/danmichaelo/quitesimplexmlelement/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253160727,"owners_count":21863624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T19:09:59.779Z","updated_at":"2025-10-28T15:05:41.622Z","avatar_url":"https://github.com/danmichaelo.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# QuiteSimpleXMLElement\n\n[![Build Status](http://img.shields.io/travis/danmichaelo/quitesimplexmlelement.svg?style=flat-square)](https://travis-ci.org/danmichaelo/quitesimplexmlelement)\n[![Coverage Status](http://img.shields.io/coveralls/danmichaelo/quitesimplexmlelement.svg?style=flat-square)](https://coveralls.io/r/danmichaelo/quitesimplexmlelement?branch=master)\n[![Code Quality](http://img.shields.io/scrutinizer/g/danmichaelo/quitesimplexmlelement/master.svg?style=flat-square)](https://scrutinizer-ci.com/g/danmichaelo/quitesimplexmlelement/?branch=master)\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/2654313d-e4ea-48dd-90c0-c13863d10c3a/mini.png)](https://insight.sensiolabs.com/projects/2654313d-e4ea-48dd-90c0-c13863d10c3a)\n[![Latest Stable Version](http://img.shields.io/packagist/v/danmichaelo/quitesimplexmlelement.svg?style=flat-square)](https://packagist.org/packages/danmichaelo/quitesimplexmlelement)\n[![Total Downloads](http://img.shields.io/packagist/dt/danmichaelo/quitesimplexmlelement.svg?style=flat-square)](https://packagist.org/packages/danmichaelo/quitesimplexmlelement)\n\nThe `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`. \n\nQuiteSimpleXMLElement 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.\n\nThe library is actively maintained and pull requests are welcome.\n\n## Why this library was developed\n\nTaking an example document,\n\n```php\n$xml = '\u003croot xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\u003e\n    \u003cdc:a\u003e\n      \u003cdc:b \u003e\n        1.9\n      \u003c/dc:a\u003e\n    \u003c/dc:b\u003e\n  \u003c/root\u003e';\n```\n\nUsing SimpleXMLElement I found myself having to register namespaces over and over again:\n\n```php\n$root = new SimpleXMLElement($xml);\n$root-\u003eregisterXPathNamespace('d', 'http://purl.org/dc/elements/1.1/');\n$a = $root-\u003expath('d:a');\n$a[0]-\u003eregisterXPathNamespace('d', 'http://purl.org/dc/elements/1.1/');\n$b = $a[0]-\u003expath('d:b');\n```\n\nWhen using QuiteSimpleXMLElement, it should only be necessary to register the namespaces once and for all.\n\n```php\n$node = new QuiteSimpleXMLElement($xml);\n$node-\u003eregisterXPathNamespace('d', 'http://purl.org/dc/elements/1.1/');\n$a = $node-\u003expath('d:a');\n$b = $a-\u003expath('d:b');\n```\n\nThe namespaces can also be defined using the alternative constructor `QuiteSimpleXMLElement::make`:\n\n```php\n$node = QuiteSimpleXMLElement::make($xml, ['d' =\u003e 'http://purl.org/dc/elements/1.1/']);\n$a = $node-\u003expath('d:a');\n$b = $a-\u003expath('d:b');\n```\n\nA 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.\n\n## Helper methods\n\nThe library defines some new methods to support less typing and cleaner code.\n\n### attr($name)\n\nReturns the value of an attribute as a string. Namespace prefixes are supported.\n\n```php\necho $node-\u003eattr('id');\n```\n\n### text($xpath)\n\nReturns the text content of the node\n\n```php\necho $node-\u003etext('d:a/d:b');\n```\n\n### first($xpath)\n\nReturns the first node that matches the given path, or null if none.\n\n```php\n$node = $node-\u003efirst('d:a/d:b');\n```\n\n#### all($xpath)\n\nReturns all nodes that matches the given path, or an empty array if none.\n\n```php\n$node = $node-\u003eall('d:a/d:b');\n```\n\n### has($xpath)\n\nReturns true if the node exists, false if not\n\n```php\nif ($node-\u003ehas('d:a/d:b') {\n\t…\n}\n```\n\n### setValue($value)\n\nSets the value of a node\n\n```php\n$node-\u003esetValue('Hello world');\n```\n\n### replace($newNode)\n\nReplaces the current node with a new one. Example:\n\n```php\n$book = new QuiteSimpleXMLElement('\n\u003cbook\u003e\n\t\u003cchapter\u003e\n\t\t\u003ctitle\u003eChapter one\u003c/title\u003e\n\t\u003c/chapter\u003e\n\t\u003cchapter\u003e\n\t\t\u003ctitle\u003eChapter two\u003c/title\u003e\n\t\u003c/chapter\u003e\n\u003c/book\u003e\n');\n\n$introduction = new QuiteSimpleXMLElement('\n\t\u003cintroduction\u003e\n\t\t\u003ctitle\u003eIntroduction\u003c/title\u003e\n\t\u003c/introduction\u003e\n');\n\n$firstChapter = $book-\u003efirst('chapter');\n$firstChapter-\u003ereplace($introduction);\n```\n\ngives\n\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003cbook\u003e\n    \u003cintroduction\u003e\n        \u003ctitle\u003eIntroduction\u003c/title\u003e\n    \u003c/introduction\u003e\n    \u003cchapter\u003e\n        \u003ctitle\u003eChapter two\u003c/title\u003e\n    \u003c/chapter\u003e\n\u003c/book\u003e\n```\n\nWorks with namespaces as well, but any namespaces used in the replacement node\nmust be specified in that document as well. See `QuiteSimpleXMLElementTest.php`\nfor an example.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanmichaelo%2Fquitesimplexmlelement","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanmichaelo%2Fquitesimplexmlelement","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanmichaelo%2Fquitesimplexmlelement/lists"}