我有一个类似于下面示例的 XML:
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite errors="0" failures="0" name="test" tests="1" time="2.747">
<properties>
<property name="categories" value="ExampleCategory" />
<property name="timestamp" value="1519664414463" />
</properties>
<testcase classname="com.example.junit.Test" name="test" time="2.747" />
</testsuite>
有没有办法根据属性名称检索属性标签值?
现在,我正在使用类似的东西:
@doc.xpath('//testsuite//properties//property/@value').text
这会给我“ExampleCategory1519664414463”。
我知道如果我使用 .first
或 [0]
、[1]
等,我可以单独获取值,但我不能'找不到根据“name”属性分别获取值的方法。
有人知道如何检索它吗?
最佳答案
这个 XPath,
//property[@name='timestamp']/@value
将选择property
元素的所有value
属性,其name
属性值等于'timestamp'
。
关于ruby - 使用 XPath 获取属性的 XML 属性值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49008844/