{"id":20016902,"url":"https://github.com/inspirum/xml-php","last_synced_at":"2025-05-04T22:31:47.586Z","repository":{"id":54738601,"uuid":"298284347","full_name":"inspirum/xml-php","owner":"inspirum","description":"Simple XML writer and memory efficient XML reader with powerful xml-to-array cast.","archived":false,"fork":false,"pushed_at":"2025-05-04T11:44:34.000Z","size":158,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-04T12:32:26.146Z","etag":null,"topics":["domdocument","php","xml","xml-parser","xml-parsing","xml-to-array","xml-to-json","xmlreader","xmlwriter"],"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/inspirum.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"docs/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"docs/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-09-24T13:16:15.000Z","updated_at":"2025-05-04T11:44:37.000Z","dependencies_parsed_at":"2023-02-06T05:15:32.883Z","dependency_job_id":"a3fe37ae-d0fc-4661-8a7b-a766e92fda93","html_url":"https://github.com/inspirum/xml-php","commit_stats":{"total_commits":56,"total_committers":2,"mean_commits":28.0,"dds":"0.017857142857142905","last_synced_commit":"dcddfcc2030920a5783627f25f8db386755c293d"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inspirum%2Fxml-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inspirum%2Fxml-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inspirum%2Fxml-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/inspirum%2Fxml-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/inspirum","download_url":"https://codeload.github.com/inspirum/xml-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252337175,"owners_count":21731837,"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":["domdocument","php","xml","xml-parser","xml-parsing","xml-to-array","xml-to-json","xmlreader","xmlwriter"],"created_at":"2024-11-13T08:13:38.589Z","updated_at":"2025-05-04T22:31:47.570Z","avatar_url":"https://github.com/inspirum.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XML reader / writer\n\n[![Latest Stable Version][ico-packagist-stable]][link-packagist-stable]\n[![Build Status][ico-workflow]][link-workflow]\n[![Coverage Status][ico-scrutinizer]][link-scrutinizer]\n[![Quality Score][ico-code-quality]][link-code-quality]\n[![PHPStan][ico-phpstan]][link-phpstan]\n[![Total Downloads][ico-packagist-download]][link-packagist-download]\n[![Software License][ico-license]][link-licence]\n\nSimple XML fluent writer and memory efficient XML reader.\n\n- Fluent builder build over [Document Object Model](https://www.php.net/manual/en/book.dom.php) with automatic CDATA escaping, namespace support and other features\n- Utilises [XMLReader](https://www.php.net/manual/en/book.xmlreader.php) and [Generator](https://www.php.net/manual/en/language.generators.overview.php) for memory efficient reading of large files\n- The entire code is covered by unit tests\n\n## Usage example\n\n*All the code snippets shown here are modified for clarity, so they may not be executable.*\n\n#### XML Writer\n\nWriting Google Merchant XML feed file\n\n```php\n/** @var Inspirum\\XML\\Builder\\DocumentFactory $factory */\n\n$locale       = 'cs';\n$currencyCode = 'CZK';\n\n$xml = $factory-\u003ecreate();\n$rss = $xml-\u003eaddElement('rss', [\n    'version' =\u003e '2.0',\n    'xmlns:g' =\u003e 'http://base.google.com/ns/1.0',\n]);\n\n$channel = $rss-\u003eaddElement('channel');\n$channel-\u003eaddTextElement('title', 'Google Merchant');\n$channel-\u003eaddTextElement('link', 'https://www.example.com');\n$channel-\u003eaddTextElement('description', 'Google Merchant products feed');\n$channel-\u003eaddTextElement('language', $locale);\n$channel-\u003eaddTextElement('lastBuildDate', (new \\DateTime())-\u003eformat('D, d M y H:i:s O'));\n$channel-\u003eaddTextElement('generator', 'Eshop');\n\nforeach ($products as $product) {\n    $item = $xml-\u003ecreateElement('item');\n    $item-\u003eaddTextElement('g:id', $product-\u003egetId());\n    $item-\u003eaddTextElement('title', $product-\u003egetName($locale));\n    $item-\u003eaddTextElement('link', $product-\u003egetUrl());\n    $item-\u003eaddTextElement('description', \\strip_tags($product-\u003egetDescription($locale)));\n    $item-\u003eaddTextElement('g:image_link', $product-\u003egetImageUrl());\n    foreach ($product-\u003egetAdditionalImageUrls() as $imageUrl) {\n        $item-\u003eaddTextElement('g:additional_image_link', $imageUrl);\n    }\n    $price = $product-\u003egetPrice($currencyCode);\n    $item-\u003eaddTextElement('g:price', $price-\u003egetOriginalPriceWithVat() . ' ' . $currencyCode);\n    if ($price-\u003einDiscount()) {\n        $item-\u003eaddTextElement('g:sale_price', $price-\u003egetPriceWithVat() . ' ' . $currencyCode);\n    }\n    if ($product-\u003ehasEAN()) {\n        $item-\u003eaddTextElement('g:gtin', $product-\u003egetEAN());\n    } else {\n        $item-\u003eaddTextElement('g:identifier_exists', 'no');\n    }\n    $item-\u003eaddTextElement('g:condition', 'new');\n    if ($product-\u003einStock()) {\n        $item-\u003eaddTextElement('g:availability', 'in stock');\n    } elseif ($product-\u003ehasPreorder()) {\n        $item-\u003eaddTextElement('g:availability', 'preorder');\n        $item-\u003eaddTextElement('g:availability_date', $product-\u003egetDeliveryDate());\n    } else {\n        $item-\u003eaddTextElement('g:availability', 'out of stock');\n    }\n    $item-\u003eaddTextElement('g:brand', $product-\u003egetBrand());\n    $item-\u003eaddTextElement('g:size', $product-\u003egetParameterValue('size', $locale));\n    $item-\u003eaddTextElement('g:color', $product-\u003egetParameterValue('color', $locale));\n    $item-\u003eaddTextElement('g:material', $product-\u003egetParameterValue('material', $locale));\n    if ($product-\u003eisVariant()) {\n        $item-\u003eaddTextElement('g:item_group_id', $product-\u003egetParentProductId()());\n    }\n    if ($product-\u003egetCustomAttribute('google_category') !== null) {\n        $item-\u003eaddTextElement('g:google_product_category', $product-\u003egetCustomAttribute('google_category'));\n    } elseif ($product-\u003egetMainCategory() !== null) {\n        $item-\u003eaddTextElement('g:product_type', $product-\u003egetMainCategory()-\u003egetFullname($locale));\n    }\n}\n\n$xml-\u003evalidate('/google_feed.xsd');\n\n$xml-\u003esave('/output/feeds/google.xml');\n\n/**\nvar_dump($xml-\u003etoString(true));\n\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003crss version=\"2.0\" xmlns:g=\"http://base.google.com/ns/1.0\"\u003e\n  \u003cchannel\u003e\n    \u003ctitle\u003eGoogle Merchant\u003c/title\u003e\n    \u003clink\u003ehttps://www.example.com\u003c/link\u003e\n    \u003cdescription\u003eGoogle Merchant products feed\u003c/description\u003e\n    \u003clanguage\u003ecs\u003c/language\u003e\n    \u003clastBuildDate\u003eSat, 14 Nov 20 08:00:00 +0200\u003c/lastBuildDate\u003e\n    \u003cgenerator\u003eEshop\u003c/generator\u003e\n    \u003citem\u003e\n      \u003cg:id\u003e0001\u003c/g:id\u003e\n      \u003ctitle\u003e\u003c![CDATA[Sample products #1 A\u0026B]]\u003e\u003c/title\u003e\n      \u003clink\u003ehttp://localhost/produkt/sample-product-1-a-b\u003c/link\u003e\n      \u003cdescription\u003eLorem ipsum dolor sit amet, consectetur adipisicing elit.\u003c/description\u003e\n      \u003cg:image_link\u003ehttp://localhost/images/no_image.webp\u003c/g:image_link\u003e\n      \u003cg:price\u003e19.99 CZK\u003c/g:price\u003e\n      \u003cg:gtin\u003e7220110003812\u003c/g:gtin\u003e\n      \u003cg:condition\u003enew\u003c/g:condition\u003e\n      \u003cg:availability\u003ein stock\u003c/g:availability\u003e\n      \u003cg:brand\u003eCo.\u003c/g:brand\u003e\n    \u003c/item\u003e\n    ...\n  \u003c/channel\u003e\n\u003c/rss\u003e\n*/\n```\n\n#### XML Reader\n\nReading data from Google Merchant XML feed\n\n```php\n/** @var \\Inspirum\\XML\\Reader\\ReaderFactory $factory */\n\n$reader = $factory-\u003ecreate('/output/feeds/google.xml');\n\n$title = $reader-\u003enextNode('title')-\u003egetTextContent();\n\n/**\nvar_dump($title);\n'Google Merchant'\n*/\n\n$lastBuildDate = $reader-\u003enextNode('lastBuildDate')-\u003egetTextContent();\n\n/**\nvar_dump($lastBuildDate);\n'2020-08-25T13:53:38+00:00'\n*/\n\n$price = 0.0;\nforeach ($reader-\u003eiterateNode('item') as $item) {\n    $data = $item-\u003etoArray();\n    $price += (float) $data['g:price'];\n}\n\n/**\nvar_dump($price);\n501.98\n*/\n```\n\nSplitting data to XML fragments by xpath (with valid namespaces)\n\n```php\n/** @var \\Inspirum\\XML\\Reader\\ReaderFactory $factory */\n$reader = $factory-\u003ecreate('/output/feeds/google.xml');\n\nforeach ($reader-\u003eiterateNode('/rss/channel/item', true) as $item) {\n    $data = $item-\u003etoString();\n    $id = ($item-\u003expath('/item/g:id')[0] ?? null)?-\u003egetTextContent()\n    // ...\n}\n```\n\n\n## System requirements\n\n* [PHP 8.2+](http://php.net/releases/8_2_0.php)\n* [ext-dom](http://php.net/dom)\n* [ext-json](http://php.net/json)\n* [ext-xmlreader](http://php.net/xmlreader)\n\n\n## Installation\n\nRun composer require command\n```bash\n$ composer require inspirum/xml\n```\nor add requirement to your `composer.json`\n```json\n\"inspirum/xml\": \"^3.0\"\n```\n\n## Usage\n\nAvailable framework integrations:\n\n- [Symfony](https://github.com/inspirum/xml-php-symfony)\n\nBut you can also use it without any framework implementation:\n\n```php\nuse Inspirum\\XML\\Builder\\DefaultDocumentFactory;\nuse Inspirum\\XML\\Builder\\DefaultDOMDocumentFactory;\nuse Inspirum\\XML\\Reader\\DefaultReaderFactory;\nuse Inspirum\\XML\\Reader\\DefaultXMLReaderFactory;\n\n$documentFactory = new DefaultDocumentFactory(new DefaultDOMDocumentFactory());\n$document = $documentFactory-\u003ecreate();\n// ...\n\n$readerFactory = new DefaultReaderFactory(new DefaultXMLReaderFactory(), $documentFactory);\n$reader = $readerFactory-\u003ecreate('/path/to/file.xml');\n// ...\n```\n\n\n#### XML Writer\n\nOptionally you can specify XML version and encoding (defaults to UTF-8).\n\n```php\nuse Inspirum\\XML\\Builder\\DefaultDocumentFactory;\n\n$factory = new DefaultDocumentFactory()\n\n$xml = $factory-\u003ecreate('1.0', 'WINDOWS-1250');\n/**\n\u003c?xml version=\"1.0\" encoding=\"WINDOWS-1250\"?\u003e\n*/\n\n$xml = $factory-\u003ecreate();\n/**\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n*/\n```\n\nNesting elements\n```php\n$a = $xml-\u003eaddElement('a');\n$a-\u003eaddTextElement('b', 'BB', ['id' =\u003e 1]);\n$b = $a-\u003eaddElement('b', ['id' =\u003e 2]);\n$b-\u003eaddTextElement('c', 'CC');\n\n/**\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ca\u003e\n  \u003cb id=\"1\"\u003eBB\u003c/a\u003e\n  \u003cb id=\"2\"\u003e\n    \u003cc\u003eCC\u003c/c\u003e\n  \u003c/b\u003e\n\u003c/a\u003e\n*/\n```\n\nUsed as fluent builder\n```php\n$xml-\u003eaddElement('root')-\u003eaddElement('a')-\u003eaddElement('b', ['id' =\u003e 1])-\u003eaddTextElement('c', 'CC');\n\n/**\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003croot\u003e\n  \u003ca\u003e\n    \u003cb id=\"2\"\u003e\n      \u003cc\u003eCC\u003c/c\u003e\n    \u003c/b\u003e\n  \u003c/a\u003e\n\u003c/root\u003e\n*/\n```\n\nAutomatic CDATA escaping\n```php\n$a = $xml-\u003eaddElement('a');\n$a-\u003eaddTextElement('b', 'me \u0026 you');\n$a-\u003eaddTextElement('b', '30\u0026nbsp;km');\n\n/**\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ca\u003e\n  \u003cb\u003e\n     \u003c![CDATA[me \u0026 you]]\u003e\n  \u003c/b\u003e\n  \u003cb\u003e\n    \u003c![CDATA[30\u0026nbsp;km]]\u003e\n  \u003c/b\u003e\n\u003c/a\u003e\n*/\n```\n\nForced CDATA escaping\n```php\n$a = $xml-\u003eaddElement('a');\n$a-\u003eaddTextElement('b', 'me');\n$a-\u003eaddTextElement('b', 'you', forcedEscape: true);\n\n/**\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ca\u003e\n  \u003cb\u003eme\u003c/b\u003e\n  \u003cb\u003e\n    \u003c![CDATA[you]]\u003e\n  \u003c/b\u003e\n\u003c/a\u003e\n*/\n```\n\nAdding XML fragments\n```php\n$a = $xml-\u003eaddElement('a');\n$a-\u003eaddXMLData('\u003cb\u003e\u003cc\u003eCC\u003c/c\u003e\u003c/b\u003e\u003cb\u003e0\u003c/b\u003e');\n$a-\u003eaddTextElement('b', '1');\n\n/**\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ca\u003e\n  \u003cb\u003e\n    \u003cc\u003eCC\u003c/c\u003e\n  \u003c/b\u003e\n  \u003cb\u003e0\u003c/b\u003e\n  \u003cb\u003e1\u003c/b\u003e\n\u003c/a\u003e\n*/\n```\n\nTo use automatic namespace usage you only have to set `xmlns:{prefix}` attribute on (usually) root element.\n\nElements (or/and attributes) use given prefix as `{prefix}:{localName}`, and it will be created with [`createElementNS`](https://php.net/manual/domdocument.createelementns.php) or [`createAttributeNS`](https://php.net/manual/domdocument.createattributens.php) method.\n```php\n$root = $xml-\u003eaddElement('g:root', ['xmlns:g' =\u003e'stock.xsd', 'g:version' =\u003e '2.0']);\n$items = $root-\u003eaddElement('g:items');\n$items-\u003eaddTextElement('g:item', 1);\n$items-\u003eaddTextElement('g:item', 2);\n$items-\u003eaddTextElement('g:item', 3);\n\n/**\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cg:root xmlns:g=\"stock.xsd\" g:version=\"2.0\"\u003e\n  \u003cg:items\u003e\n     \u003cg:item\u003e1\u003c/g:item\u003e\n     \u003cg:item\u003e2\u003c/g:item\u003e\n     \u003cg:item\u003e3\u003c/g:item\u003e\n  \u003c/a\u003e\n\u003c/root\u003e\n*/\n```\n\nNamespace support its necessary for XML validation with XSD schema\n\n```php\ntry {\n    $xml-\u003evalidate('/sample.xsd');\n    // valid XML\n} catch (\\DOMException $exception) {\n    // invalid XML\n}\n```\n\n#### XML Reader\n\n\u003e /sample.xml\n```xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cg:feed xmlns:g=\"stock.xsd\" g:version=\"2.0\"\u003e\n    \u003cg:updated\u003e2020-08-25T13:53:38+00:00\u003c/g:updated\u003e\n    \u003ctitle\u003e\u003c/title\u003e\n    \u003cg:items\u003e\n        \u003cg:item active=\"true\" price=\"99.9\"\u003e\n            \u003cg:id\u003e1\u003c/g:id\u003e\n            \u003cg:name\u003eTest 1\u003c/g:name\u003e\n        \u003c/g:item\u003e\n        \u003citem active=\"true\" price=\"19.9\"\u003e\n            \u003cg:id\u003e2\u003c/g:id\u003e\n            \u003cg:name\u003eTest 2\u003c/g:name\u003e\n        \u003c/item\u003e\n        \u003cg:item active=\"false\" price=\"0\"\u003e\n            \u003cg:id\u003e3\u003c/g:id\u003e\n            \u003cg:name\u003eTest 3\u003c/g:name\u003e\n        \u003c/g:item\u003e\n    \u003c/g:items\u003e\n\u003c/g:feed\u003e\n```\nReading XML files into [**Node**](./src/Builder/Node.php) instances\n\nRead next node with given name\n```php\n$node = $reader-\u003enextNode('g:updated');\n\n$node-\u003egetTextContent();\n/**\n'2020-08-25T13:53:38+00:00'\n*/\n\n$node-\u003etoString();\n/**\n\u003cg:updated\u003e2020-08-25T13:53:38+00:00\u003c/g:updated\u003e\n*/\n```\n\nPowerful cast to array method\n```php\n$data = $reader-\u003enextNode('g:items')-\u003etoArray();\n\n/**\nvar_dump($ids);\n[\n  'g:item' =\u003e [\n    0 =\u003e [\n      'g:id'        =\u003e '1'\n      'g:name'      =\u003e 'Test 1'\n      '@attributes' =\u003e [\n        'active' =\u003e 'true'\n        'price'  =\u003e '99.9'\n      ]\n    ]\n    1 =\u003e [\n      'g:id'        =\u003e '3'\n      'g:name'      =\u003e 'Test 3'\n      '@attributes' =\u003e [\n        'active' =\u003e 'false'\n        'price'  =\u003e '0'\n      ]\n    ]\n  ]\n  'item' =\u003e [\n    0 =\u003e [\n      'g:id'        =\u003e '2'\n      'g:name'      =\u003e 'Test 2'\n      '@attributes' =\u003e [\n        'active' =\u003e 'true'\n        'price'  =\u003e '19.9'\n      ]\n    ]\n  ]\n]\n*/\n```\n\n\nOptional config supported for `toArray` method\n\n```php\nuse Inspirum\\XML\\Builder\\DefaultDocumentFactory;\nuse Inspirum\\XML\\Formatter\\FullResponseConfig;\n\n$factory = new DefaultDocumentFactory()\n\n$config = new FullResponseConfig(\n    attributesName: '@attr', \n    valueName: '@val',\n    autoCast: true,\n);\n\n$data = $factory-\u003ecreateForFile('/sample.xml')-\u003etoArray($config);\n\n/**\nvar_dump($ids);\n[\n  '@attr'  =\u003e []\n  '@val'   =\u003e null\n  '@nodes' =\u003e [\n    'g:feed' =\u003e [\n      0 =\u003e [\n        '@attr'  =\u003e [\n          'g:version' =\u003e 2.0\n        ]\n        '@val'   =\u003e null\n        '@nodes' =\u003e [\n          'g:updated' =\u003e [\n            0 =\u003e [\n              '@attr'  =\u003e []\n              '@val'   =\u003e '2020-08-25T13:53:38+00:00'\n              '@nodes' =\u003e []\n            ]\n          ]\n          'title' =\u003e [\n            0 =\u003e [\n              '@attr'  =\u003e []\n              '@val'   =\u003e null\n              '@nodes' =\u003e []\n            ]\n          ]\n          'g:items' =\u003e [\n            0 =\u003e [\n              '@attr'  =\u003e []\n              '@val'   =\u003e null\n              '@nodes' =\u003e [\n                'g:item' =\u003e [\n                  0 =\u003e [\n                    '@attr'  =\u003e [\n                      'active' =\u003e true\n                      'price'  =\u003e 99.9\n                    ]\n                    '@val'   =\u003e null\n                    '@nodes' =\u003e [\n                      'g:id' =\u003e [\n                        0 =\u003e [\n                          '@attr'  =\u003e []\n                          '@val'   =\u003e 1\n                          '@nodes' =\u003e []\n                        ]\n                      ]\n                      'g:name' =\u003e [\n                        0 =\u003e [\n                          '@attr'  =\u003e []\n                          '@val'   =\u003e 'Test 1'\n                          '@nodes' =\u003e []\n                        ]\n                      ]\n                    ]\n                  ]\n                  1 =\u003e [\n                    '@attr'  =\u003e [\n                      'active' =\u003e false\n                      'price'  =\u003e 0\n                    ]\n                    '@val'   =\u003e null\n                    '@nodes' =\u003e \n                    [\n                      'g:id' =\u003e [\n                        0 =\u003e [\n                          '@attr'  =\u003e []\n                          '@val'   =\u003e 3\n                          '@nodes' =\u003e []\n                        ]\n                      ]\n                      'g:name' =\u003e [\n                        0 =\u003e [\n                          '@attr'  =\u003e []\n                          '@val'   =\u003e 'Test 3'\n                          '@nodes' =\u003e []\n                        ]\n                      ]\n                    ]\n                  ]\n                ]\n                'item' =\u003e [\n                  0 =\u003e [\n                    '@attr'  =\u003e [\n                      'active' =\u003e true\n                      'price'  =\u003e 19.9\n                    ]\n                    '@val'   =\u003e null\n                    '@nodes' =\u003e [\n                      'g:id' =\u003e [\n                        0 =\u003e [\n                          '@attr'  =\u003e []\n                          '@val'   =\u003e 2\n                          '@nodes' =\u003e []\n                        ]\n                      ]\n                      'g:name' =\u003e [\n                        0 =\u003e [\n                          '@attr'  =\u003e []\n                          '@val'   =\u003e 'Test 2'\n                          '@nodes' =\u003e []\n                        ]\n                      ]\n                    ]\n                  ]\n                ]\n              ]\n            ]\n          ]\n        ]\n      ]\n    ]\n  ]\n]\n*/\n```\n\nIterate all nodes with given name\n\n```php\n$ids = [];\nforeach ($reader-\u003eiterateNode('item') as $item) {\n    $ids[] = $item-\u003etoArray()['id'];\n}\n\n/**\nvar_dump($ids);\n[\n  0 =\u003e '1'\n  1 =\u003e '3'\n]\n*/\n```\n\nSplitting data to XML fragments (with valid namespaces)\n\n\n```php\n$items = [];\nforeach ($reader-\u003eiterateNode('g:item', true) as $item) {\n    $items[] = $item-\u003etoString();\n}\n\n/**\nvar_dump($items);\n[\n  0 =\u003e '\u003cg:item xmlns:g=\"stock.xsd\" active=\"true\" price=\"99.9\"\u003e\u003cg:id\u003e1\u003c/g:id\u003e\u003cg:name\u003eTest 1\u003c/g:name\u003e\u003c/g:item\u003e'\n  1 =\u003e '\u003cg:item xmlns:g=\"stock.xsd\" active=\"false\" price=\"0\"\u003e\u003cg:id\u003e3\u003c/g:id\u003e\u003cg:name\u003eTest 3\u003c/g:name\u003e\u003c/g:item\u003e'\n]\n*/\n```\n\n\n### All available methods\n\n- [`Inspirum\\XML\\Builder\\DocumentFactory`](./src/Builder/DocumentFactory.php)\n- [`Inspirum\\XML\\Builder\\Document`](./src/Builder/Document.php)\n- [`Inspirum\\XML\\Builder\\Node`](./src/Builder/Node.php)\n- [`Inspirum\\XML\\Reader\\ReaderFactory`](./src/Reader/ReaderFactory.php)\n- [`Inspirum\\XML\\Reader\\Reader`](./src/Reader/Reader.php)\n\n\n## Testing\n\nTo run unit tests, run:\n\n```bash\n$ composer test:test\n```\n\nTo show coverage, run:\n\n```bash\n$ composer test:coverage\n```\n\n\n## Contributing\n\nPlease see [CONTRIBUTING][link-contributing] and [CODE_OF_CONDUCT][link-code-of-conduct] for details.\n\n\n## Security\n\nIf you discover any security related issues, please email tomas.novotny@inspirum.cz instead of using the issue tracker.\n\n\n## Credits\n\n- [Tomáš Novotný](https://github.com/tomas-novotny)\n- [All Contributors][link-contributors]\n\n\n## License\n\nThe MIT License (MIT). Please see [License File][link-licence] for more information.\n\n\n[ico-license]:              https://img.shields.io/github/license/inspirum/xml-php.svg?style=flat-square\u0026colorB=blue\n[ico-workflow]:             https://img.shields.io/github/actions/workflow/status/inspirum/xml-php/master.yml?branch=master\u0026style=flat-square\n[ico-scrutinizer]:          https://img.shields.io/scrutinizer/coverage/g/inspirum/xml-php/master.svg?style=flat-square\n[ico-code-quality]:         https://img.shields.io/scrutinizer/g/inspirum/xml-php.svg?style=flat-square\n[ico-packagist-stable]:     https://img.shields.io/packagist/v/inspirum/xml.svg?style=flat-square\u0026colorB=blue\n[ico-packagist-download]:   https://img.shields.io/packagist/dt/inspirum/xml.svg?style=flat-square\u0026colorB=blue\n[ico-phpstan]:              https://img.shields.io/badge/style-level%2010-brightgreen.svg?style=flat-square\u0026label=phpstan\n\n[link-author]:              https://github.com/inspirum\n[link-contributors]:        https://github.com/inspirum/xml-php/contributors\n[link-licence]:             ./LICENSE.md\n[link-changelog]:           ./CHANGELOG.md\n[link-contributing]:        ./docs/CONTRIBUTING.md\n[link-code-of-conduct]:     ./docs/CODE_OF_CONDUCT.md\n[link-workflow]:            https://github.com/inspirum/xml-php/actions\n[link-scrutinizer]:         https://scrutinizer-ci.com/g/inspirum/xml-php/code-structure\n[link-code-quality]:        https://scrutinizer-ci.com/g/inspirum/xml-php\n[link-packagist-stable]:    https://packagist.org/packages/inspirum/xml\n[link-packagist-download]:  https://packagist.org/packages/inspirum/xml/stats\n[link-phpstan]:             https://github.com/phpstan/phpstan\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finspirum%2Fxml-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Finspirum%2Fxml-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Finspirum%2Fxml-php/lists"}