【发布时间】:2021-11-06 13:19:49
【问题描述】:
我正在尝试没有命名空间的 XPathNavigator.SelectSingleNode。
带有命名空间的初始版本
string Val1 = nav.SelectSingleNode("/nn:AAA/nn:SomeTag/@Code", nsmgr).Value; 工作正常。
我正在尝试摆脱命名空间的选项:
string Val2 = nav.SelectSingleNode("/*[local-name()='AAA']/*[local-name()='SomeTag']/@Code", nsmgr).Value;
string Val3 = nav.SelectSingleNode("/*:AAA/*:SomeTag/@Code", nsmg).Value;
string Val4 = nav.SelectSingleNode("/*:AAA/*:SomeTag/@Code").Value;
Val2 使用 XPath 1.0 函数。然而Val3 和Val4 都抛出异常“Invalid token”。
应接受通配符,因为文档 https://docs.microsoft.com/en-us/dotnet/api/system.xml.xpath?view=netcore-3.1 表示它支持 XPath 2.0 数据模型。
同样回答问题Is it possible to ignore namespaces in c# when using xPath?
【问题讨论】: