使用 XPath 获取 属性 的 XML 属性值
Get XML attribute value of property using XPath
我有一个 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]
等,我可以单独获取值,但我找不到根据 [= 单独获取值的方法28=] 属性。
有人知道我怎样才能找回它吗?
这个 XPath,
//property[@name='timestamp']/@value
将 select property
元素的所有 value
属性 name
属性值等于 'timestamp'
。
我有一个 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]
等,我可以单独获取值,但我找不到根据 [= 单独获取值的方法28=] 属性。
有人知道我怎样才能找回它吗?
这个 XPath,
//property[@name='timestamp']/@value
将 select property
元素的所有 value
属性 name
属性值等于 'timestamp'
。