Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Updating converter to work with additional test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Wilson committed Jul 17, 2014
1 parent 409bffd commit 827691f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/MarkWilson/XmlToJson/Tests/XmlToJsonConverterTest.php
Expand Up @@ -46,8 +46,8 @@ public function getConvertData()
'{"Metadata":{"SubscriptionCreate":{"-url":"http:\/\/www.google.com\/home#anchor"},"SubscriptionValidate":{"-url":"https:\/\/yahoo.com\/login","-required":"N"},"Studio":{"-email":"studio@gmail.com","-phone":"020 7607 3200"}}}'
],
[
'<Main><Sub><Child demo="something" another="something else" /><Child demo="something" another="something else" /><Child demo="something" another="something else" /></Sub></Main>',
'{"Main":{"Sub":{"Child":[{"-demo": "something,"-another":"something else"},{"-demo": "something,"-another":"something else"},{"-demo": "something,"-another":"something else"}]}}}'
'<Main><Child demo="something" another="something else" /><Child demo="something" another="something else" /><Child demo="something" another="something else" /></Main>',
'{"Main":{"Child":[{"-demo":"something","-another":"something else"},{"-demo":"something","-another":"something else"},{"-demo":"something","-another":"something else"}]}}'
]
];
}
Expand Down
8 changes: 7 additions & 1 deletion src/MarkWilson/XmlToJson/XmlToJsonConverter.php
Expand Up @@ -55,7 +55,13 @@ private function getData(\SimpleXMLElement $xml)
$data[$key] = array($data[$key], $childData);
}
} else {
$data[$key] = $childData;
$data[$key] = array($childData);
}
}

foreach ($data as $key => $value) {
if (is_array($value) && count($value) === 1) {
$data[$key] = $value[0];
}
}
} else {
Expand Down

0 comments on commit 827691f

Please sign in to comment.