XPathNavigator.Select

B

Bruce Sandeman

Hi,
I am trying to execute the following xpath query against my
XmlDocument.

//*[not(*)][count(ancestor::node())=max(//*[not(*)]/
count(ancestor::node()))]

This query will retrieve the deepest node. It only works in XPath 2.0
but according to MS documentation .Net 2.0 supports XPath 2.0 so this
should work in theory....
There is nothing wrong with the query as I can execute it just fine
within OxygenXML but when I use it within my C# code it bounces back
with the error XPathException "...." has an invalid token.

Does anyone know why this could be? or have any ideas of things I
could try?

The code I am using is as follows:

public XPathNodeIterator ExecuteXPathQuery(String query)
{
XPathNavigator nav = xmlDoc.CreateNavigator();
XPathExpression exp = nav.Compile(query);
exp.SetContext(namespaceManager);
XPathNodeIterator xpni =
xmlDoc.CreateNavigator().Select(exp);
return xpni;
}

thanks
Bruce
 
M

Martin Honnen

Bruce said:
I am trying to execute the following xpath query against my
XmlDocument.

//*[not(*)][count(ancestor::node())=max(//*[not(*)]/
count(ancestor::node()))]

This query will retrieve the deepest node. It only works in XPath 2.0
but according to MS documentation .Net 2.0 supports XPath 2.0 so this
should work in theory....

No, .NET 2.0 (XPathNavigator) does not support XPath 2.0, only XPath
1.0. Unless you use Saxon.NET from http://www.saxonica.com/, that
supports XPath 2.0. But it has its own API.
 

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

Top