Fix #4: extra ->children() should show for prefixed root element

This commit is contained in:
Rowan Collins 2017-11-09 21:07:32 +00:00
parent f3238d95c0
commit 6ac7c40043
2 changed files with 29 additions and 20 deletions

View file

@ -124,11 +124,19 @@ function _simplexml_tree_recursively_process_node($item, $depth, $include_string
}
// To what namespace does this element belong? Returns array( alias => URI )
$item_ns = $item->getNamespaces(false);
if ( ! $item_ns )
// For top-level elements, cheat, and say they're in the null namespace, to force a ->children() call
if ( $depth == 1 )
{
$item_ns = array('' => NULL);
}
else
{
$item_ns = $item->getNamespaces(false);
if ( !$item_ns )
{
$item_ns = array('' => NULL);
}
}
// This returns all namespaces used by this node and all its descendants,
// whether declared in this node, in its ancestors, or in its descendants

View file

@ -1,18 +1,19 @@
SimpleXML object (1 item)
[0] // <movies>
->movie[0]
->title[0]
->characters[0]
->character[0]
->name[0]
->actor[0]
->character[1]
->name[0]
->actor[0]
->plot[0]
->great-lines[0]
->line[0]
->rating[0]
['type']
->rating[1]
['type']
->children('', true)
->movie[0]
->title[0]
->characters[0]
->character[0]
->name[0]
->actor[0]
->character[1]
->name[0]
->actor[0]
->plot[0]
->great-lines[0]
->line[0]
->rating[0]
['type']
->rating[1]
['type']