在xQuery中选择第n个子元素/选择下一个元素 [英] Select nth child in xQuery / select next element

查看:197
本文介绍了在xQuery中选择第n个子元素/选择下一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难找到好的xQuery教程,基本上我想做的是从这个html节点检索文本etc...

I am having trouble finding good xQuery tutorials, basically what I am trying to do is retreive the text etc... from this html node

<div class="venue">
    <div class="vitem">
        <p style="padding: 6px 0pt 0pt;" class="label">ADDRESS:</p>
        <p class="item-big">blabla</p>
    </div><br class="clear">
    <div class="vitem">
        <p style="padding: 6px 0pt 0pt;" class="label">PHONE:</p>
        <p class="item-big">123</p>
    </div><br class="clear">
    <div class="vitem">
        <p style="padding: 6px 0pt 0pt;" class="label">WEB:</p>
        <p class="item-big">etc...</p>
    </div><br class="clear">
</div>

我想知道如何从第三 div[@class="vitem"]
的第二p中获取数据 或紧随包含文本的WEB:

I'd like to know how can I get the data out of the 2nd p in the third div[@class="vitem"]
Or the p directly following the p[@class="label"] that contains the text WEB:

答案已经很有帮助,但是我的第二个问题是布局是否会更改为类似的内容

Answeres already helped a great bit, however my second question is if the layout changes to something like this

<div class="venue">
    <div class="vitem">
        <p style="padding: 6px 0pt 0pt;" class="label">ADDRESS:</p>
        <p class="item-big">blabla</p>
    </div><br class="clear">
    <div class="vitem">
        <p style="padding: 6px 0pt 0pt;" class="label">WEB:</p>
        <p class="item-big">etc...</p>
    </div><br class="clear">
</div>

我如何获得etc...,仅知道它跟在p后面且包含带有文本WEB:的类标签?它不再位于div [3]/p [2]

How do i get the etc..., knowing only that it follows a p with the class label containing the text WEB:? it's no longer in div[3]/p[2]

谢谢!

推荐答案

我想知道如何获得 第三个第二个p中的数据 div [@ class ="vitem"]

I'd like to know how can I get the data out of the 2nd p in the third div[@class="vitem"]

使用:

/*/div[@class='vitem'][3]/p[2]/text()

这意味着:获取具有属性class且值为"vitem"的所有div元素的第三个div元素的第二个p子元素的所有文本节点子元素./p>

This means: get all the text node children of the second p child of the third of all div elements that have an attribute class with value "vitem" and that are children of the top element.

或紧随其后的p p [@ class ="label"]和数据WEB:

Or the p directly following the p[@class="label"] with the data WEB:

使用:

/*/div[@class='vitem'][3]/p[@class='label']
                             /following-sibling::p[1]/text()

这意味着:获得具有值"label"class属性的任何p元素的第一个后继同级p的所有文本节点子级,即所有div的第三个子级属性值为"vitem"且为"vitem"且是顶部元素的子元素的元素.

This means: get all the text node children of the first following-sibling p of any p element with class attribute with value "label", that is a child of the third of all div elements that have an attribute class with value "vitem" and that are children of the top element.

更新:OP添加了第二个问题:他只想选择p作为字符串值的文本"etc ..."

UPDATE: The OP has added a second question: he wants just to select the p that has as a string value the text "etc..."

使用:

/*/div/p[.='etc...']

这篇关于在xQuery中选择第n个子元素/选择下一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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