<?xml version="1.0"?>
<Student xmlns="http://www.tibco.com/schemas/TrainingPOCs/SharedRec/Schemas/Schema.xsd">
<Phno type="kwh" value="70" name=""/>
<Phno type="wh" value="100" name="80">
<Type>D</Type>
<Mobile>7777777777</Mobile>
<TPhone>6666666666</TPhone>
</Phno>
<Phno type="kwh" value="200" name="">
<Type>E</Type>
<Mobile>5555555555</Mobile>
<TPhone>4444444444</TPhone>
</Phno
</Student>
我的輸入檔案需要使用值屬性值更新名稱屬性,只要型別屬性有 kWh 我處理過的腳本
xmlstarlet edit -N w="http://www.tibco.com/schemas/TrainingPOCs/SharedRec/Schemas/Schema.xsd" -u "/w:Student/w:Phno[@type='kwh']/@name" -x "/w:Student/w:Phno[@type='kwh']/@value" sample.xml
uj5u.com熱心網友回復:
您快到了,但對-x / --expr選項使用相對 XPath 運算式
:
xmlstarlet edit \
-N w='http://www.tibco.com/schemas/TrainingPOCs/SharedRec/Schemas/Schema.xsd' \
-u '/w:Student/w:Phno[@type="kwh"]/@name' \
-x 'string(../@value)' file.xml
或者,使用默認命名空間 快捷方式,
xmlstarlet ed -u '/_:Student/_:Phno[@type="kwh"]/@name' -x 'string(../@value)' file.xml
并且可能添加一個-L / --inplace選項(參見
xmlstarlet.txt)進行就地編輯。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/405844.html
標籤:
上一篇:如何確保第一個命令完成,然后只在shell腳本中執行第二個命令
下一篇:在Heroku上運行bash檔案
