Xpath 搜索具有包含特定字符串的任何属性的节点? [英] Xpath to search for a node that has ANY attribute containing a specific string?

查看:56
本文介绍了Xpath 搜索具有包含特定字符串的任何属性的节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用以下 XPath,我可以搜索包含在 特定 属性中的字符串/xs:schema/node()/descendant::node()[starts-with(@my-specific-attribute-name-here, 'my-search-string')]

I can search for a String contained in an specific attribute if I use the following XPath /xs:schema/node()/descendant::node()[starts-with(@my-specific-attribute-name-here, 'my-search-string')]

但是,我想搜索包含*字符串的任何属性

However, I'd like to search for ANY attribute containing* a String

推荐答案

示例 XML:

<root>
  <element1 a="hello" b="world"/>
  <element2 c="world" d="hello"/>
  <element3 e="world" f="world"/>
</root>

假设,我们需要选择具有包含 h 的任何属性的元素.在此示例中:element1element2.我们可以使用这个 XPath:

Suppose, we need to select elements which have any attribute containing h. In this sample: element1, element2. We can use this XPath:

//*[@*[starts-with(., 'h')]]

在您的示例中:

/xs:schema/node()/descendant::node()
    [@*[starts-with(@my-specific-attribute-name-here, 'my-search-string')]]

这篇关于Xpath 搜索具有包含特定字符串的任何属性的节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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