I have an div elemet:
This is some text
This is a title
Some other content
<
To get the string value of div use:
string(/div)
This is the concatenation of all text nodes that are descendents of the (top) div element.
To select all text node descendents of div use:
/div//text()
To get only the text nodes that are direct children of div use:
/div/text()
Finally, get the first (and hopefully only) non-whitespace-only text node child of div:
/div/text()[not(normalize-space())][1]
You can use this XPath expression:
./div[1]/text()[1]
to test, I use this online tester : http://xpather.com/
expression like ./text() will retrieve only the content of root element only.
Regards, Nitin
What xpath expression should I use to only get the
divcontent without his child elementsh1anddiv
This XPath expression:
/div/node()[not(self::h1|self::div)]
It selects every div root element's children except those h1 or div elements.