tags:

views:

82

answers:

1

Hi,

I am executing the following. Given an XDocument doc;

doc.XPathEvaluate("//namespace-uri()");

I get the error '//namespace-uri()' has an invalid token.

It seems to work in a node test, for example "//*[namespace-uri()='xyz']". The function should work though, XMLSPY is happy with the above version, and I believe it uses the same engine.

Any help would be appreciated. I want to enumerate all the namespaces in the document using xpath.

Thanks Regards Craig.

+2  A: 

Your XPath is wrong. The namespace-uri() function returns a string, so it can't be used where a nodeset is expected. Instead, you should use the namespace axis:

doc.XPathEvaluate("//namespace::*");

This will return a nodeset containing every namespace declaration in the document.

Phil Booth
Fabulous, thanks very much for that. Works perfectly.
Jim