Using XPath to select TD elements in a table with visible data

F

Foxpointe

I'm new to XPath so am sure my understanding is the issue here and could
use some help....

I've got some fairly messy (X)HTML which has TD elements sprinkled in
solely for the purposes of formatting (i.e. <td height="2"></td>) and
was thinking that I could use XPath to select only the TD nodes which
actually display a value. I've verified the basic path to get all
elements in the table (./html/body/table/tr), but when tried to extend
this with various permutations such as
../html/body/table/tr/td[string-length(text()) > 0] without success.

Thanks in advance,
Phil
 
R

Richard Tobin

./html/body/table/tr/td[string-length(text()) > 0] without success.

That should work, but you could just use

./html/body/table/tr/td[text()]

since empty ones won't have a text node at all.

-- Richard
 
F

Foxpointe

Richard said:
That should work, but you could just use

./html/body/table/tr/td[text()]

since empty ones won't have a text node at all.

-- Richard

It turns out it did work (user error ;-) but thanks for the tip as I
didn't realize I didn't need to explicitly check the length.

Thanks,
Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top