Skip to content

Commit

Permalink
**3.3.0** (2022/03/10)
Browse files Browse the repository at this point in the history
* Fix namespaced attributes (Thank you Nitin Patel and Mirko Temperini [#10](#10))
  • Loading branch information
rquadling committed Mar 10, 2022
1 parent 6271c1f commit c42d6ba
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Version History

**3.3.0** (2022/03/10)

* Fix namespaced attributes (Thank you Nitin Patel and Mirko Temperini [#10](https://github.com/digitickets/lalit/issues/10))

**3.2.0** (2022/03/10)

* Allow alternative labels to be defined (Thank you Frank Aguirre [#16](https://github.com/digitickets/lalit/pull/16))
Expand Down
2 changes: 1 addition & 1 deletion src/XML2Array.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private static function convert(DOMNode $node)
if ($node->attributes->length) {
$a = [];
foreach ($node->attributes as $attrName => $attrNode) {
$a[$attrName] = $attrNode->value;
$a[$attrNode->nodeName] = $attrNode->value;
}
// if its an leaf node, store the value in @value instead of directly storing it.
if (!is_array($output)) {
Expand Down
16 changes: 14 additions & 2 deletions tests/MainLaLitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,17 @@ private function generateTags($tags)
],
VALID_TEST_FOR => ARRAY_TO_XML_ONLY,
],
'Namespaced attribute' => [
XML_CONTENT => ' xml:attribute7="namespaced"',
PHP_CONTENT => [
'@attributes' => [
'xml:attribute7' => 'namespaced',
],
],
VALID_TEST_FOR => ARRAY_TO_XML_ONLY,
],
'All attributes' => [
XML_CONTENT => ' attribute1="" attribute2="<important>" attribute3="1" attribute4="\'<important>\'" attribute5="\'\'" attribute6=""',
XML_CONTENT => ' attribute1="" attribute2="<important>" attribute3="1" attribute4="\'<important>\'" attribute5="\'\'" attribute6="" xml:attribute7="namespaced"',
PHP_CONTENT => [
'@attributes' => [
'attribute1' => '',
Expand All @@ -94,19 +103,21 @@ private function generateTags($tags)
'attribute4' => '\'<important>\'',
'attribute5' => '\'\'',
'attribute6' => null, // A null in PHP will become an empty value in XML.
'xml:attribute7' => 'namespaced',
],
],
VALID_TEST_FOR => ARRAY_TO_XML_ONLY,
],
'All attributes without null attribute' => [
XML_CONTENT => ' attribute1="" attribute2="&lt;important&gt;" attribute3="1" attribute4="\'&lt;important&gt;\'" attribute5="\'\'"',
XML_CONTENT => ' attribute1="" attribute2="&lt;important&gt;" attribute3="1" attribute4="\'&lt;important&gt;\'" attribute5="\'\'" xml:attribute7="namespaced"',
PHP_CONTENT => [
'@attributes' => [
'attribute1' => '',
'attribute2' => '<important>',
'attribute3' => '1',
'attribute4' => '\'<important>\'',
'attribute5' => '\'\'',
'xml:attribute7' => 'namespaced',
],
],
],
Expand Down Expand Up @@ -223,6 +234,7 @@ public function provideTestData()
return array_merge(
$this->generateTags(['root']),
$this->generateTags(['root', 'node']),
$this->generateTags(['root', 'xml:namespaced_node']),
$this->generateTags(['root', ['node', 2]]),
$this->generateTags(['root', 'collection', ['node', 2]]),
$this->generateTags(['root', ['collections', 2], ['node', 2]])
Expand Down

0 comments on commit c42d6ba

Please sign in to comment.