0

Basically I'm working with the following XML:

<div>
    <div>
    <b>E-mail:</b>
    <span>TheValue</span>
    </div>
    ... and more div tags
</div>

Keep in mind that there are lots of different div tags - but only one containing a tag with the innertext of "E-mail:".

What I want to parse is the value of the span tag where the bold tag equals "E-mail:".

I know I could do something like ("//div//div[contains(@text(), 'E-mail:')].innerText;

But I would like to do this by checking if the bold tag contains E-Mail and not just the innerText of the whole div tag.

4

1 回答 1

1
//div/div[b = 'E-mail:']/span/text()

但是最后一个text()是可选的

//div/div[b = 'E-mail:']/span

也可以。前者为您提供文本节点,后者为您提供<span>元素。

如果它们没有被包裹在 a<div>中,而只是彼此跟随:

//b[. = 'E-mail:']/following-sibling::span[1]

请注意,这.innerText是非标准的。您应该.textContent在现代浏览器中使用。

于 2013-10-14T15:56:17.360 回答