|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-07-01 07:54 UTC] scruoge at gmail dot com
Description:
------------
XPath, selecting attribute returns SimpleXMLElement, which's children() method returns NULL.
Probably it's a documentation issue. It says
"Returns a SimpleXMLElement element, whether the node has children or not."
Test script:
---------------
<?php
$s = '<rootNode><childNode attr="attrval" attr2="attr2val">nodeContents</childNode></rootNode>';
$xml = new SimpleXMLElement($s);
$xpathres = $xml->xpath('childNode/@attr');
$xres = array_shift($xpathres);
$xres = array_shift($xml->xpath('childNode/@attr'));
echo '$xres->children() result: ';
var_dump($xres->children());
echo 'typecast result: ';
var_dump((string) $xres);
Expected result:
----------------
$xres->children() result: object(SimpleXMLElement)#2 (0) {
}
typecast result: string(7) "attrval"
Actual result:
--------------
$xres->children() result: NULL
typecast result: string(7) "attrval"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 23:00:01 2025 UTC |
There's extra string in the code that should be removed: (line 6) $xres = array_shift($xml->xpath('childNode/@attr')); It does not affect test script result, though it generates E_STRICT notice.