{"id":17472361,"url":"https://github.com/jackiedo/xml-array","last_synced_at":"2025-04-22T10:42:26.595Z","repository":{"id":33503374,"uuid":"158960392","full_name":"JackieDo/Xml-Array","owner":"JackieDo","description":"Simple tools to work with the conversion between xml and array.","archived":false,"fork":false,"pushed_at":"2022-05-30T09:37:53.000Z","size":56,"stargazers_count":8,"open_issues_count":2,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T11:54:26.866Z","etag":null,"topics":["array","array-2-xml","array-to-xml","convert","xml","xml-2-array","xml-to-array"],"latest_commit_sha":null,"homepage":null,"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/JackieDo.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":"2018-11-24T17:51:07.000Z","updated_at":"2023-06-02T22:16:05.000Z","dependencies_parsed_at":"2022-08-24T13:21:04.900Z","dependency_job_id":null,"html_url":"https://github.com/JackieDo/Xml-Array","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FXml-Array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FXml-Array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FXml-Array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JackieDo%2FXml-Array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JackieDo","download_url":"https://codeload.github.com/JackieDo/Xml-Array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249259146,"owners_count":21239422,"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":["array","array-2-xml","array-to-xml","convert","xml","xml-2-array","xml-to-array"],"created_at":"2024-10-18T17:08:44.925Z","updated_at":"2025-04-16T16:31:41.785Z","avatar_url":"https://github.com/JackieDo.png","language":"PHP","readme":"# Xml-Array\n\n[![Run tests](https://github.com/JackieDo/Xml-Array/actions/workflows/run-tests.yml/badge.svg)](https://github.com/JackieDo/Xml-Array/actions/workflows/run-tests.yml)\n[![Total Downloads](https://poser.pugx.org/jackiedo/xml-array/downloads)](https://packagist.org/packages/jackiedo/xml-array)\n[![Latest Stable Version](https://poser.pugx.org/jackiedo/xml-array/v/stable)](https://packagist.org/packages/jackiedo/xml-array)\n[![License](https://poser.pugx.org/jackiedo/xml-array/license)](https://packagist.org/packages/jackiedo/xml-array)\n\nThe conversion between xml and array becomes easier than ever. This package provides some very simple classes to convert XML to array and back.\n\n# Features of this package\n* Convert an XML object (DOMDocument, SimpleXMLElement) or well-formed XML string to an associative array or Json string.\n* Convert an associative array to well-formed XML string or DOMDocument.\n* Support parsing and building attributes, Cdata sections and namespaces of XML in conversion process.\n\n# Overview\nLook at one of the following sessions to learn more about this package.\n\n- [Xml-Array](#xml-array)\n- [Features of this package](#features-of-this-package)\n- [Overview](#overview)\n  - [Installation](#installation)\n  - [Basic usage](#basic-usage)\n    - [Convert from XML](#convert-from-xml)\n    - [Convert from array](#convert-from-array)\n  - [Advanced usage](#advanced-usage)\n    - [Set configuration](#set-configuration)\n      - [Method 1](#method-1)\n      - [Method 2](#method-2)\n      - [Method 3](#method-3)\n    - [Get configuration](#get-configuration)\n    - [Default configuration](#default-configuration)\n      - [For Xml2Array](#for-xml2array)\n      - [For Array2Xml](#for-array2xml)\n    - [Effect of configuration settings](#effect-of-configuration-settings)\n      - [version](#version)\n      - [encoding](#encoding)\n      - [standalone](#standalone)\n      - [attributesKey, cdataKey, valueKey](#attributeskey-cdatakey-valuekey)\n      - [namespacesOnRoot](#namespacesonroot)\n      - [rootElement](#rootelement)\n      - [keyFixer](#keyfixer)\n- [License](#license)\n\n## Installation\nYou can install this package through [Composer](https://getcomposer.org).\n\n```shell\n$ composer require jackiedo/xml-array\n```\n\n## Basic usage\n\n### Convert from XML\n\nWeb have two following methods:\n\n**Convert to array**:\n\n```php\nXml2Array::convert(DOMDocument|SimpleXMLElement|string $inputXML)-\u003etoArray();\n```\n\n**Convert to Json**:\n\n```php\nXml2Array::convert(DOMDocument|SimpleXMLElement|string $inputXML)-\u003etoJson(int $flag = 0);\n```\n\n\u003e **Note:** The input XML can be one of types DOMDocument object, SimpleXMLElement object or well-formed XML string.\n\n**Example 1**: - _(Convert from XML string)_\n\n```php\nuse Jackiedo\\XmlArray\\Xml2Array;\n...\n\n$xmlString = '\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n    \u003croot_node\u003e\n        \u003ctag\u003eExample tag\u003c/tag\u003e\n\n        \u003cattribute_tag description=\"This is a tag with attribute\"\u003eAnother tag with attributes\u003c/attribute_tag\u003e\n\n        \u003ccdata_section\u003e\u003c![CDATA[ This is CDATA section ]]\u003e\u003c/cdata_section\u003e\n\n        \u003ctag_with_subtag\u003e\n            \u003csub_tag\u003eSub tag 1\u003c/sub_tag\u003e\n            \u003csub_tag\u003eSub tag 2\u003c/sub_tag\u003e\n        \u003c/tag_with_subtag\u003e\n\n        \u003cmixed_section\u003e\n            Hello\n\n            \u003c![CDATA[ This is another CDATA section ]]\u003e\n\n            \u003csection id=\"sec_1\"\u003eSection number 1\u003c/section\u003e\n            \u003csection id=\"sec_2\"\u003eSection number 2\u003c/section\u003e\n            \u003csection id=\"sec_3\"\u003eSection number 3\u003c/section\u003e\n        \u003c/mixed_section\u003e\n\n        \u003cexample:with_namespace xmlns:example=\"http://example.com\"\u003e\n            \u003cexample:sub\u003eContent\u003c/example:sub\u003e\n        \u003c/example:with_namespace\u003e\n    \u003c/root_node\u003e';\n\n$array = Xml2Array::convert($xmlString)-\u003etoArray();\n```\n\nAfter running this piece of code `$array` will contain:\n\n```php\n$array = [\n    \"root_node\" =\u003e [\n        \"tag\"           =\u003e \"Example tag\",\n        \"attribute_tag\" =\u003e [\n            \"@value\"      =\u003e \"Another tag with attributes\",\n            \"@attributes\" =\u003e [\n                \"description\" =\u003e \"This is a tag with attribute\"\n            ]\n        ],\n        \"cdata_section\" =\u003e [\n            \"@cdata\" =\u003e \"This is CDATA section\"\n        ],\n        \"tag_with_subtag\" =\u003e [\n            \"sub_tag\" =\u003e [\"Sub tag 1\", \"Sub tag 2\"]\n        ],\n        \"mixed_section\" =\u003e [\n            \"@value\"  =\u003e \"Hello\",\n            \"@cdata\"  =\u003e \"This is another CDATA section\",\n            \"section\" =\u003e [\n                [\n                    \"@value\"      =\u003e \"Section number 1\",\n                    \"@attributes\" =\u003e [\n                        \"id\" =\u003e \"sec_1\"\n                    ]\n                ],\n                [\n                    \"@value\"      =\u003e \"Section number 2\",\n                    \"@attributes\" =\u003e [\n                        \"id\" =\u003e \"sec_2\"\n                    ]\n                ],\n                [\n                    \"@value\"      =\u003e \"Section number 3\",\n                    \"@attributes\" =\u003e [\n                        \"id\" =\u003e \"sec_3\"\n                    ]\n                ]\n            ]\n        ],\n        \"example:with_namespace\" =\u003e [\n            \"example:sub\" =\u003e \"Content\"\n        ],\n        \"@attributes\" =\u003e [\n            \"xmlns:example\" =\u003e \"http://example.com\"\n        ]\n    ]\n]\n```\n\n**Example 2**: - _(Convert form XML object, such as SimpleXMLElement)_\n\n```php\nuse Jackiedo\\XmlArray\\Xml2Array;\n...\n\n$xmlObject = simplexml_load_file('https://www.vietcombank.com.vn/ExchangeRates/ExrateXML.aspx');\n$array     = Xml2Array::convert($xmlObject)-\u003etoArray();\n```\n\nThe result of above code is:\n\n```php\n$array = [\n    \"ExrateList\" =\u003e [\n        \"DateTime\" =\u003e \"11/26/2018 1:56:20 PM\",\n        \"Exrate\" =\u003e [\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"AUD\",\n                    \"CurrencyName\" =\u003e \"AUST.DOLLAR\",\n                    \"Buy\" =\u003e \"16724.09\",\n                    \"Transfer\" =\u003e \"16825.04\",\n                    \"Sell\" =\u003e \"17008.7\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"CAD\",\n                    \"CurrencyName\" =\u003e \"CANADIAN DOLLAR\",\n                    \"Buy\" =\u003e \"17412.21\",\n                    \"Transfer\" =\u003e \"17570.34\",\n                    \"Sell\" =\u003e \"17762.14\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"CHF\",\n                    \"CurrencyName\" =\u003e \"SWISS FRANCE\",\n                    \"Buy\" =\u003e \"23074.67\",\n                    \"Transfer\" =\u003e \"23237.33\",\n                    \"Sell\" =\u003e \"23538.02\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"DKK\",\n                    \"CurrencyName\" =\u003e \"DANISH KRONE\",\n                    \"Buy\" =\u003e \"0\",\n                    \"Transfer\" =\u003e \"3493.19\",\n                    \"Sell\" =\u003e \"3602.67\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"EUR\",\n                    \"CurrencyName\" =\u003e \"EURO\",\n                    \"Buy\" =\u003e \"26264.39\",\n                    \"Transfer\" =\u003e \"26343.42\",\n                    \"Sell\" =\u003e \"26736.61\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"GBP\",\n                    \"CurrencyName\" =\u003e \"BRITISH POUND\",\n                    \"Buy\" =\u003e \"29562.43\",\n                    \"Transfer\" =\u003e \"29770.83\",\n                    \"Sell\" =\u003e \"30035.68\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"HKD\",\n                    \"CurrencyName\" =\u003e \"HONGKONG DOLLAR\",\n                    \"Buy\" =\u003e \"2939.91\",\n                    \"Transfer\" =\u003e \"2960.63\",\n                    \"Sell\" =\u003e \"3004.95\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"INR\",\n                    \"CurrencyName\" =\u003e \"INDIAN RUPEE\",\n                    \"Buy\" =\u003e \"0\",\n                    \"Transfer\" =\u003e \"331.15\",\n                    \"Sell\" =\u003e \"344.15\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"JPY\",\n                    \"CurrencyName\" =\u003e \"JAPANESE YEN\",\n                    \"Buy\" =\u003e \"200.38\",\n                    \"Transfer\" =\u003e \"202.4\",\n                    \"Sell\" =\u003e \"207.05\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"KRW\",\n                    \"CurrencyName\" =\u003e \"SOUTH KOREAN WON\",\n                    \"Buy\" =\u003e \"19.07\",\n                    \"Transfer\" =\u003e \"20.07\",\n                    \"Sell\" =\u003e \"21.33\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"KWD\",\n                    \"CurrencyName\" =\u003e \"KUWAITI DINAR\",\n                    \"Buy\" =\u003e \"0\",\n                    \"Transfer\" =\u003e \"76615.44\",\n                    \"Sell\" =\u003e \"79621.23\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"MYR\",\n                    \"CurrencyName\" =\u003e \"MALAYSIAN RINGGIT\",\n                    \"Buy\" =\u003e \"0\",\n                    \"Transfer\" =\u003e \"5532.17\",\n                    \"Sell\" =\u003e \"5603.76\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"NOK\",\n                    \"CurrencyName\" =\u003e \"NORWEGIAN KRONER\",\n                    \"Buy\" =\u003e \"0\",\n                    \"Transfer\" =\u003e \"2674.72\",\n                    \"Sell\" =\u003e \"2758.55\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"RUB\",\n                    \"CurrencyName\" =\u003e \"RUSSIAN RUBLE\",\n                    \"Buy\" =\u003e \"0\",\n                    \"Transfer\" =\u003e \"349.9\",\n                    \"Sell\" =\u003e \"389.89\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"SAR\",\n                    \"CurrencyName\" =\u003e \"SAUDI RIAL\",\n                    \"Buy\" =\u003e \"0\",\n                    \"Transfer\" =\u003e \"6206.27\",\n                    \"Sell\" =\u003e \"6449.75\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"SEK\",\n                    \"CurrencyName\" =\u003e \"SWEDISH KRONA\",\n                    \"Buy\" =\u003e \"0\",\n                    \"Transfer\" =\u003e \"2536.35\",\n                    \"Sell\" =\u003e \"2600.19\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"SGD\",\n                    \"CurrencyName\" =\u003e \"SINGAPORE DOLLAR\",\n                    \"Buy\" =\u003e \"16775.66\",\n                    \"Transfer\" =\u003e \"16893.92\",\n                    \"Sell\" =\u003e \"17078.33\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"THB\",\n                    \"CurrencyName\" =\u003e \"THAI BAHT\",\n                    \"Buy\" =\u003e \"691.64\",\n                    \"Transfer\" =\u003e \"691.64\",\n                    \"Sell\" =\u003e \"720.49\"\n                ]\n            ],\n            [\n                \"@attributes\" =\u003e [\n                    \"CurrencyCode\" =\u003e \"USD\",\n                    \"CurrencyName\" =\u003e \"US DOLLAR\",\n                    \"Buy\" =\u003e \"23295\",\n                    \"Transfer\" =\u003e \"23295\",\n                    \"Sell\" =\u003e \"23385\"\n                ]\n            ]\n        ],\n        \"Source\" =\u003e \"Joint Stock Commercial Bank for Foreign Trade of Vietnam - Vietcombank\"\n    ]\n];\n```\n\n**Example 3**: - _(Convert to Json)_\n\n```php\n$jsonString = Xml2Array::convert($xmlString)-\u003etoJson(JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);\n```\n\n### Convert from array\n\nWe also have two following methods:\n\n**Convert to XML string**:\n\n```php\nArray2Xml::convert(array $array)-\u003etoXml(bool $prettyOutput = false);\n```\n\n**Convert to DOMDocument object**:\n\n```php\nArray2Xml::convert(array $array)-\u003etoDom();\n```\n\n**Example 4**:\n\n```php\nuse Jackiedo\\XmlArray\\Array2Xml;\n...\n\n// We will use array from the result of first example as input for this example\n$xmlString = Array2Xml::convert($array)-\u003etoXml(true);\n```\n\n**Example 5**:\n\n```php\n$domObject = Array2Xml::convert($array)-\u003etoDom();\n```\n\n## Advanced usage\n\n### Set configuration\nIf we want to change the settings for the conversion process, we can do it in the following ways:\n\n#### Method 1\n\n```php\n...\n$config = [\n    'valueKey' =\u003e '@text',\n    'cdataKey' =\u003e '@cdata-section',\n    ...\n];\n\n$array = Xml2Array::convert($inputXml, $config)-\u003etoArray();\n...\n\n// And for backward processing\n$xml = Array2Xml::convert($inputArray, $config)-\u003etoXml();\n```\n\n\u003e **Note**: Configuration is an array of parameters. For more details, see section [Default configuration](#default-configuration).\n\n#### Method 2\n\n```php\n$converter = new Xml2Array($config);\n$array     = $converter-\u003econvertFrom($inputXml)-\u003etoArray();\n```\n\n#### Method 3\n\n```php\n$converter = new Xml2Array;\n$array     = $converter-\u003esetConfig($config)-\u003econvertFrom($inputXml)-\u003etoArray();\n```\n\n### Get configuration\nIf we implemented the conversion process using methods 2 and 3, we can get configuration of the conversion with method:\n\n```php\n$config = $converter-\u003egetConfig();\n```\n\n### Default configuration\n\n#### For Xml2Array\n\n```php\n$defaultConfig = [\n    'version'          =\u003e '1.0',         // Version of XML document\n    'encoding'         =\u003e 'UTF-8',       // Encoding of XML document\n    'standalone'       =\u003e null,          // Standalone directive for XML document\n    'attributesKey'    =\u003e '@attributes', // The key name use for storing attributes of node\n    'cdataKey'         =\u003e '@cdata',      // The key name use for storing value of Cdata Section in node\n    'valueKey'         =\u003e '@value',      // The key name use for storing text content of node\n    'namespacesOnRoot' =\u003e true           // Collapse all the namespaces at the root node, otherwise it will put in the nodes for which the namespace first appeared.\n];\n```\n\n#### For Array2Xml\n\n```php\n$defaultConfig = [\n    'version'       =\u003e '1.0',         // Version of XML document\n    'encoding'      =\u003e 'UTF-8',       // Encoding of XML document\n    'standalone'    =\u003e null,          // Standalone directive for XML document\n    'attributesKey' =\u003e '@attributes', // The key name use for storing attributes of node\n    'cdataKey'      =\u003e '@cdata',      // The key name use for storing value of Cdata Section in node\n    'valueKey'      =\u003e '@value',      // The key name use for storing text content of node\n    'rootElement'   =\u003e null,          // The name of root node will be create automatically in process of conversion\n    'keyFixer'      =\u003e true,          // The automatically key normalization will be used during conversion. It can be bool|string|numeric|callable\n];\n```\n\n### Effect of configuration settings\n\n#### version\n\n| Use in               | Data type |\n| -------------------- | --------- |\n| Xml2Array, Array2Xml | string    |\n\n**Effect**: This setting allows specifying the XML version to be generated (in Array2Xml), or reconstructed from the XML string (in Xml2Array)\n\n#### encoding\n\n| Use in               | Data type |\n| -------------------- | --------- |\n| Xml2Array, Array2Xml | string    |\n\n**Effect**: This setting is to indicate the encoding type of the XML to be generated (in Array2Xml), or reconstructed from the XML string (in Xml2Array)\n\n#### standalone\n\n| Use in               | Data type |\n| -------------------- | --------- |\n| Xml2Array, Array2Xml | null|bool |\n\n**Effect**: This setting is to allow the `standalone` directive to appear in the XML or not. If it is set to `null`, this directive will not appear.\n\n**Example**:\n\n```php\n$xml = Array2Xml::convert($array, [\n    'standalone' =\u003e true\n])-\u003etoXml(true);\n```\n\nContent in $xml will be\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?\u003e\n...\n```\n\n#### attributesKey, cdataKey, valueKey\n\n| Use in               | Data type |\n| -------------------- | --------- |\n| Xml2Array, Array2Xml | string    |\n\n**Effect**: This setting allows the use of special keywords to contain the values ​​of properties, CDATA section... during the conversion process.\n\n**Example**: Please review the examples above for more detailed understanding.\n\n#### namespacesOnRoot\n\n| Use in    | Data type |\n| --------- | --------- |\n| Xml2Array | bool      |\n\n**Effect**: This setting allows to collect all the parsed XML namespaces and place them in the root node. If it is set to `false`, the namespaces will be located at the nodes where it is declared.\n\n**Example**: We use the `Example 1` above again, but this time the configuration is different:\n\n```php\n$array = Xml2Array::convert($xmlString, [\n    'namespacesOnRoot' =\u003e false\n])-\u003etoArray();\n```\n\nAfter running this piece of code `$array` will contain:\n\n```php\n$array = [\n    \"root_node\" =\u003e [\n        \"tag\"           =\u003e \"Example tag\",\n        \"attribute_tag\" =\u003e [\n            \"@value\"      =\u003e \"Another tag with attributes\",\n            \"@attributes\" =\u003e [\n                \"description\" =\u003e \"This is a tag with attribute\"\n            ]\n        ],\n        ...\n        \"example:with_namespace\" =\u003e [\n            \"@attributes\" =\u003e [\n                \"xmlns:example\" =\u003e \"http://example.com\"\n            ]\n            \"example:sub\" =\u003e \"Content\"\n        ],\n    ]\n]\n```\n\nYou see, the `xlmns:example` namespace is put at the `example:with_namespace` key, not at `root_node` as it was originally.\n\n#### rootElement\n\n| Use in    | Data type |\n| --------- | --------- |\n| Array2Xml | string    |\n\n**Effect**: According to the Well-formed XML standard, the XML content is only allowed to have a single Root node. This setting allows to wrap all the elements of the original array into a single root node, instead of having to manually edit your array.\n\n#### keyFixer\n\n| Use in    | Data type                    |\n| --------- | ---------------------------- |\n| Array2Xml | bool|string|numeric|callable |\n\n**Effect**:\n\nAccording to the Well-formed XML standard, the tag names and attributes must satisfy a number of requirements, in which naming is specified as follows:\n\n- Only allowed to start with aphabet characters and underscore.\n- Only accept the `[a-zA-Z]`, `-`, `_`, `.`, `:` characters. In which, the `:` is used to indicate the namespace prefix.\n- Do not allow to end with `:`\n\nDuring conversion, array key names that violate these rules are automatically normalized. If you do not agree to this normalization, set this setting to `false`.\n\nBy default, this normalization replaces invalid characters with underscores (`_`). You can change to another character as you like.\n\n**Example**:\n\n```php\n// Do not use the key normalization\n$xml = Array2Xml::convert($array, [\n    'keyFixer' =\u003e false\n])-\u003etoXml();\n\n// Use the key normalization with default character (_)\n$xml = Array2Xml::convert($array, [\n    'keyFixer' =\u003e true\n])-\u003etoXml();\n\n// Replace with '---'\n$xml = Array2Xml::convert($array, [\n    'keyFixer' =\u003e '---'\n])-\u003etoXml();\n\n// Use a callable for fixing\n$xml = Array2Xml::convert($array, [\n    'keyFixer' =\u003e function ($key) {\n        $key = str_replace('/', '_', $key);\n        $key = str_replace('\\\\' , '.', $key);\n\n        return $key;\n    }\n])-\u003etoXml();\n```\n\n# License\n[MIT](LICENSE) © Jackie Do\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackiedo%2Fxml-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackiedo%2Fxml-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackiedo%2Fxml-array/lists"}