|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-08-14 01:12 UTC] cpriest at warpmail dot net
Description:
------------
Non-absolute paths using ->xpath() do not match appropriately. With the given example, changing the xpath to '/postresponse/status/@accept' correctly returns "no"
Reproduce code:
---------------
<?
$ResponseBody = '<?xml version="1.0" encoding="UTF-8"?><postresponse><status accept="no">INVALID</status></postresponse>';
$objXML = new SimpleXMLElement($ResponseBody);
$tMatches = $objXML->xpath('postresponse/status/@accept');
print_r((string)$tMatches[0]);
?>
Expected result:
----------------
"no"
Actual result:
--------------
xpath() returns no results
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 15 20:00:01 2025 UTC |
According to the specs: > Always returns an array of SimpleXMLElement objects. While the xpath() is actually returning a boolean value. Here is some revised code which demonstrates an incorrect return value: <?php require_once('inc.backend.interactive.php'); header('Content-Type: text/plain'); set_time_limit(0); $ResponseBody = '<?xml version="1.0" encoding="UTF-8"?><postresponse><status accept="no">INVALID</status></postresponse>'; $objXML = new SimpleXMLElement($ResponseBody); $tMatches = $objXML->xpath('postresponse/status/@accept'); print_r($tMatches); print_r(gettype($tMatches)); // print_r((string)$tMatches[0]); ?>