xpath mysql,xpath查询是否具有像MySQL这样的Limit选项

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

For example:-

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

You see that LIMIT 0,100.

解决方案

You should be able to use "//*[firstname='Sheila' and position() <= 100]"

Edit:

Given the following XML:

Abu

Agartala

Agra

Ahmedabad

Ahmednagar

Aizwal

abcd

You can use the following XPath to get the first three cities:

//cityList/*[position()<=3]

Results:

Node element0 Abu

Node element1 Agartala

Node element2 Agra

If you want to limit this to nodes that start with element:

//cityList/*[substring(name(), 1, 7) = 'element' and position()<=3]

Note that this latter example works because you're selecting all the child nodes of cityList, so in this case Position() works to limit the results as expected. If there was a mix of other node names under the cityList node, you'd get undesirable results.

For example, changing the XML as follows:

Abu

Agartala

Agra

Ahmedabad

Ahmednagar

Aizwal

abcd

and using the above XPath expression, we now get

Node element0 Abu

Note that we're losing the second and third results, because the position() function is evaluating at a higher order of precedence - the same as requesting "give me the first three nodes, now out of those give me all the nodes that start with 'element'".

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值