2014-04-04 32 views

回答

0

在XPath 1.0可以使用此:

//*[starts-with(@class,'hostHostGrid') and substring-after(@class,'_') = 'body'] 

選擇含有一個類任何元件。它將在任何情況下匹配標籤。這將符合以下所有三個要素:

<div class="hostHostGrid0_body"> 
    <span class="hostHostGrid123_body"/> 
    <b class="hostHostGrid1_body">xxx</b> 
</div> 

侷限性:它不限制什麼是一些他們之間。它可以是任何東西,包括空格(例如:它也將匹配該:class="hostHostGrid xyz abc_body"

這一個允許其他類中出現的類:

//*[contains(substring-before(@class,'_body'),'hostHostGrid')] 

它將匹配:

<div class="other-class hostHostGrid0_body"> 
    <span class="hostHostGrid123_body other-class"/> 
    <b class="hostHostGrid1_body">xxx</b> 
</div> 

(它也有相同的限制 - 將匹配'hostHostGrid'和'_body'之間的任何內容)