开发者

calling namespace-uri in C#, namespace-uri has an invalid token

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 docume开发者_如何学编程nt using xpath.

Thanks Regards Craig.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜