XPath in C Sharp

Discussion in 'XML' started by Markus Wallner, Dec 21, 2004.

  1. 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
    Markus Wallner, Dec 21, 2004
    #1
    1. Advertising

  2. (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
    David Carlisle, Dec 21, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Hai Nguyen
    Replies:
    3
    Views:
    1,972
    Hai Nguyen
    Jan 8, 2004
  2. Guest
    Replies:
    1
    Views:
    535
    Matt Berther
    Apr 20, 2005
  3. =?Utf-8?B?ZXN3YW5zb24=?=

    getting currently logged in user asp.net c sharp class

    =?Utf-8?B?ZXN3YW5zb24=?=, Feb 28, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    5,738
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 28, 2006
  4. The LoxFather

    C plus plus vs C Sharp

    The LoxFather, Aug 9, 2003, in forum: C++
    Replies:
    23
    Views:
    9,156
  5. The LoxFather

    C plus plus vs C Sharp

    The LoxFather, Aug 9, 2003, in forum: C Programming
    Replies:
    23
    Views:
    1,347
Loading...

Share This Page