用于搜索具有包含特定字符串的ANY属性的节点的Xpath?

[英]Xpath to search for a node that has ANY attribute containing a specific 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')]

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

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

但是,我想搜索包含* String的ANY属性

2 个解决方案

#1


11  

Sample XML:

示例XML:

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

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

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

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

In your sample:

在你的样本中:

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

#2


8  

The general pattern you're looking for is:

您正在寻找的一般模式是:

@*[contains(., 'string')]

which will match any attribute on the context element that contains string. So if you simply want to search the whole document for attributes containing string, you'd use:

它将匹配包含字符串的context元素的任何属性。因此,如果您只想在整个文档中搜索包含字符串的属性,您可以使用:

//@*[contains(., 'string')]
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2011/09/13/7de8b361e4ef74b73c8491b66a0af175.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告