Xpath如果包含

时间:2016-07-30 10:47:57

标签: xml xpath

如果说明tasg包含特定文本,我想提取值。

输入:

<section class='question-other-answers'>

	<article>
		<div class='user' </div>
		
		<div class='details'> 
		
			<p class='content'>
				exampleXYZexample
			</p>	
		</div>
		
		<div class='info'>
			<div class='rating'>

				<div class='rate-up'>

					<a>123456789</a>

				</div>
				
				<div class='rate-down'>

					<a>123456789</a>

				</div>	
			</div>

		</div>
		

	</article>


</section>

我想做的是: 如果rate-up包含<p class='content'>

,则会提取每个XYZ

我知道如何检查内容是否包含XYZ

//section[@class='question-other-answers']/article/div[2]/p and contains (.,'XYZ')

我知道如何获得rate-up

//section[@class='question-other-answers']/article/div[3]/div/div[1]/a

但我不知道如何将它们组合起来

1 个答案:

答案 0 :(得分:0)

谓词可以包含节点检查,所以

//section[@class='question-other-answers']/article[div[2]/p[@class = 'content' and contains (.,'XYZ')]]/div[3]/div/div[1]/a

是一种组合表达式的方法。