From: php at jacob-head dot com Operating system: Debian Testing (Lenny) PHP version: 5.2.6 PHP Bug Type: SimpleXML related Bug description: Suggestion: allow SimpleXMLElement->xpath() to return single SimpleXMLElement
Description: ------------ Currently SimpleXMLElement->xpath() returns an array comprised of SimpleXMLElements which match the xpath query. To manipulate the results it is therefore necessary to extract the elements from the array. This is not problematic for situations when one is using xpath to search for a number of nodes. However, when one searching for specific and unique elements, it would be helpful if rather than having xpath return an array comprised of the single element, it would be possible to have it return only the SimpleXMLElement object. My suggestion is that a second parameter, an integer, be added to the function. If used, SimpleXMLElement->xpath() would return the SimpleXMLElement object equivalent to that result. For example: $finalresult=$xml->xpath('[EMAIL PROTECTED]"XYZ"]', 1); would be the same as: $firstresult=$xml->xpath('[EMAIL PROTECTED]"XYZ"]'); $finalresult=$firstresult[0]; This would be useful as it would allow further manipulation of the element within a specific SimpleXML list of functions. For example: $xml->xpath('[EMAIL PROTECTED]"XYZ"]', 1)->addChild('new', 'element'); rather than the current: $firstresult=$xml->xpath('[EMAIL PROTECTED]"XYZ"]'); $firstresult[0]->addChild('new', 'element'); Equally, it would also allow stacking of xpath elements. E.g.: $finalresult=$xml->xpath('[EMAIL PROTECTED]"XYZ"]', 1)->xpath('[EMAIL PROTECTED]"ABC"]', 1); rather than the current: $firstresult=$xml->xpath('[EMAIL PROTECTED]"XYZ"]'); $secondresult=$firstresult[0]->xpath('[EMAIL PROTECTED]"ABC"]'); $finalresult=$secondresult[0]; Although this may seem like a small change, when dealing with large numbers of these calls it would be very helpful. Many thanks, -Jacob PS. This is my first attempt at a Wishlist Bug Report suggestion. I hope I have done everything correctly, but please accept my apologies if I have not! -- Edit bug report at http://bugs.php.net/?id=45201&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=45201&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=45201&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=45201&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=45201&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=45201&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=45201&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=45201&r=needscript Try newer version: http://bugs.php.net/fix.php?id=45201&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=45201&r=support Expected behavior: http://bugs.php.net/fix.php?id=45201&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=45201&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=45201&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=45201&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=45201&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=45201&r=dst IIS Stability: http://bugs.php.net/fix.php?id=45201&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=45201&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=45201&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=45201&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=45201&r=mysqlcfg