开发者

CreateNavigator (X-Path has invalid token)

开发者 https://www.devze.com 2023-01-07 19:22 出处:网络
I am trying to enumerate all the namespaces in a document using XPath. The following works in xmlspy, but not in .NET

I am trying to enumerate all the namespaces in a document using XPath. The following works in xmlspy, but not in .NET

//*/namespace-uri(.)

// Executing this in linqpad, I get the error below.
xml.CreateNaviga开发者_如何学Gotor().Select("//*/namespace-uri(.)").Dump();
// the error below.
XPathException: ('//*/namespace-uri(.)' has an invalid token)

Thanks


For anyone else trying this here is the code that works.

(element.XPathEvaluate("//namespace::*") as IEnumerable).OfType<XAttribute>().Distinct()

Regards

Me

0

精彩评论

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