以下のxmlについては、<studentName>CLASSA</studentName>
〜<studentStatus>failed</studentStatus>
の代わりに<studentStatus>
を置き換える必要があります。xmlを解析して特定のタグを置き換えるシェルスクリプト
<studentFile>
<student>
<studentName>CLASSA</studentName>
<studentStatus>Success</studentStatus>
<studentActions>
<studentAction>
<studentType>Juniour</studentType>
<studentStatus>Completed</studentStatus>
<studentMsg/>
</studentAction>
<studentAction>
<studentType>HighSchool</studentType>
<studentStatus>Completed</studentStatus>
<studentMsg/>
</studentAction>
</studentActions>
</student>
<student>
<studentName>CLASSB</studentName>
<studentStatus>Success</studentStatus>
<studentActions>
<studentAction>
<studentType>Senior</studentType>
<studentStatus>Completed</studentStatus>
</studentAction>
<studentAction>
<studentType>Middle</studentType>
<studentStatus>Completed</studentStatus>
</studentAction>
</studentActions>
</student>
</studentFile>
完了として、私はこれまでのところ、
xmllint -xpath "/studentFile/student[studentName='CLASSA']/studentActions/studentAction[studentType="Juniour"]/studentStatus" myxml.xml
は、今私が学生の地位を得てしまった何を、今、この値は失敗に変更する必要があります。 <studentType>Juniour</studentType>
のみ はどうすれば
<studentFile>
<student>
<studentName>CLASSA</studentName>
<studentStatus>Success</studentStatus>
<studentActions>
<studentAction>
<studentType>Juniour</studentType>
<studentStatus>Failed</studentStatus>
<studentMsg/>
</studentAction>
<studentAction>
<studentType>HighSchool</studentType>
<studentStatus>Completed</studentStatus>
<studentMsg/>
</studentAction>
</studentActions>
</student>
<student>
<studentName>CLASSB</studentName>
<studentStatus>Success</studentStatus>
<studentActions>
<studentAction>
<studentType>Senior</studentType>
<studentStatus>Completed</studentStatus>
</studentAction>
<studentAction>
<studentType>Middle</studentType>
<studentStatus>Completed</studentStatus>
</studentAction>
</studentActions>
</studentFile>
が、これはsedを使用して行うことができ、としてそれを得るために順序どおりXMLを編集する必要があります。 xsltprocのようなツールがありますが、これがクラスタ内のすべてのノードにインストールされているかどうかはわかりません。
ご協力いただければ幸いです。 ありがとうございます!場合
「*これはsedを使用して行うことができます。* "参照:http://stackoverflow.com/a/1732454/3016153(XMLにも同様に適用されます) –
' xmlstarlet'にアクセスできますか? – Cyrus
ほとんどのシステムでは、Pythonにはxmlモジュールが付属しています。それを試してみてください – 123