加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 如何使用Xpath选择具有多个类的元素?

发布时间:2020-12-16 08:06:23 所属栏目:百科 来源:网络整理
导读:在上面的xml示例中,我想使用xpath选择属于类foo而不是在类bar中的所有书。 ?xml version="1.0" encoding="ISO-8859-1"?bookstore book class="foo" title lang="en"Harry Potter/title authorJ K. Rowling/author year2005/year price29.99/price /book boo
在上面的xml示例中,我想使用xpath选择属于类foo而不是在类bar中的所有书。
<?xml version="1.0" encoding="ISO-8859-1"?>
<bookstore>
  <book class="foo">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book class="foo bar">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
  <book class="foo bar">
    <title lang="en">Harry Potter</title>
    <author>J K. Rowling</author>
    <year>2005</year>
    <price>29.99</price>
  </book>
</bookstore>
通过用前导和尾随空格填充@class值,您可以测试“foo”和“bar”的存在,而不必担心它是第一个,中间还是最后,以及对“食物”的任何假阳性点击“barren”@class值:
/bookstore/book[contains(concat(' ',@class,' '),' foo ')
        and not(contains(concat(' ',' bar '))]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读