S
S
Shimpanze2017-08-12 10:37:04
XPath
Shimpanze, 2017-08-12 10:37:04

XPath: how to loop through all text nodes inside a paragraph?

Hello!
Guys, please tell me how to iterate over all text nodes inside, say, a paragraph? After all, they can be 2-3 levels.
Look, there is a paragraph:

<p>Lorem <i>ipsum dolor</i> sit <span>amet, <b><i>consectetur</i> adipisicing</b> elit</span>. Odit, sunt?</p>

I get the paragraph tag: How now to iterate over all these text nodes inside the paragraph here? It's just text. These ones:
.//p
foreach ($elements as $element) {
  // Lorem;
  // ipsum dolor;
  // sit;
  // amet,;
  // consectetur;
  // adipisicing;
  // elit;
  // . Odit, sunt?;
}

Explain to me once and for all how it's done.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
egor_nullptr, 2017-08-12
@Shimpanze

//p//text()
How to process only text nodes?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question