Skip to content

Commit 860e563

Browse files
committed
added @root elem tagname
1 parent 990b445 commit 860e563

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

test.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function prettyPrint($title, $thing)
1111
}
1212

1313
$xmlstr = <<<EOD
14-
<tv>
14+
<tv type="cartoon">
1515
<show name="Family Guy">
1616
<dog>Brian</dog>
1717
<kid>Chris</kid>
@@ -34,6 +34,11 @@ $xmlstr = <<<EOD
3434
EOD;
3535

3636
$expected = array(
37+
38+
"@root" => 'tv',
39+
40+
"@attributes" => array( "type" => "cartoon" ),
41+
3742
"show" => array(
3843

3944
array(

xmlstr_to_array.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
function xmlstr_to_array($xmlstr) {
1313
$doc = new DOMDocument();
1414
$doc->loadXML($xmlstr);
15-
return domnode_to_array($doc->documentElement);
15+
$root = $doc->documentElement;
16+
$output = domnode_to_array($root);
17+
$output['@root'] = $root->tagName;
18+
return $output;
1619
}
1720

1821
function domnode_to_array($node) {

0 commit comments

Comments
 (0)