P
P
podust2014-07-31 21:24:19
HTML
podust, 2014-07-31 21:24:19

How to select two types of nodes at once in XPath?

I am parsing an HTML DOM document using XPath. There is a task to get a selection at once for two types of nodes located in the hierarchy at the same level. By p and h2 tags .
.//div[@class='article']/p
All I've been able to come up with so far is:
.//div[@class='article']/p | //h2
But such a query prints all p first , and only then all h2 , which does not solve the problem - it is necessary that the sequence of paragraphs and headings be observed.
What will the community suggest?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MrCarlione, 2015-05-12
@MrCarlione

I guess so. ".//div[@class='article']/p | following-sibling::h2".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question