Edit XML using xmlstarlet only in one subnode

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












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>GitPushNotifier@hpe.com</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:gitdataalm_mng.git</gitFolderWindows>
<rules>
<rule>
<name>APP1</name>
<repo>hookTester</repo>
<branch>refs/heads/master</branch>
<emailTo>test@gmail.com</emailTo>
<path>F1/ido.xml </path>
</rule>
<rule>
<name>APP2</name>
<repo>hookTester</repo>
<branch>refs/heads/master</branch>
<emailTo>test@gmail.com</emailTo>
<path>F2/ido.xml </path>
</rule>
</rules>
</configurations>






share|improve this question


















  • 1




    I've found this page has some good xpath examples: msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
    – glenn jackman
    Dec 6 '17 at 15:42














up vote
2
down vote

favorite












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>GitPushNotifier@hpe.com</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:gitdataalm_mng.git</gitFolderWindows>
<rules>
<rule>
<name>APP1</name>
<repo>hookTester</repo>
<branch>refs/heads/master</branch>
<emailTo>test@gmail.com</emailTo>
<path>F1/ido.xml </path>
</rule>
<rule>
<name>APP2</name>
<repo>hookTester</repo>
<branch>refs/heads/master</branch>
<emailTo>test@gmail.com</emailTo>
<path>F2/ido.xml </path>
</rule>
</rules>
</configurations>






share|improve this question


















  • 1




    I've found this page has some good xpath examples: msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
    – glenn jackman
    Dec 6 '17 at 15:42












up vote
2
down vote

favorite









up vote
2
down vote

favorite











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>GitPushNotifier@hpe.com</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:gitdataalm_mng.git</gitFolderWindows>
<rules>
<rule>
<name>APP1</name>
<repo>hookTester</repo>
<branch>refs/heads/master</branch>
<emailTo>test@gmail.com</emailTo>
<path>F1/ido.xml </path>
</rule>
<rule>
<name>APP2</name>
<repo>hookTester</repo>
<branch>refs/heads/master</branch>
<emailTo>test@gmail.com</emailTo>
<path>F2/ido.xml </path>
</rule>
</rules>
</configurations>






share|improve this question














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>GitPushNotifier@hpe.com</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:gitdataalm_mng.git</gitFolderWindows>
<rules>
<rule>
<name>APP1</name>
<repo>hookTester</repo>
<branch>refs/heads/master</branch>
<emailTo>test@gmail.com</emailTo>
<path>F1/ido.xml </path>
</rule>
<rule>
<name>APP2</name>
<repo>hookTester</repo>
<branch>refs/heads/master</branch>
<emailTo>test@gmail.com</emailTo>
<path>F2/ido.xml </path>
</rule>
</rules>
</configurations>








share|improve this question













share|improve this question




share|improve this question








edited Dec 6 '17 at 17:42









Jeff Schaller

32k848109




32k848109










asked Dec 6 '17 at 14:55









Shachar Hamuzim Rajuan

1134




1134







  • 1




    I've found this page has some good xpath examples: msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
    – glenn jackman
    Dec 6 '17 at 15:42












  • 1




    I've found this page has some good xpath examples: msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
    – glenn jackman
    Dec 6 '17 at 15:42







1




1




I've found this page has some good xpath examples: msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
– glenn jackman
Dec 6 '17 at 15:42




I've found this page has some good xpath examples: msdn.microsoft.com/en-us/library/ms256086(v=vs.110).aspx
– glenn jackman
Dec 6 '17 at 15:42










1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










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>test@gmail.com</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





share|improve this answer




















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409229%2fedit-xml-using-xmlstarlet-only-in-one-subnode%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    3
    down vote



    accepted










    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>test@gmail.com</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





    share|improve this answer
























      up vote
      3
      down vote



      accepted










      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>test@gmail.com</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





      share|improve this answer






















        up vote
        3
        down vote



        accepted







        up vote
        3
        down vote



        accepted






        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>test@gmail.com</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





        share|improve this answer












        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>test@gmail.com</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






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 6 '17 at 15:20









        RomanPerekhrest

        22.4k12145




        22.4k12145



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f409229%2fedit-xml-using-xmlstarlet-only-in-one-subnode%23new-answer', 'question_page');

            );

            Post as a guest













































































            Popular posts from this blog

            How to check contact read email or not when send email to Individual?

            Bahrain

            Postfix configuration issue with fips on centos 7; mailgun relay