xml文件的一部分:
<caldata chopper="on" gain_1="0" gain_2="0" gain_3="0" impedance="(0,0)">
<c0 unit="V">0.00000000e+00</c0>
<c1 unit="Hz">4.00000000e-01</c1>
<c2 unit="V/(nT*Hz)">1.93430000e-02</c2>
<c3 unit="deg">8.92260000e+01</c3>
</caldata>
<caldata chopper="on" gain_1="0" gain_2="0" gain_3="0" impedance="(0,0)">
<c0 unit="V">0.00000000e+00</c0>
<c1 unit="Hz">5.55800000e-01</c1>
<c2 unit="V/(nT*Hz)">1.93390000e-02</c2>
<c3 unit="deg">8.89710000e+01</c3>
</caldata>
<caldata chopper="on" gain_1="0" gain_2="0" gain_3="0" impedance="(0,0)">
<c0 unit="V">0.00000000e+00</c0>
<c1 unit="Hz">7.72300000e-01</c1>
<c2 unit="V/(nT*Hz)">1.93320000e-02</c2>
<c3 unit="deg">8.86030000e+01</c3>
</caldata>
我想在c2线上提取数值。这是我的尝试:
xmlstarlet sel -t -v '//caldata chopper="on"[<c2 unit="V/(nT*Hz)"> ]' 263.xml
Invalid expression: //caldata chopper="on"[<c2 unit="V/(nT*Hz)"> ]
compilation error: element with-param
XSLT-with-param: Failed to compile select expression '//caldata chopper="on"[<c2 unit="V/(nT*Hz)"> ]'
xmlstarlet sel -t -v '//caldata chopper="on"[<c2 unit="V/(nT*Hz)"> ]' 263.xml
Invalid expression: //caldata chopper="on"[<c2 unit="V/(nT*Hz)"> ]
compilation error: element with-param
XSLT-with-param: Failed to compile select expression '//caldata chopper="on"[<c2 unit="V/(nT*Hz)"> ]'
我应该改变什么? xmlstarlet
是否适合此工具?
答案 0 :(得分:2)
xmlstarlet非常适合此任务。尝试:
xmlstarlet sel -t -v '//caldata[@chopper="on"]/c2[@unit="V/(nT*Hz)"]' 263.xml
结果:
1.93430000e-02
1.93390000e-02
1.93320000e-02