XPath in C Sharp

M

Markus Wallner

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
 
D

David Carlisle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top