Re: Bug #14340: DOMXML is broken
| From: | Krzysztof Jarecki | Date: | Wed, 05 Dec 2001 15:31:24 +0000 |
| Subject: | Re: Bug #14340: DOMXML is broken | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-72623@lists.php.net to get a copy of this message | ||
Hi :)
You can find a fully working code down here.
It does not only works with the tagname problem but it also solves the
displaying of contents.
Right now only the textnode has a 'content' property.
<?
$string = '<?xml version="1.0"?>
<webcam_users>
<user>
<login>user1</login>
<password>passwd1</password>
</user>
<user>
<login>user2</login>
<password>passwd2</password>
</user>
<user>
<login>guest</login>
<password>guest_passwd</password>
</user>
</webcam_users>';
$doc = xmldoc($string);
if (false == $doc)
{
die('The input XML is bad formed');
}
$root = $doc->root();
$users = $root->children();
foreach ($users as $user)
{
if ($user->type == "1")
{
file://$nom = $user->tagname;
file://print "balise: ".$nom."<BR>";
$login=find_content($user, 'login');
if (false != $login)
{
echo 'Login: '.$login;
}
echo '<br/>';
$pazz=find_content($user, 'password');
if (false != $login)
{
echo 'Pazz: '.$pazz;
}
echo '<br/>';
}
}
function find_content($parent,$name)
{
$nodes = $parent->children();
while($node = array_shift($nodes))
{
if ($node->tagname == $name)
{
return get_content($node);
}
}
return false;
}
function get_content($domElement)
{
$children=$domElement->children();
return $children[0]->content;
}
?>