5

When using the command:

-bash-4.2$ xmlstarlet ed -u "/configurations/rules/rule/branch" -v 'DAVID' config.xml > final.xml

I see that the output file was changed to DAVID, But it was changed globally every place the tag "branch" was declared.

But I only want to change it on one subnode, let's say "APP1", What is the command that I need to use? and is there a way to give the value 'DAVID' as a parameter?

  <configurations>
    <smtpHost>smtp3.gmail.com</smtpHost>
    <smtpPort>25</smtpPort>
    <emailFrom>[email protected]</emailFrom>
    <emailSubject>Push notification</emailSubject>
    <!-- Stash general URL-->
    <gitViewerURL>http://mydtbld0005.gmail.com:7990/projects/</gitViewerURL>

    <!-- repositories list and commit URL path per repo -->

    <repositoryViewerPath name="hookTester" path="DevOps/repos/hooktester/commits/"/>

    <separator>#@#</separator>
    <catExe>cat</catExe>
    <catExeWindows>type</catExeWindows>
    <gitExe>git</gitExe>
    <gitExeWindows>C:\\Program Files (x86)\\Git\\cmd\\git.exe</gitExeWindows>
    <gitFolder>/gitdata/alm_mng.git</gitFolder>
    <gitFolderWindows>c:\gitdata\alm_mng.git</gitFolderWindows>
      <rules>
            <rule>
                <name>APP1</name>
                <repo>hookTester</repo>
                <branch>refs/heads/master</branch>
                <emailTo>[email protected]</emailTo>
                <path>F1/ido.xml </path>
            </rule>
            <rule>
                <name>APP2</name>
                <repo>hookTester</repo>
                <branch>refs/heads/master</branch>
                <emailTo>[email protected]</emailTo>
                <path>F2/ido.xml </path>
            </rule>
       </rules>
  </configurations> 
1

1 Answer 1

7

xmlstarlet solution:

new_branch="DAVID"
xmlstarlet ed -u "/configurations/rules/rule[name='APP1']/branch" -v "$new_branch" config.xml > final.xml

The crucial <rule> node should look like:

<rule>
      <name>APP1</name>
      <repo>hookTester</repo>
      <branch>DAVID</branch>
      <emailTo>[email protected]</emailTo>
      <path>F1/ido.xml </path>
    </rule>

You are also able to modify the initial file inplace by applying global -L option:

xmlstarlet ed -L -u ... config.xml

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .