• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Extracting Node using Xpath

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic