tags:

views:

2106

answers:

4
+2  Q: 

xpath and c#

Hi

I am trying to create a winform application that searches through an XML doc. for my search I need to convert the the XML attribute in the xpath condition to lower case, by using lower-case() xpath function. this causes a problem related to the function namespace.

I have tried to add the namespace manualy:

        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 exception: XsltContext is needed for this query because of an unknown function.

+2  A: 

fn:lower-case is defined in XQuery 1.0 and XPath 2.0. XSLT 2.0 works with XPATH 2.0.

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

codemeit
What else is possible to do in order to run a query search?
Can you provide the XML you want to work with?
codemeit
+1  A: 

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

Si
+1  A: 

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

In XPath 1.0 to convert letters to lower case one can still use the translate() function as shown below:

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

Dimitre Novatchev
A: 

what about starts-with and/or contains(). I am getting error in using these functions..

@Pawan. This is not a discussion board - it's a question and answer site. Ask a question, and you'll get answers.
John Saunders