Does xpath query has Limit option like mysql

前端 未结 2 1579
余生分开走
余生分开走 2020-12-19 02:21

I want to limit number of result I receive from xpath query.

For example:-

$info = $xml->xpath(\"//*[firstname=\'Sheila\'] **LIMIT 0,100**\"); 
         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 03:05

    Ran into the same issue myself and had some issue with Geoffs answer as it, as he clearly describes, limits the number of elements returned before it performs the other parts of the query due to precedence.

    My solution is to add the position() < 10 as an additional conditional after my other conditions have been applied e.g.:

    //ElementsIWant[./ChildElementToFilterOn='ValueToSearchFor'][position() <= 10]/.
    

    Notice that I'm using two separate conditional blocks. This will first filter out elements that live up to my condition and secondly only take 10 of those.

提交回复
热议问题