我可以搜索包含在特定屬性如果我用下面的XPath /xs:schema/node()/descendant::node()[starts-with(@my-specific-attribute-name-here, 'my-search-string')]
Xpath用於搜索具有包含特定字符串的ANY屬性的節點?
但是一個字符串,我想搜索包含*的String
我可以搜索包含在特定屬性如果我用下面的XPath /xs:schema/node()/descendant::node()[starts-with(@my-specific-attribute-name-here, 'my-search-string')]
Xpath用於搜索具有包含特定字符串的ANY屬性的節點?
但是一個字符串,我想搜索包含*的String
示例XML的任何屬性:
<root>
<element1 a="hello" b="world"/>
<element2 c="world" d="hello"/>
<element3 e="world" f="world"/>
</root>
假設我們需要選擇具有包含h
的任何屬性的元素。在此示例中:element1
,element2
。我們可以用這樣的XPath:
//*[@*[starts-with(., 'h')]]
在您的樣本:
/xs:schema/node()/descendant::node()
[@*[starts-with(@my-specific-attribute-name-here, 'my-search-string')]]
你正在尋找的一般模式是:
@*[contains(., 'string')]
將背景元素匹配任何屬性包含string
。所以,如果你只是想搜索包含string
屬性整個文檔,你會使用:
//@*[contains(., 'string')]
簡短而甜美 –
你需要清楚你所說的「含有」的意思。你的意思是「等於」還是「有一個子字符串等於」?或者,如你的例子所示,「開始」? –
*有一個子字符串等於 – emdog4