How to Append the specific data to the xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to Append the specific data to the xml file
# 1  
Old 04-02-2009
PHP How to Append the specific data to the xml file

I have an xml file data as shown below:

<impl name="Nortel" is-enabled="true">
<package-mappings>
<const-mapping target-state="EndPoint"
target-param="cfCNDSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCWSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCFVSubscribed" constant-value="true"/>
</package-mappings>

I want to append few line to the last that is after </package-mappings>

i am using the following script
but it seems to be not working

cat File.xml|sed '/\(.*<impl name=\"Nortel\" *is-enabled=\"true\".*\)/{
N
s:\(.*<impl name=\"Nortel\" *is-enabled=\"true\".*\)\n\( *\)<\/impl>.*$:\1\
\2<attribute max-instances="1" min-instances="0">\
\2 <simple-attribute name="securityLevel" type="number"\
\2is-key-field="false" is-package-defined="false">\
\2</attribute>:
}'

Please some one can help me out in the above issue.


Thank you very much in advance
# 2  
Old 04-02-2009

Code:
data='<impl> .... </impl>
<attribute max-instances="1" min-instances="0">
<simple-attribute name="securityLevel" 
  type="number" is-key-field="false" is-package-defined="false">
</simple-attribute>'

printf "%s\n" "$data" >> File.xml


Last edited by cfajohnson; 04-03-2009 at 04:40 AM..
# 3  
Old 04-03-2009
PHP

Actually my problem is, i have a data like below
<impl name="Nortel" is-enabled="true">
<package-mappings>
<const-mapping target-state="EndPoint"
target-param="cfCNDSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCWSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCFVSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCFBLSubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
target-param="cfCFDASubscribed" constant-value="true"/>
<const-mapping target-state="EndPoint"
</package-mappings>
<attribute max-instances="1" min-instances="0">
<simple-attribute name="lineNumber" type="string"
sub-type="number" is-key-field="false" is-package-defined="false">
<description>Telephone Number.</description>
<help>Subscriber's Telephone Number. </help>
</simple-attribute>
</attribute>

<attribute ....
</attribute>

</impl>

i want to the below data after </package-mappings> and above <attribute tag

below is the regular expression i am using to add but it is adding above
<package-mappings> but i have to add after </package-mappings>

The script i am using is
cat $i|sed '/\(.*<impl name=\"NueraWithNortel\" *is-enabled=\"true\".*\)/{
N
s:\(.*<impl name=\"NueraWithNortel\" *is-enabled=\"true\".*\)\n\( *\)<package-mappings>.*$:\1\
\2<attribute max-instances="1" min-instances="0">\
\2 <simple-attribute name="securityLevel" type="number"\
\2 is-key-field="false" is-package-defined="false">\
\2 <description>securityLevel</description>\
\2 <help>security level of the end pont</help>\
\2 </simple-attribute>\
\2</attribute>\
\2<package-mappings>:
}'
Please help me in resolving the issue
thank you very much in advance.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Moving XML tag/contents after specific XML tag within same file

Hi Forum. I have an XML file with the following requirement to move the <AdditionalAccountHolders> tag and its content right after the <accountHolderName> tag within the same file but I'm not sure how to accomplish this through a Unix script. Any feedback will be greatly appreciated. ... (19 Replies)
Discussion started by: pchang
19 Replies

2. Shell Programming and Scripting

Append a specific keyword in a text file into a new column

All, I have some sample text file(.csv) in the below format. In my actual file there are at least 100K rows. date 03/25/2016 A,B,C D,E,F date 03/26/2016 1,2,3 4,5,6 date 03/27/2016 6,4,3 4,5,6 I require the following output where in the date appeared at different locations need to... (3 Replies)
Discussion started by: ks_reddy
3 Replies

3. Shell Programming and Scripting

Overwrite specific column in xml file with the specific column from adjacent line

I have an xml file dumped from rrd file, that I want to "patch" so the xml file doesn't contain any blank hole in the resulting graph of the rrd file. Here is the file. <!-- 2015-10-12 14:00:00 WIB / 1444633200 --> <row><v> 4.0419731265e+07 </v><v> 4.5045912770e+06... (2 Replies)
Discussion started by: rk4k
2 Replies

4. Shell Programming and Scripting

sed to append on specific line in password file

I have the a group file and my ftp group line looks like this ... (3 Replies)
Discussion started by: slufoot80
3 Replies

5. Shell Programming and Scripting

want to append the data in one file to the another

Hi , i have two log files, i need to combine this as a one log file. i need to do this by SED , test1.log sadadadaadfsaf test2.log adadadadadada i need this in a single file from test 1 to test2.log test2.log(expected result) adadadadadada (7 Replies)
Discussion started by: mhdmehraj
7 Replies

6. Shell Programming and Scripting

read from a specific pattern from one file and append it to another

Hi! Everyone, Say this file1 -------------- line 1 51610183 420001010 0010CTCTLEDPPOO 2151610183 line 2 2151610183 420001010 0030A2TH2 line 3 2151610183 420001010 0040A2TH3 line 4 2151610183 420001010 ... (0 Replies)
Discussion started by: kinkar_ghosh
0 Replies

7. UNIX for Dummies Questions & Answers

append data to file

i want to develop a script newdata that writes new data to a file called items the file items has the following headings columns separated by tabs: channel date time programe if i type executable file newdata on the command line with parameters, it should append it to the items files the... (1 Reply)
Discussion started by: fletcher
1 Replies

8. Shell Programming and Scripting

get the data from sybase and append to the file

How to get the data from the sybase database and append the data obtained into the file. For example, I will get the filename 'temp' from the database. This filename is associated with the number 1.6... This number 1.6 needs to be copied into the file that matches the filename in the... (1 Reply)
Discussion started by: vinay123
1 Replies

9. Shell Programming and Scripting

extract specific data from xml format file.

Hi, I need to extract the start time value (bold, red font) under the '<LogEvent ID="Timer Start">' tag (black bold) from a file with the following pattern. There are other LogEventIDs listed in the file as well, making it harder for me to extract out the specific start time that I need. . .... (7 Replies)
Discussion started by: 60doses
7 Replies
Login or Register to Ask a Question