XPATH:检查xml节点是否包含特定字符或字符串 [英] XPATH: Check if a xml node contains specific characters or strings

查看:470
本文介绍了XPATH:检查xml节点是否包含特定字符或字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象一下这个XML文件(对不起,请病假的例子!)

Imagine this XML file (sorry for sick example!!)

<DOC>
<Test>
    <Name>1 vs 100 Pre pre History</Name>
    <Type>Dinasors</Type>
</Test>

<Test>
    <Name> 1 vs 100 Post moderns</Name>
    <Type>Aliens</Type>
</Test>
</Doc>

此想法是通过检查Name节点是否包含特定字符或字符串来返回Type值。例如,我想要一个XPath查询,例如:

The idea is returning the Type value, By checking if Name node contains a specific character or string. For example I want a XPath Query like:

/Doc//Test[contains "Pre" and "History" and 1]/Type

这是检查Test是否包含 Pre和 History以及数字1,这将是什么是xpath查询吗?

That is check if Test contains "Pre" and "History" and number 1, What will be the xpath query? Alo I like this query to not be CASE SENSITIVE.

谢谢。

推荐答案

我认为这应该有效(未经测试):

I think this should work (haven't tested it):

/Doc//Test[contains(Name,'Pre') and contains(Name,'History') and contains(Name,1)]/Type

但是区分大小写。如果您希望它不区分大小写,那么您可能想看看此问题:必须使用 translate 来转换您的 Name 转换为小写(或大写),然后匹配。

However that is case sensitive. If you want it case insensitive, then you may want to have a look at this question or this question: you must use translate to convert your Name to lower-case (or upper-case) and then match.

这篇关于XPATH:检查xml节点是否包含特定字符或字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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