|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
[2011-04-08 21:08 UTC] jani@php.net
-Package: Feature/Change Request
+Package: SimpleXML related
[2014-06-24 07:31 UTC] ahmad dot almajdi at yahoo dot dk
[2016-01-07 12:34 UTC] contact at willianveiga dot com
[2024-06-12 11:23 UTC] ahdgwyf98 at gmail dot com
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 08:00:01 2025 UTC |
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('element[@called="XYZ"]', 1); would be the same as: $firstresult=$xml->xpath('element[@called="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('element[@called="XYZ"]', 1)->addChild('new', 'element'); rather than the current: $firstresult=$xml->xpath('element[@called="XYZ"]'); $firstresult[0]->addChild('new', 'element'); Equally, it would also allow stacking of xpath elements. E.g.: $finalresult=$xml->xpath('element[@called="XYZ"]', 1)->xpath('child[@named="ABC"]', 1); rather than the current: $firstresult=$xml->xpath('element[@called="XYZ"]'); $secondresult=$firstresult[0]->xpath('child[@named="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!