Xpath 表达式 [英] Xpath expressions

查看:33
本文介绍了Xpath 表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取 元素的值,因为元素 的值为 2.请更正下面给出的 Xpath 表达式:

I am in need to get the value of <mathcolor> element for the element <colorvalue> has value 2. Please correct the Xpath expression given below:

尝试过 Xpath 表达式:

/colors/child::color/child::mathcolor[colorvalue='2']

示例 XML:

<?xml version="1.0"?>
<colors>
    <color>
        <mathcolor>#007dc5</mathcolor>
        <textcolor>C=100 M=40 Y=0 K=0</textcolor>
        <colorvalue>2</colorvalue>
    </color>
    <color>
        <mathcolor>#ed1b34</mathcolor>
        <textcolor>C=0 M=100 Y=85 K=0</textcolor>
        <colorvalue>3</colorvalue>
    </color>
</colors>

推荐答案

差不多,试试这个:

/colors/child::color[colorvalue='2']/child::mathcolor/text()

或者更简单

/colors/color[colorvalue='2']/mathcolor/text()

这篇关于Xpath 表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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