Xpath//a[contains(@class, 'storylink')]/@*
将提取锚标记的所有属性。我的xml中的Anchor标签没有标题属性,该属性通常包含链接的内容。有没有办法在XPATH 1.0的锚链接中同时选择href和文本内容?
如果要同时选择@href
和text()
在单个XPath选择中,则可以使用union运算符|
。
使用XPath 1.0,这可能是您可以做的最好的事情:
//a[contains(@class, 'storylink')]/@href | //a[contains(@class, 'storylink')]/text()
使用XPath 2.0(或更高版本),您可以避免重复定位选择条件:
//a[contains(@class, 'storylink')]/(@href,text())
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句