XPath get texts inside a "might existed" tag -
i have html contains tags below:
<div id="snt">text1</div> <div id="snt">text2</div> <div id="snt"><span style='color: #efffff'>text3</span></div> <div id="snt"><span style='color: #efffff'>text4</span></div> how can all texts included in <div> tags using xpath?
i.e.:
text1 text2 text3 text4
use:
//div[@id='snt']//text() this selects text node descendent of div element in xml document, has id attribute string value string "snt".
if want excclude whitespace-only text nodes selection, use:
//div[@id='snt']//text()[normalize-space()] this similar first xpath expression, each selected text node must have additional predicate satisfied -- value of normalize-space() function upon string contents non-empty string.
the value of normalize-space() function empty string when argument empty string itself, or string comprised of whitespace-only characters (space, nl, cr , tab).
Comments
Post a Comment