Parsing xml to and replacing specific tags shell script

前端 未结 3 1042
抹茶落季
抹茶落季 2021-02-10 02:40

For the below xml ,I need to replace for CLASSA to failed

3条回答
  •  你的背包
    2021-02-10 03:07

    Update value with xmllint in file.xml:

    xmllint --shell file.xml << EOF
    cd /studentFile/student[studentName='CLASSA']/studentActions/studentAction[studentType='Juniour']/studentStatus
    set failed
    save
    EOF
    

    or without here document:

    echo -e "cd /studentFile/student[studentName='CLASSA']/studentActions/studentAction[studentType='Juniour']/studentStatus\nset failed\nsave" | xmllint --shell file.xml
    

    Update: With bash and XML in a variable:

    xml=$(xmllint --shell <(echo "$xml") << EOF
    cd /studentFile/student[studentName='CLASSA']/studentActions/studentAction[studentType='Juniour']/studentStatus
    set failed
    save -
    EOF
    )
    

    or without here document:

    xml=$(echo -e "cd /studentFile/student[studentName='CLASSA']/studentActions/studentAction[studentType='Juniour']/studentStatus\nset failed\nsave -" | xmllint --shell <(echo "$xml"))
    

提交回复
热议问题