Xpath and C #

I am trying to create a winform application that searches through an XML document. for my search, I need to convert the XML attribute in the xpath condition to lowercase using the lowercase () xpath function. this causes a problem with the function namespace.

I tried adding the namespace manually:

XmlNamespaceManager nsMgr = new XmlNamespaceManager(prs.Doc.NameTable); nsMgr.AddNamespace("fn", "http://www.w3.org/2005/02/xpath-functions"); XmlNodeList results = prs.Doc.SelectNodes("//function[starts-with(fn:lower-case(@name),'" + txtSearch.Text + "')]",nsMgr); 

but still I get an exception: XsltContext is needed for this request due to an unknown function.

+7
c # xpath
source share
3 answers

fn: Lowercase is defined in XQuery 1.0 and XPath 2.0 . XSLT 2.0 works with XPATH 2.0.

AFAIK, .NET does not yet support XPATH 2.0. and the XSLT version from .NET is 1.0 as well as 2.0.

+4
source share

The lower-case() function is defined for XPath 2.0 .

In XPath 1.0 , to convert letters to lowercase , you can still use the translate() function , as shown below:

translate(@attrName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')

+5
source share

I think CodeMelt is correct and gets my +1, but maybe Microsoft ms: string-compare extension function (case insensitive) can help solve your problem?

+3
source share

All Articles