Frage

I have the element $paragraph in my DOMDocument:

<p class=4textlist>
    String 1
    <p class=4textlist> String 1.1</p>
<p class=4textlist>String 1.2</p>
    String 2
</p>

At one moment, I selected the element and I would like to get all the p tags from this elements that have the class "4textlist".

For that, I have try:

$result = $xpath->query('descendent::p[@class="4textlist"]', $paragraph);

But this is not working. Any idea please ?

War es hilfreich?

Lösung

You've got a typo in your query, descendent vs. descendant. descendant::p[@class="4textlist"] works fine.

You might also consider .//p[@class="4textlist"].

Andere Tipps

Try this:

//p[@class="4textList"]
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top