Re: unexpected behaviour in SimpleXML (php 5.2.2)
| From: | kepbepos kepbepos | Date: | Tue, 22 May 2007 15:02:50 +0000 |
| Subject: | Re: unexpected behaviour in SimpleXML (php 5.2.2) | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-29663@lists.php.net to get a copy of this message | ||
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