I am having problems with the following functions where my return simply
is "#text Joe #text Smith #text unknown", it should have read
firstname Joe lastname Smith address unknown
What am I doing wrong?
<?php
$xmlstring =
"<element><firstname>Joe</firstname><lastname>Smith</lastname><address>unknown</address></element>";
$domdoc = new DomDocument();
$domdoc->loadXML($xmlstring);
$domroot = $domdoc->documentElement;
function process_children($node)
{
$children = $node->childNodes;
foreach ($children as $elem) {
if ($elem->nodeType == XML_TEXT_NODE) {
if (strlen(trim($elem->nodeValue))) {
$name = $elem->nodeName ;
$res = mb_convert_encoding(trim($elem->nodeValue),
'html', 'utf-8');
echo "$name $res \n";
}
} else if ($elem->nodeType == XML_ELEMENT_NODE) {
process_children($elem);
}
}
}
process_children($domroot);
?>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php