Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: how to access sibling node that do not have children

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent