如何检查 xml 中的属性可用性?

How to check the attribute availability in xml?

如何在特定元素中查找属性是否可用?

使用 XPath 将 return 您的目标属性并将结果转换为布尔值:

boolean(//target_element/@target_attribute)

或类似的方法,但使用 exists() 函数:

exists(//target_element/@target_attribute)

其实题中并没有说清楚context,比如你的case中的context元素可能已经是target元素了,所以不需要//target_element/部分.

此外,您可以 return 目标元素的所有属性名称:

//target-element/(@*[1])