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

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -