tags:

views:

35

answers:

2

I am trying to evaluate a XPathExpression with XQSharp and get the Error:"Type check error. The empty sequence cannot be cast to type 'xs:integer'."

AltovaXMLSpy evaluates it correct as "true".

oXmlDoc.CreateNavigator().XPathEvaluate("root/foo/bar cast as xs:integer lt count(root/blah/blub)", oNamespaseManager).ToString()

This XML looks like this:

<root xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
    <foo>
        <bar>0</bar>
    </foo>
    <blah>
        <blub/> 
    </blah>
</root>

What am I missing?

+1  A: 

Update:

there is no .NET - provided XPath engine that supports XPath 2.0.

Initial reply:

oXmlDoc.CreateNavigator()
          .XPathEvaluate("root/foo/bar cast as xs:integer lt count(root/blah/blub)",
                          oNamespaseManager
                        )
                         .ToString()

Most probably the actual XML document, against which the XPath expression is evaluated is not the one you provided, or the current (context) node is not the document-node.

Dimitre Novatchev
Thanks for your answer :)I figured it out myselfe. Was a pretty stupid mistake - I overlooked a relative path that has to be an absolute path in the real XPath-expression.
Florian
+1  A: 

The path expression "root/foo/bar" must not be returning any nodes.

Does the default namespace in your namespace manager match the default namespace of the document?

You could try testing this part of the path expression with the .NET XPath functions to ensure that you are returning the correct nodes:

oXmlDoc.CreateNavigator().Evaluate("root/foo/bar", oNamespaceManager)
Oliver Hallam
Thanks for your answer :)I figured it out myselfe. Was a pretty stupid mistake - I overlooked a relative path that has to be an absolute path in the real XPath-expression.
Florian