2012-12-18 58 views
4

可能重複:
How do I select multiple sets of attributes within an XML document using XPath?如何選擇多個屬性的XPath查詢

我的HTML代碼:

<table width="100%" cellpadding="6" cellspacing="0"> 

我想不僅是指定選擇此表寬度,但也與cellpadding和cellspacing ..

我使用這個PHP代碼:

$query = $xpath->query('//table[@width|@cellpadding|@cellspacing]'); 

,但它仍然顯示整個HTML源代碼,而不是我想要的東西..
幫我請..

+0

實際上,我已經看到它,但它並沒有在我的情況下。可能我不知道如何使它在html..im新使用xpath ..我需要幫助:| |感謝您的迴應 – Vainglory07

回答

8

好像你不想選擇屬性,但檢查是否所有的屬性都存在。如:

$query = $xpath->query('//table[@width and @cellpadding and @cellspacing]'); 

或者如果你想特別的表,檢查屬性的某些值?

$query = $xpath->query('//table[@width = "100%" and @cellpadding = "6" and @cellspacing = "0"]');