Skip to content

Instantly share code, notes, and snippets.

@up1
Created January 12, 2010 09:58
Show Gist options
  • Save up1/275069 to your computer and use it in GitHub Desktop.
Save up1/275069 to your computer and use it in GitHub Desktop.
function readXml($domnode, &$array)
{
$array_ptr = &$array;
$domnode = $domnode->firstChild;
while (!is_null($domnode))
{
switch ($domnode->nodeType)
{
case XML_TEXT_NODE: if(!(trim($domnode->nodeValue) == ""))
$array_ptr['cdata'] = $domnode->nodeValue;
break;
case XML_CDATA_SECTION_NODE: if(!(trim($domnode->nodeValue) == ""))
$array_ptr['cdata'] = $domnode->nodeValue;
break;
case XML_ELEMENT_NODE:
$array_ptr = &$array[$domnode->nodeName][];
if ($domnode->hasAttributes() )
{
$attributes = $domnode->attributes;
foreach ($attributes as $index => $domobj)
{
$array_ptr[$domobj->name] = $domobj->value;
}
}
break;
}
if ( $domnode->hasChildNodes() )
{
$this->readXml($domnode, $array_ptr);
}
$domnode = $domnode->nextSibling;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment