Search code examples
phphtmlxpathdomdocumentdomxpath

How to select multiple attributes for XPath query


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..


Solution

  • 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"]');