I am trying to XPathNavigator.SelectSingleNode without namespaces.
The initial version with namespaces
string Val1 = nav.SelectSingleNode("/nn:AAA/nn:SomeTag/@Code", nsmgr).Value;
works fine.
Options for getting rid of namespaces I am trying:
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
works as uses XPath 1.0 function. However both Val3
and Val4
throw an exception "Invalid token".
Wildcard shall be accepted, as documentation https://learn.microsoft.com/en-us/dotnet/api/system.xml.xpath?view=netcore-3.1 says it supports XPath 2.0 Data Model.
Same say answers to the question Is it possible to ignore namespaces in c# when using xPath?