tags:

views:

32

answers:

1

Hello,

I was wondering if it was possible to get a tag's contents only if has a given length (say, 300 characters) using XPath. Any help is welcome.

Thanks in advance

+2  A: 

Use:

XpathExpressionForTheElement[string-length() = 300]/text()

This selects the text nodes of all elements selected by XpathExpressionForTheElement the length of whose string value is 300.

This also assumes that the elements to be selected have only one text-node child.

Dimitre Novatchev
Thank you. I presume you don't know a nice tutorial on XPath queries ... :)
Tupak Goliam
@Tupak Goliam I always recommend my XPathVisualizer tool. It has been available for download at www.topxml.com since the year 2000 and many thousands of people have downloaded it and praise it. However, since recently the site has malware and if you decide to download the XPath Visualizer first equip yourself with a decent anti-malware tool. The link for the downlad is: http://www.topxml.com/editor/code_files/v20010929235959.zip
Dimitre Novatchev
'lenth' typo in answer (not enough rep to change)AquaPath is a similar visualisation tool for OS X, that I find similarly useful.
Jon Hadley
@Jon-Hadley: Thanks for noticing this. Fixed.
Dimitre Novatchev