0

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?

Henrique Mauri
  • 718
  • 6
  • 20
Megrez7
  • 1,423
  • 1
  • 15
  • 35

1 Answers1

2

They might support the XPath 2.0 data model, but I'm pretty certain they don't support XPath 2.0 syntax or the XPath 2.0 function library.

There's information on XPath 2.0 support for .NET at XPath and XSLT 2.0 for .NET?

The current Saxon product for .NET doesn't work on .NET 5.0, unfortunately. We're hoping to have a new product that fills that gap within weeks.

2023 Update

SaxonCS from v11.0 onwards works on .NET Core (that is, 5.0 or later)

Michael Kay
  • 156,231
  • 11
  • 92
  • 164