Creating a larger .xml file from a template(sample file)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Creating a larger .xml file from a template(sample file)
# 1  
Old 10-26-2012
Creating a larger .xml file from a template(sample file)

Dear All,

I have a template xml file like below.

Code:
....Some---Header.......
<SignalPreference>
        ...
        <SignalName>STRING</SignalName>
        ...
</SignalPreference>
......Some formatting text.......
<SignalPreference>
        .........
        <SignalName>STRING</SignalName>
</SignalPreference>
....Some footer text......

I want to create an actual .xml like below.
For 2 instances of my signals output shown below, preserving all header, footer and other formatting tags.

Code:
....Some---Header....... ## Must preserve all the header tags
<SignalPreference>
        ...   #Must preserve this part as it is
        <SignalName>STRING1</SignalName>
        ...  #Must preserve this part as it is
</SignalPreference>
<SignalPreference>
        ...  #Must preserve this part as it is
        <SignalName>STRING2</SignalName>
        ...  #Must preserve this part as it is
</SignalPreference>

......Some formatting text.......   ### must Preserve this as it is

<SignalPreference>
        .........  #Must preserve this part as it is
        <SignalName>STRING1</SignalName>
        ......... #Must preserve this part as it is
</SignalPreference>
<SignalPreference>
        ...  #Must preserve this part as it is
        <SignalName>STRING2</SignalName>
        ...  #Must preserve this part as it is
</SignalPreference>

....Some footer text......  ### Must preserve this as it is.

where STRING1,STRING2 etc are from one more text file signal.txt.
cat Signal.txt
Code:
STRING1
STRING2
........ so on
up to 10000 STRINGS

Currently I am manually replicating the <SignalPreference>.. </SignalPreference> tag portions and replacing <SignalName>STRING </SignalName> with my desired string based on line number using grep and sed commands. But this is becoming a very tedious task as I have many tags to replace with.

Thanks
Sidda
# 2  
Old 10-26-2012
Check out the below example, you should be able to modify it to do what you want:
Code:
$ cat t
STRING1
STRING2
STRING3
STRING4


## perl script
print "....Some---Header....... ## Must preserve all the header tags\n";
open ( STRINGS, "</temp/tmp/t") or die ("***Error- Couldn't open file: C:/temp/tmp/t, $!\n");
while ( <STRINGS> ) {
  chomp;
  print "<SignalPreference>\n";
  print "        ...   #Must preserve this part as it is\n";
  print "        <SignalName>$_</SignalName>\n";
  print "        ...  #Must preserve this part as it is\n";
  print "</SignalPreference>\n";
  print "\n";
  print "......Some formatting text.......   ### must Preserve this as it is\n";
}
close STRINGS;
print "....Some footer text......  ### Must preserve this as it is.\n";


$ test.pl
....Some---Header....... ## Must preserve all the header tags
<SignalPreference>
        ...   #Must preserve this part as it is
        <SignalName>STRING1</SignalName>
        ...  #Must preserve this part as it is
</SignalPreference>

......Some formatting text.......   ### must Preserve this as it is
<SignalPreference>
        ...   #Must preserve this part as it is
        <SignalName>STRING2</SignalName>
        ...  #Must preserve this part as it is
</SignalPreference>

......Some formatting text.......   ### must Preserve this as it is
<SignalPreference>
        ...   #Must preserve this part as it is
        <SignalName>STRING3</SignalName>
        ...  #Must preserve this part as it is
</SignalPreference>

......Some formatting text.......   ### must Preserve this as it is
<SignalPreference>
        ...   #Must preserve this part as it is
        <SignalName>STRING4</SignalName>
        ...  #Must preserve this part as it is
</SignalPreference>

......Some formatting text.......   ### must Preserve this as it is
....Some footer text......  ### Must preserve this as it is.

# 3  
Old 10-26-2012
Thanks Spacebar.. but looks some issue in print command

Hi Spacebar,

I am working on the perl script you mentioned.
Can you let me know on how to print some text containing
Code:
""

in it using perl command
Code:
print

. ??
Example: I have below text to be printed with print.
Code:
<?xml version="1.0" encoding="utf-8"?>

Except this looks like I can do rest of the things.

Regards
Sidda
# 4  
Old 10-26-2012
You can do it like this:
Code:
print '<?xml version="1.0" encoding="utf-8"?>';

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inputing info from a CSV file and filling a template file

Hi, I have a .csv file that contains a variety of fields for 60 clients: USERNAME, PASSWORD, and COMMENTS. I have a template file which contains a great deal of data for each client and has the fields USERNAME, PASSWORD, and COMMENTS that has to be filled with the values of USERNAME,... (1 Reply)
Discussion started by: mojoman
1 Replies

2. UNIX for Dummies Questions & Answers

XML File Generation - Template Help

Hi, I have hit a bit of a brick wall.:confused: need the following code edited: echo "<?xml version=\"1.0\"?><dailyBalance_ROWSET>" > ${DataDir}/${extract_script}${ApplicationDate}.${Suffix} RunSQL ${extract_script} ${ActionFlag} echo "</dailyBalance_ROWSET>" >>... (2 Replies)
Discussion started by: Xergxes7
2 Replies

3. Shell Programming and Scripting

Creating multiple xml tag lines in a file

Hi All, Can someone tell me how can we create same xml tag lines based on the number of lines present in other file and replace the Name variable vaule present in other file. basically I have this xml line <typ:RequestKey NameType="RIC" Name="A1" Service="DDA"/> and say I... (4 Replies)
Discussion started by: Optimus81
4 Replies

4. Shell Programming and Scripting

Add column info from one file to larger second file

Hi, long time reader, first time poster. I've done some searching so please if this is a repeated post excuse the duplicate, but what I have are two files roughly like so: File 1: A W B X C Y D Z File 2: A 1 C 2 D 3 And what I would like to get out is... (4 Replies)
Discussion started by: wallysb01
4 Replies

5. Shell Programming and Scripting

KSH - help needed for creating a script to generate xml file from text file

Dear Members, I have a table in Oracle DB and one of its column name is INFO which has data in text format which we need to fetch in a script and create an xml file of a new table from the input. The contents of a single cell of INFO column is like: Area:app - aam Clean Up Criteria:... (0 Replies)
Discussion started by: Yoodit
0 Replies

6. UNIX for Advanced & Expert Users

Can someone help me with creating RPM sample i need ?

i know there are tons n tons of documentation out there to help me out to understand this.. but wen i read it, its to confusing for me.. i would really wish a kind hearted person on this forum can come out with a sample spec file for the example steps that i need for the RPM. This will make me... (0 Replies)
Discussion started by: bladez
0 Replies

7. Shell Programming and Scripting

xmlstarlet template parse small xml file

I have a file like: <?xml version="1.0" encoding="UTF-8" standalone="no"?> <geonames> <geoname> <toponymName>Palos Verdes</toponymName> <name>Palos Verdes</name> <lat>42.1628912</lat> <lng>-123.6481235</lng> <geonameId>5718340</geonameId> <countryCode>US</countryCode>... (4 Replies)
Discussion started by: unclecameron
4 Replies

8. UNIX for Dummies Questions & Answers

How to find a file whick is consuming larger disk space in file system

Hello, Can anybody please tell me the command to find out the filesystem or a file which is consuming larger disk space sing i want to find out the file and want to compress it please help me out any help would be appreciated (6 Replies)
Discussion started by: lokeshpashine
6 Replies

9. Shell Programming and Scripting

Need help in creating a Unix Script to parse xml file

Hi All, My requirement is create an unix script to parse the xml file and display the values of the Elements/value between the tags on console. Like say, I would like to fetch the value of errorCode from the below xml which is 'U007' and display it. Can we use SED command for this? I have tried... (10 Replies)
Discussion started by: Anil.Wmg
10 Replies

10. Shell Programming and Scripting

Sample Unix script file to convert .xml to .csv

Dear all, Can you send me a script file the changes .xml to .csv file. Thanks, Srinivasa (4 Replies)
Discussion started by: srinivasaphani
4 Replies
Login or Register to Ask a Question