downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

DOMNode::insertBefore> <DOMNode::hasAttributes
Last updated: Fri, 06 Nov 2009

view this page in

DOMNode::hasChildNodes

(PHP 5)

DOMNode::hasChildNodes Checks if node has children

Description

bool DOMNode::hasChildNodes ( void )

This function checks if the node has children.

Return Values

Returns TRUE on success or FALSE on failure.

See Also



add a note add a note User Contributed Notes
DOMNode::hasChildNodes
jintoppy at gmail dot com
28-Apr-2009 11:13
<?php

$doc
= new DOMDocument;
$node = $doc->createElement("FirstMain", "First Main Node. This have child");
$doc->appendChild($node);
$childnode = $doc->createElement("childnode", "child node");
$node->appendChild($childnode);
$secondnode = $doc->createElement("SecondMain", "First Main Node. This don't have child");
$doc->appendChild($secondnode);
$doc->saveXML();
$nodeElmt = $doc->getElementsByTagName("FirstMain");
/*
if given as $nodeElmt = $doc->getElementsByTagName("childnode");
the output would be "This node has childnodes"

if given as $nodeElmt = $doc->getElementsByTagName("SecondMain");
the output would be "This node has no childnodes"

*/

foreach($nodeElmt as $nodeElmt)
{
if(
$nodeElmt->hasChildNodes())
{
echo
"This node has childnodes";
}
else
{
echo
"This node has no childnodes";
}
}

 
?>

- - - - - - - - - - - - - -

Output:

This node has childnodes

- - - - - - - - - - - - - -

DOMNode::insertBefore> <DOMNode::hasAttributes
Last updated: Fri, 06 Nov 2009
 
 
show source | credits | sitemap | contact | advertising | mirror sites