Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select multiple attributes for XPath query [duplicate]

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

like image 745
Vainglory07 Avatar asked Dec 18 '12 06:12

Vainglory07


People also ask

How do I combine two attributes in XPath?

The syntax for locating elements through XPath- Multiple Attribute can be written as: //<HTML tag>[@attribute_name1='attribute_value1'][@attribute_name2='attribute_value2]

How do you identify elements with the same XPath?

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

Is XPath unique for each element?

Unlike ID attributes, every element in a web page has a unique XPath.

How use attribute for contain in 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.


1 Answers

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"]');
like image 195
BeniBela Avatar answered Sep 28 '22 07:09

BeniBela