Um pouco mais do que simples hack XML

Suponha que você tenha o seguinte arquivo xml

<?xml version="1.0" ?>
<parent>
<child>
Some text

<sub>more text</sub>
continued text

</child>
</parent>

Usar SimpleXML fornece um resultado como este

SimpleXMLElement Object
(
[child] =>
Some text

continued text

)

Esquisito. Eu escrevi um hack rápido para contornar isso. Comentários são bem-vindos.

function parseXML($xml) {
$xr
= new XMLReader();
$xr
->open($xml);

# Set variables for loop
$array
= array();
$openParentNode
= false;
$openChildNode
= false;
$setNode
= null;
$parentNode
= 'parent';
$triggerNodes
= array('child');

while($xr->read()) {
# If we hit the "parent" node, open it
if ($xr->name == $parentNode && !$openParentNode) {
$i
= count($array);
$openParentNode
= true;
$setNode
= $parentNode;
$array
[$i][$parentNode] = array();
} elseif ($xr->name == $parentNode && $openParentNode) {
$openParentNode
= false;
$setNode
= null;
}

# If the "parent" is open, process the title parameters
if ($openParentNode && (in_array($xr->name, $triggerNodes) || $xr->nodeType == XMLReader::TEXT)) {
# If one of the trigger nodes is hit, open it
if (in_array($xr->name, $triggerNodes) && $xr->name != $setNode) {
$openChildNode
= true;
$setNode
= $xr->name;
} elseif (in_array($xr->name, $triggerNodes) && $xr->name == $setNode) {
$openChildNode
= false;
$setNode
= $parentNode;
}

# Text node - throw it into the array
if ($openChildNode && $xr->nodeType == XMLReader::TEXT) {
$array
[$i][$parentNode][$setNode] = (isset($array[$i][$parentNode][$setNode])) ? $array[$i][$parentNode][$setNode].$xr->value : $xr->value;
}
}
}

return $array;
}