Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XPath in C Sharp (http://www.velocityreviews.com/forums/t168450-xpath-in-c-sharp.html)

Markus Wallner 12-21-2004 12:49 PM

XPath in C Sharp
 
Hi!

Can some XPath expert please answer the following question:

How can I quickly check if a set of nodes do all have the same parent
node?

For example (i)

<table name="X" >
<field name="a" />
<field name="b" />
</table>

<table name="Y" >
<field name="c" />
<field name="d" />
</table>

Question: Do the nodes a, b, c and d all have the same parent node?
No, they do not in this example.

For example (ii)
<table name="X" >
<field name="a" />
<field name="b" />
</table>

Question: Do the nodes a and b all have the same parent node?
Yes, they do in this example.

How can I express that question in XPath? Of course I could retrieve
all field-nodes and then iterate over them and check but I wonder if
there is a quicker way.

Programming language: C#, VS .NET 2003

Thanks a bunch!
Markus

David Carlisle 12-21-2004 01:03 PM

Re: XPath in C Sharp
 
waschbaer2@yahoo.com (Markus Wallner) writes:

> Hi!
>
> Can some XPath expert please answer the following question:
>
> How can I quickly check if a set of nodes do all have the same parent
> node?
>
> For example (i)
>
> <table name="X" >
> <field name="a" />
> <field name="b" />
> </table>
>
> <table name="Y" >
> <field name="c" />
> <field name="d" />
> </table>
>
> Question: Do the nodes a, b, c and d all have the same parent node?


1=count(.//field[@name='a' or @name='b' or @name='c' or @name='d']/..)

is just true if they all have the same parent.

David


All times are GMT. The time now is 12:15 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.