问题描述
我正在边学边做 xmlstarlet
以执行特定任务:
选择元素 <value>
中的每个 <outcomeVariable>
,父元素 <itemResult>
和附加属性 @identifier="MAXscore"
(并逐行打印)。>
使用这个示例文件
<test>
<itemResult>
<outcomeVariable identifier="MAXscore" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">1.5</value>
</outcomeVariable>
<outcomeVariable identifier="MAXscore" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">2.5</value>
</outcomeVariable>
<outcomeVariable identifier="MAXscore" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">3.5</value>
</outcomeVariable>
</itemResult>
<outcomeVariable identifier="MAXscore" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">4.5</value>
</outcomeVariable>
</test>
我的代码
xmlstarlet sel --template --match "//itemResult/outcomeVariable[@identifier='MAXscore']" -v . *.xml
放出来
1.5
2.5
3.5
(带前导空格和空行)
[edit] 我想要
1.5
2.5
3.5
[/edit]。
但是使用(提取的)真实文件(从那里我刚刚复制了示例节点并更改了值)
<?xml version="1.0" encoding="UTF-8"?>
<assessmentResult xmlns="http://www.imsglobal.org/xsd/imsqti_v2p1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.imsglobal.org/xsd/imsqti_v2p1 imsqti_v2p1.xsd">
<context />
<testResult identifier="idTest9cb05b88-72ee-47fe-92b0-c517bf5ee46b" datestamp="2020-11-21T12:17:57" currentItemIndex="11">
<responseVariable identifier="duration" cardinality="single" baseType="duration">
<candidateResponse>
<value baseType="integer">500</value>
</candidateResponse>
</responseVariable>
<responseVariable identifier="id8a88d3f5-631d-45dd-a3ef-29f6b2457d78.duration" cardinality="single" baseType="duration">
<candidateResponse>
<value baseType="integer">245</value>
</candidateResponse>
</responseVariable>
<outcomeVariable identifier="score_id8a88d3f5-631d-45dd-a3ef-29f6b2457d78" cardinality="single" manualscored="false" baseType="float" view="tutor">
<value baseType="float">13.5</value>
</outcomeVariable>
<outcomeVariable identifier="MAXscore_id8a88d3f5-631d-45dd-a3ef-29f6b2457d78" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">16</value>
</outcomeVariable>
<outcomeVariable identifier="MINscore_id8a88d3f5-631d-45dd-a3ef-29f6b2457d78" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">0</value>
</outcomeVariable>
<outcomeVariable identifier="score_idd35753ab-a9bd-4234-b7ea-d1db89ce6516" cardinality="single" manualscored="false" baseType="float" view="tutor">
<value baseType="float">0</value>
</outcomeVariable>
<outcomeVariable identifier="MAXscore_idd35753ab-a9bd-4234-b7ea-d1db89ce6516" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">2</value>
</outcomeVariable>
<outcomeVariable identifier="MINscore_idd35753ab-a9bd-4234-b7ea-d1db89ce6516" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">0</value>
</outcomeVariable>
</testResult>
<itemResult identifier="iddb301400-85da-4652-9162-088a49f927f0_1" datestamp="2021-07-26T09:18:51" sessionStatus="final" sequenceIndex="1">
<responseVariable identifier="duration" cardinality="single" baseType="duration">
<candidateResponse>
<value baseType="integer">54</value>
</candidateResponse>
</responseVariable>
<responseVariable identifier="RESPONSE_1" baseType="identifier" cardinality="multiple" choiceSequence="ID_3 ID_2 ID_6 ID_5 ID_4 ID_1">
<correctResponse>
<value baseType="identifier">ID_1</value>
<value baseType="identifier">ID_2</value>
</correctResponse>
<candidateResponse>
<value baseType="identifier">ID_2</value>
<value baseType="identifier">ID_1</value>
</candidateResponse>
</responseVariable>
<outcomeVariable identifier="score" cardinality="single" manualscored="false" baseType="float" view="tutor">
<value baseType="float">2</value>
</outcomeVariable>
<outcomeVariable identifier="MAXscore" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">2</value>
</outcomeVariable>
<outcomeVariable identifier="MINscore" cardinality="single" manualscored="false" baseType="float" view="scorer">
<value baseType="float">0</value>
</outcomeVariable>
</itemResult>
</assessmentResult>
输出为空
...
我发现了不同的教程等,其中描述了 --template --match "//...
用于在整个文件中搜索该模式。
所以我的问题是
我希望得到一些答案/提示,在哪里寻找解决我的问题的方法(-s)!
最好的问候,
J.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)