Edit XML from command line with shell script on Linux

南楼画角 提交于 2019-12-11 20:26:43

问题


I'm trying to make a script that changes a few values then deploys. I have this XML:

<application>
    <NVPairs name="Variables">
        <NameValuePair>
            <name>Parameter/1</name>
            <value>MyOtherValue</value>
        </NameValuePair>
        <NameValuePair>
            <name>Parameter/2</name>
            <value>MyValue</value>
        </NameValuePair>
    </NVPairs>
</application>

Which I am trying to edit with SED. The NVPAIRS and NameValue seems to be messing me around a bit. Can I ask for suggestions how to deal with NameValuePair? I did try XMLStarlet as well, but same problem. Can not seem to deal with NameValuePairs.


回答1:


I wouldn't try to use sed to edit XML. Unless there is some constant to match on (that lets you decide if you are on a /1 or /2) it'll be hard (I would say impossible, but some sed guru will chime and and prove me wrong...)

If you can't install stuff, something like an awk or perl script that lets you keep a minimum of state you work better than sed.



来源:https://stackoverflow.com/questions/17592740/edit-xml-from-command-line-with-shell-script-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!