permaculture playing cards*
The moose likes XML and Related Technologies and the fly likes Extracting Node using Xpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Extracting Node using Xpath" Watch "Extracting Node using Xpath" New topic
Author

Extracting Node using Xpath

ronnir paterl
Greenhorn

Joined: Oct 18, 2007
Posts: 11
Hi,

I am newbie in XML working with XPath. I am using Xpath to parse a code that looks like this






I am interested in extracting the node td, (or alternatively the node that has a total of 4 text nodes). I tried using //tr//text(), but it returns all (8) text nodes instead of 4.

Is there any way to specify a node by the number of children it has?

Any help is appreciated.

Thanks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

Well, sure. Whenever you are trying to select nodes which satisfy a particular condition, you would put that condition into an XPath predicate. And I believe XPath has a count() function: you could look that up.

However both the "td" elements in your example have five descendants which are text. Not four, there's a whitespace text node in both cases. So comparing the number of text descendants wouldn't help in this caswe.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Extracting Node using Xpath
 
Similar Threads
Parsing HTML Table using Java XPath
How to dynamically create or modify XSL
Fixed Table Header and changing classes
JSP returning old data, database was changed correctly!
Creating CSS class at runtime