XPath小写()函数 [英] XPath lower-case() function

查看:26
本文介绍了XPath小写()函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 XPATH 从 XML 文档中选择某些节点.

I'm using XPATH to select certain nodes from an XML document.

用户可以为位置插入一个值.它工作正常,但如果使用不同的情况,它就不起作用.

The user is able to insert a value for the location. It's working fine, but it does not work if different cases are used.

我决定在比较之前将 XML 值和用户输入都更改为小写可能是最好的方法.

I've decided that changing both the XML values and the user's input to lower case before being compared is probably the best way to go about it.

我现在把它作为我的选择器:

I've got this as my selector at the moment:

NodeIter = nav.Select("/Houses/House/location[contains(../location, '" + location_input + "')]");

我尝试将 lower-case() 函数放在不同的位置,但它并不满意.

I've tried putting the lower-case() function in various locations, but it isn't happy with it.

如何将 ../location 的值作为小写进行比较?

How do I make it so that the value of ../location is compared as lower case?

注意:在我的 c# 代码中使用 ToLower() 将 location_input 设置为较低.

Note: location_input is set to lower using ToLower() within my c# code.

推荐答案

小写() 函数仅从 XPath 2.0 开始支持.如果你的环境支持这个版本的标准,你可以这样写:

The lower-case() function is only supported from XPath 2.0 onwards. If your environment supports this version of the standard, you can write:

NodeIter = nav.Select("/Houses/House/location[contains(lower-case(.), '"
    + location_input + "')]");

但是,您可能会被 XPath 1.0 困住.在这种情况下,您可以滥用 translate() 函数:

However, chances are you're stuck with XPath 1.0. In that case, you can abuse the translate() function:

NodeIter = nav.Select("/Houses/House/location[contains(translate(., "
    + "'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '"
    + location_input + "')]");

这篇关于XPath小写()函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆