使用xpath在svg下找到第n个孩子 [英] Find the nth child under svg using xpath

查看:157
本文介绍了使用xpath在svg下找到第n个孩子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为xv标签下的元素编写xpath.我想获得第二个rect节点.

I am writing xpath for elements present under svg tag. I want to get the 2nd rect node.

我的xpath找到了所有3个节点,而我的要求是仅找到第2个-

My xpath finds all 3 nodes, whereas my requirement is to find only the 2nd -

xpath://*[name()='svg']/*[name()='rect' and @fill='#919EF9']

HTML示例,

<svg width="400" height="110">
<rect id="yui_3_6_0_1_1435305312018_1190" x="35.5" y="60.5" width="68" height="117" stroke="#FFFFFF" stroke-width="1" fill="#919EF9" rx="0" ry="0">
<rect x="176.5" y="65.5" width="68" height="48" stroke="#FFFFFF" stroke-width="1" fill="#919EF9" rx="0" ry="0">
<rect x="316.5" y="30.5" width="68" height="70" stroke="#FFFFFF" stroke-width="1" fill="#919EF9" rx="0" ry="0">
</svg>

推荐答案

使用以下XPATH

//svg/rect[2]

这篇关于使用xpath在svg下找到第n个孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆