Problems getting the nodeName with DomDocument

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux