.NET Framework 2.0 does really support XPath 2.0?

Hi to everybody,
today I am facing a really tough problem. I am trying to compile the following XPath 2.0 expression:

ancestor::node()[1]/position()

in order to get the ordinal position of a context node within its context node-set.

Here it is the simple code that I'm using:

XPathExpression expression = XPathExpression.Compile(xpathExpression, nsMgr);

Here it is the simple code that I'm using but when I execute the program I receive this error:

' ..... /position()' has an invalid token

I have tried to evaluate the same expression with Altova and it's work. Could be a bug of the Microsoft's XPath 2.0 implementation


Answer this question

.NET Framework 2.0 does really support XPath 2.0?

  • VTS

    In the documentation of System.Xml.XPath Namespace I found this sentence:

    "The System.Xml.XPath namespace contains the classes that define a cursor model for navigating and editing XML information items as instances of the XQuery 1.0 and XPath 2.0 Data Model."

    now I am confused. I know that the specification are still in development, but I also know that W3C has released variuos draft.

    Can you confirm me that .NET 2.0 does not support "XPath 2.0"

  • Haneli

    Just use:

    count(preceding-sibling::C) + 1

    Cheers,

    Dimitre Novatchev


  • Julianín

    thanks a lot, Dimitre! I don't know why I didn't think to it before!

  • JeffJohnsonMVPVB

    .NET Framework 2.0 does not support XPath 2.0. In http://msdn.microsoft.com/msdnmag/issues/03/01/XMLFiles/. Aaron points to Michael Kay's Saxon processor.


  • super_pointer

    thank you for the answer now the story is more clear.

    Do you have any idea how to solve my problem without using the XPath function position()

    I need to get with an Xpath expression the ordinal position of a node. Do you see any chance to get it in some way


  • TheBlackShadow

    What do you want to achieve

    In XPath 2.0

    ancestor::node()[1]/position()

    has always the value of 1. That is, the position of a node within a node-set consisting of just one node is, of course, always 1.


  • Ahoapap

    The .NET Framework 2.0 does *not* support XPath 2.0, because its specification is still being developed.


  • hazz

    hey, you are right! I am sorry, I hav interpreted wrong the use of position().

    Practically I would like to achieve the following result. I attach a short code example:


    <A>
      <B>
        <C>String1</C>
        <C>String2</C>
        <C>StringN</C>
      </B>
      <D>
        <C>String1</C>
        <C>String2</C>
        <C>StringN</C>
      </D>
    </A>

    I am parsing the node <C>String2</C> and I want to know (by using an XPath expression) its ordinal position referred to the parent node <D>.

    I am expeting 2 as result. Is this possible

    thanks in advance for the help


  • rosraj

    While the data model is supported, the XPath 2.0 query language is not implemented in the .NET Framework 2.0. As one of System.Xml developers I know that for sure. Nobody wants to end up supporting two different XPath 2.0 dialects (the final recommendation and some intermediate candidate), so the spec is really have to be finalized before we may ship the product.
  • .NET Framework 2.0 does really support XPath 2.0?