Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - how to access sibling node that do not have children [Thread Next] Re: how to access sibling node that do not have childrenTo: NULL Date: 4/5/2006 2:45:00 PM great Fez wrote: > I'm an xpath newbie and I'm trying to figure out how to return all > sibling nodes or child nodes that do not have children (so only go to > depth = 0 or 1). > > I have the following: > > <top> > <one></one> > <two></two> > <three></three> > <alpha1> > <letter1></letter1> > <letter2></letter2> > <beta> > <lettera></lettera> > <letterb></letterb> > </beta> > </alpha1> > <alpha2> > <letter1></letter1> > <letter2></letter2> > <beta> > <lettera></lettera> > <letterb></letterb> > </beta> > </alpha2> > <top> > > And I'm trying to retrieve only nodes that have no children: > <one></one> > <two></two> > <three></three> /top/*[not(node())] selects all child elements of the top root element that do not have any child nodes/contents. If the top name is just an example you can of course also use the more general /*/*[not(node())] > and for a later call node that only have children: > <alpha1> > </alpha1> > <alpha2> > <alpha2> Then /top/*[node()] or more general /*/*[node()] Note that node() selects all kind of nodes (element nodes, text nodes, comment nodes, processing instruction nodes), if you are only interested if element nodes have element node children then e.g. /*/*[*] is more appropriate. -- Martin Honnen --- MVP XML http://JavaScript.FAQTs.com/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
