How to change values in xml file?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to change values in xml file?
# 1  
Old 07-07-2016
How to change values in xml file?

I have xml file like below, i want change the values at default-value place of each argument name using shell script. like
where argument name= protocol and default-value=tcp,
where argument name =port and default-value= 7223,
where argument name = username and default-value=test,

example

Code:
<task-arguments>
      <argument name="protocol" is-required="false" default-value="ssl"/>
      <argument name="port" is-required="true" default-value="7222"/>
      <argument name="username" is-required="true" default-value="admin"/>
</task-arguments>

could some one please help me..

Moderator's Comments:
Mod Comment Pleased post in the right forum. Moving thread

Last edited by Scrutinizer; 07-07-2016 at 08:58 AM.. Reason: code tags
# 2  
Old 07-07-2016
What operating system and shell are you using?

Do you just want to change <argument name> tag data if the tag appears between <task-arguments> and </task-arguments> tags; or do you want to change them everywhere they appear?

Where do the new values come from? Is there a configuration file? Are they given as command-line arguments? Are they to be hardcoded in your script?

Are only the values shown in the example to be replaced, or are all values found in your input file to be replaced?

What is the name of your XML file? Is the name to be given as a parameter to your script? Is the name to be hard coded into your script?

What have you tried to solve this problem on your own?
# 3  
Old 07-07-2016
How to change values in xml file?

Hi Don,
Please see my comment below..
What operating system and shell are you using?
RHEL

Do you just want to change <argument name> tag data if the tag appears between <task-arguments> and </task-arguments> tags; or do you want to change them everywhere they appear?

I want to change the values only the tag b/w <task-arguments> and </task-arguments> tags.

Where do the new values come from? Is there a configuration file? Are they given as command-line arguments? Are they to be hardcoded in your script?

Those values are coming from configuration file..

Are only the values shown in the example to be replaced, or are all values found in your input file to be replaced?

All the values to be replaced which are b/w the tag.

What is the name of your XML file? Is the name to be given as a parameter to your script? Is the name to be hard coded into your script?
monitor.xml and the value is hard coded

What have you tried to solve this problem on your own?
tried like below

Code:
sed -i '/<argument\s\+name="hostname"/s/is-required="*.*"/is-required="$REQ1" default-value="$hostname"/' $file



Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!

Last edited by RudiC; 07-07-2016 at 04:09 PM.. Reason: Added code tags.
# 4  
Old 07-07-2016
My crystal ball is cloudy today and I am having trouble reading over your shoulder...

What is the name of your configuration file?

What is the format of your configuration file?
# 5  
Old 07-08-2016
How to change values in xml file?

Hi Don,,

I Have a script file like abc.sh when i run this script i want to update monitor.xml file like below..

The original file

Code:
<task-arguments>
            <argument name="hostname" is-required="true" default-value="10.211.55.4"/>
            <argument name="protocol" is-required="false" default-value="ssl"/>
            <argument name="port" is-required="true" default-value="7222"/>
            <argument name="username" is-required="true" default-value="admin"/>
            <argument name="password" is-required="true" default-value=""/>
            <argument name="tier" is-required="false" default-value="TIBCO_EMS"/>
            <argument name="emsservername" is-required="false" default-value="Tibco EMS Destinations"/>
            <argument name="showTempQueues" is-required="false" default-value="false"/>
            <argument name="showSysQueues" is-required="false" default-value="false"/>
            <argument name="queuesToExclude" is-required="false" default-value="sample1 sample2"/>
            <argument name="sslIdentityFile" is-required="false" default-value="test/conf/client_identity.p12"/>
            <argument name="sslIdentityPassword" is-required="false" default-value="password"/>
            <argument name="sslTrustedCerts" is-required="false" default-value="test/conf/server_cert.pem"/>
</task-arguments>

The file should update like below.

Code:
<task-arguments>
            <argument name="hostname" is-required="true" default-value="My hostname"/>
            <argument name="protocol" is-required="true" default-value="ssl"/>
            <argument name="port" is-required="true" default-value="7233"/>
            <argument name="username" is-required="true" default-value="admin"/>
            <argument name="password" is-required="true" default-value="admin"/>
            <argument name="tier" is-required="true" default-value="TIBCO_EMS"/>
            <argument name="emsservername" is-required="true" default-value="Tibco EMS Destinations"/>
            <argument name="showTempQueues" is-required="false" default-value="false"/>
            <argument name="showSysQueues" is-required="false" default-value="false"/>
            <argument name="queuesToExclude" is-required="true" default-value="sample1 sample2"/>
            <argument name="sslIdentityFile" is-required="false" default-value="test/conf/client_identity.p12"/>
            <argument name="sslIdentityPassword" is-required="false" default-value="password"/>
            <argument name="sslTrustedCerts" is-required="false" default-value="test/conf/server_cert.pem"/>
</task-arguments>

That means need find each argument name and should update the values accordingly... all values hard coded at script level..

Last edited by Don Cragun; 07-08-2016 at 03:50 AM.. Reason: Delete B tags; add CODE and ICODE tags.
# 6  
Old 07-08-2016
And, what does abc.sh look like now? Please show us the contents of abc.sh (in CODE tags).

And, I ask again, what shell are you using?
# 7  
Old 07-08-2016
How to change values in xml file?

Don,

The values means, Where ever it's highlighted in that place the values should update using my script file.

Code:
<task-arguments>
<argument name="hostname" is-required="true" default-value="My hostname"/>
<argument name="protocol" is-required="true" default-value="ssl"/>
<argument name="port" is-required="true" default-value="7233"/>
<argument name="username" is-required="true" default-value="admin"/>
<argument name="password" is-required="true" default-value="admin"/>
<argument name="tier" is-required="true" default-value="TIBCO_EMS"/>
<argument name="emsservername" is-required="true" default-value="Tibco EMS Destinations"/>
<argument name="showTempQueues" is-required="false" default-value="false"/>
<argument name="showSysQueues" is-required="false" default-value="false"/>
<argument name="queuesToExclude" is-required="true" default-value="sample1 sample2"/>
<argument name="sslIdentityFile" is-required="false" default-value="test/conf/client_identity.p12"/>
<argument name="sslIdentityPassword" is-required="false" default-value="password"/>
<argument name="sslTrustedCerts" is-required="false" default-value="test/conf/server_cert.pem"/>
</task-arguments>

---------- Post updated at 01:35 PM ---------- Previous update was at 01:24 PM ----------

Do,

I need to create new one script file and i am using my shell is !/bin/sh...

Code:
#!/bin/sh
#################################################
set -x
################################################################################
# Script Wide Variables                                                        #
################################################################################
dt=`date`
year=`echo ${dt} | cut -f6 -d ' '`
month=`date +%m`
day=`date +%d`
hr=`date +%H`
min=`date +%M`
diskVolume=/opt
diskSize=100MB
inputs=$*
################################################################################

In this script i am declaring the values like below.

Code:
hostname= 134.com
port=7223
protocal=tcp
username=admin
password=admin..etc..

I hope you understand everything now....

---------- Post updated at 01:40 PM ---------- Previous update was at 01:35 PM ----------

Don,,

I tried using sed command, it working but i am tying is there any another way to update values or not?

Code:
sed -i '/<argument\s\+name="hostname"/s/is-required="*.*"/is-required="${REQ1}" default-value="${hostname}"/' $file

I hope you understand my requirement here...



Moderator's Comments:
Mod Comment Please use code tags as required by forum rules!
Ignoring our requests repeatedly already led to an infraction given to you, and it may result in more severe actions.

Last edited by RudiC; 07-08-2016 at 05:36 AM.. Reason: Added code tags.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep some values from XML file

Dear community, I have a big XML log file containing several rows splitted by tag: <ActivityLogRecord> and </ActivityLogRecord>. An example below. What I need is read the file and extract some value from each tags and put them into one line (each line for every <ActivityLogRecord> tag). So... (5 Replies)
Discussion started by: Lord Spectre
5 Replies

2. UNIX for Dummies Questions & Answers

Reading Xml file and print the values into the text file in columnwise?

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (4 Replies)
Discussion started by: sravanreddy
4 Replies

3. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

4. Shell Programming and Scripting

Comparing delta values of one xml file in other xml file

Hi All, I have two xml files. One is having below input <NameValuePair> <name>Daemon</name> <value>tcp:7474</value> </NameValuePair> <NameValuePair> <name>Network</name> <value></value> </NameValuePair> ... (2 Replies)
Discussion started by: sharsour
2 Replies

5. Shell Programming and Scripting

Extract values from an XML File

Hi, I need to capture all the attributes with delete next to it. The source XML file is attached. The output should contain something like this below: Attributes = legacyExchangeDN Action = Delete Username = Hero Joker Loginid = joker09 OU =... (4 Replies)
Discussion started by: prvnrk
4 Replies

6. Shell Programming and Scripting

Need help to change values in XML using Python? noob help pls!

Hello I am a noob in XML and Python. I am trying to do this for my MSc project about a network simulation and need some help.... I want to change the values shown below: <num_crash_failures>1</num_crash_failures> −<crash_failure_entry> <freeze_at_slot>0</freeze_at_slot>... (0 Replies)
Discussion started by: erhanasd
0 Replies

7. Shell Programming and Scripting

Need help to change XML values with shell scripting for Network Simulation

Hello, I don't have experience in this scripting and I need some help to read a value from an XML file and change it with a random number to use in simulator for different network scenarios. </Description><sim_comm_rounds>35</sim_comm_rounds><num_clusters>1</num_clusters><Clocking> I want to... (5 Replies)
Discussion started by: erhanasd
5 Replies

8. Shell Programming and Scripting

Change values in Log4j.xml using ksh script

Hi, I am new to UNIX and shell scripting. I have to create a shell script(ksh) which parses log4j.xml file for a given webservice name and change the corresponding value from INFO to DEBUG or vice-versa. My log4j.xml looks like:- <!-- Appender WEBSERVICENAME--> <appender... (3 Replies)
Discussion started by: sanjeevcseng
3 Replies

9. UNIX for Dummies Questions & Answers

Extracting values from an XML file

Hello People, I have an xml file from which I need to extract the values of the parameters using UNIX shell commands. Ex : Input is like : <Name>Roger</Name> or <Address>MI</Address> I need the output as just : Roger or MI with the tags removed. Please help. (1 Reply)
Discussion started by: sushant172
1 Replies
Login or Register to Ask a Question