PHP 7.1.0 Released

DomNode->child_nodes

(PHP 4 >= 4.1.0)

DomNode->child_nodes Returns children of node

Description

array DomNode->child_nodes ( void )

Returns all children of the node.

See also domnode_next_sibling(), and domnode_previous_sibling().

add a note add a note

User Contributed Notes 4 notes

up
0
thibo1025 at hotmail dot fr
8 years ago
to avoid the "#text" what you can simply do without changing your xml file, is:

if($item->nodeName != "#text"){
// do your code.
}
up
0
arcana at yetta dot net
13 years ago
A better way to check for Text Child nodes (PHP 4.3.0)

    if ($childnode->node_type() == XML_TEXT_NODE)
    {
        echo "<br/>This item is a text node.";
    }
    else
    {
        echo "<br/>This item is not a text node.";
    }

You may want to look at DomElement->is_blank_node() as well.
up
0
jon.sprague(AT)itgco.com
14 years ago
To answer hrosas)at(linuxmail)dot(org.

<node>
<child/>
</node>

<node> has 3 children.
1. whitespace between <node> and <child/>
2. <child/>
3. whitespace between <child/> and </node>

The whitespace is treated like text. To avoid this remove all whitespace.

<node><child/></node>

This can get hard to read, but correct.

But, you can tell some programs to ignore the whitespace, so it remains easy to read.

Jon Sprague
up
0
hrosas)at(linuxmail)dot(org
14 years ago
I was using child_nodes and if I have a node like this.
<node>
    <child/>
</node>

the node <node> have two children: one the "    " spaces that appear as #text on php and <child/>. Is that normal? I think node has just one child <child/>
To Top