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..
The syntax for locating elements through XPath- Multiple Attribute can be written as: //<HTML tag>[@attribute_name1='attribute_value1'][@attribute_name2='attribute_value2]
If an xpath refers multiple elements on the DOM, It should be surrounded by brackets first () and then use numbering. if the xpath refers 4 elements in DOM and you need 3rd element then working xpath is (common xpath)[3].
Unlike ID attributes, every element in a web page has a unique XPath.
Using the XPath contains() function, we can extract all the elements on the page that match the provided text value. Here, tag: tag is the name of the tag that contains the specific word. word: In this case, the word refers to the text that must be discovered in a specific string.
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"]');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With