How can I get H1,H2,H3 contents in one single xpath expression?
I know I could do this.
//html/body/h1/text()
//html/body/h2/text()
//html/body/h3/text()
and so on.
How can I get H1,H2,H3 contents in one single xpath expression?
I know I could do this.
//html/body/h1/text()
//html/body/h2/text()
//html/body/h3/text()
and so on.
Use:
/html/body/*[self::h1 or self::h2 or self::h3]/text()
The following expression is incorrect:
//html/body/*[local-name() = "h1"
or local-name() = "h2"
or local-name() = "h3"]/text()
because it may select text nodes that are children of unwanted:h1
, different:h2
, someWeirdNamespace:h3
.
Another recommendation: Always avoid using //
when the structure of the XML document is statically known. Using //
most often results in significant inefficiencies because it causes the complete document (sub)tree roted in the context node to be traversed.
Ingredients:
Tomato Purée, Acidity Regulator (Citric Acid)
How to get it using a single xpath.?? thanks in advance