从 XML 中提取值

Edg*_*ado 1 bash xml sed

我有这个 XML:

<results><testsuites><testcase name="XXXX (XXXXX)" time="20.3817"><result>success</result></testcase><total_time value="20.3830" /></testsuites></results>
Run Code Online (Sandbox Code Playgroud)

我想提取 20.3817。

尝试一些 sed 但没有开始工作。

cho*_*oba 8

不要使用正则表达式来解析 XML。使用 XML 感知工具,例如xmllint

xmllint --xpath 'string(/results/testsuites/testcase/@time)' file.xml
Run Code Online (Sandbox Code Playgroud)