The attribute is not a child XML node. For walking through attributes
SimpleXML has $node->attributes() method.
And if($node->attributes()) check works as expected.
So I think $node->children() must be just for child XML nodes, not for
attributes (there is no sense to give back results for attributes since we
have attributes() method).

Vesselin Kenashkov

On 5/22/07, kepbepos kepbepos <[EMAIL PROTECTED]> wrote:

Hi,
I'm not an expert, but in your example

--------
> $str = '<rootnode><subnode></subnode></rootnode>';
> $x = new SimpleXMLElement($str);
>
> if($x->subnode->children())
>     print 'yes';
>     else
>         print 'no';
> ---------
> will print 'no';


ok no children

If the
> $str='<rootnode><subnode><newnode></newnode></subnode></rootnode>';
> it will print yes.


ok has  one child: <newnode>

But the same will happen if the subnode has an attribute like:
> $str = '<rootnode><subnode id="2"></subnode></rootnode>';


I think is correct, in fact (if I'm right) an attribute is a child.
Following DOM the tree is:

rootnode
     |
subnode
     |
    id

Here an example explaining that
http://www.w3schools.com/dom/nodetree.gif

Please someone else to confirm.

See you

Reply via email to