Edit XML using xmlstarlet only in one subnode
Clash 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>
xml xmlstarlet
add a comment |Â
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>
xml xmlstarlet
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
add a comment |Â
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>
xml xmlstarlet
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>
xml xmlstarlet
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
add a comment |Â
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
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
answered Dec 6 '17 at 15:20
RomanPerekhrest
22.4k12145
22.4k12145
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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