How to select multiple attributes for XPath query

Vainglory07 picture Vainglory07 · Dec 18, 2012 · Viewed 9.4k times · Source

Possible Duplicate:
How do I select multiple sets of attributes within an XML document using XPath?

My HTML code:

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

i want to select this table by specifying not only the width but also with cellpadding and cellspacing..

I am using this PHP code:

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

but it still displays the whole html source instead of what i want..
help me please..

Answer

BeniBela picture BeniBela · Dec 18, 2012

It seems like you do not want to select the attributes, but check if all of the attributes are there. I.e.:

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

Or if you want specifically the table, check the attributes for certain values?

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