Reply to Problems getting the nodeName with DomDocument

Your name:

Reply:


Posted by Kenneth Andresen on 12/23/05 04:53

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);

?>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация