Re: unexpected behaviour in SimpleXML (php 5.2.2)
| From: | Vesselin Kenashkov | Date: | Wed, 23 May 2007 17:06:55 +0000 |
| Subject: | Re: unexpected behaviour in SimpleXML (php 5.2.2) | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-29697@lists.php.net to get a copy of this message | ||
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 <kepbepos@gmail.com> 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| idHere an example explaining that http://www.w3schools.com/dom/nodetree.gif Please someone else to confirm. See you