Create xml file using a content from another xml file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Create xml file using a content from another xml file
# 1  
Old 06-14-2012
Create xml file using a content from another xml file

I need to create a xml file(master.xml) with contents from another xml files(children). I have below list of xml files in a temporary location (C:/temp/xmls)

Code:
1. child1.xml
2. child2.xml

Below is the content of the child1.xml & child2.xml files,
child1.xml
Code:
<root>
    <emp>
          <name>sam</name>
         <rollno>10</rollno>
    </emp>
</root>

child2.xml
Code:
<dept>
    <emp-dep>
          <name>sam</name>
         <dname>dept1</dname>
    </emp-dep>
</dept>

Now i need to create the master.xml using the content of the above two child xmls. Below is the expected output of master.xml
Code:
<master>
    <root>
           <emp>
                 <name>sam</name>
                 <rollno>10</rollno>
           </emp>
    </root>
    <dept>
          <emp-dep>
                 <name>sam</name>
                <dname>dept1</dname>
        </emp-dep>
     </dept>
</master>

Please help to do this using shell scripting.
# 2  
Old 06-14-2012
Code:
( echo "<master>"; cat child1.xml child2.xml ; echo "</master>" ) > master.xml

This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-14-2012
Quote:
Originally Posted by Corona688
Code:
( echo "<master>"; cat child1.xml child2.xml ; echo "</master>" ) > master.xml

Works perfectly. Thank you for your help!
# 4  
Old 06-14-2012
Code:
$ awk -vM="master>" 'NR==1{print "<"M}{print}END{print "</"M}' child1.xml child2.xml

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Create a XML file for each row from the csv file

I have a CSV file that looks like this: File,Name,birthdate,Amount File1.xml,Name1,01.02.19,1000 File2.xml,Name2 01.02.20,1000 File3.xml,Name3,01.02.21,1000 I need it to turn it into an XML file for each row, My ultimate goal is for the File1.xml look like this: <?xml version="1.0"... (5 Replies)
Discussion started by: lxdorney
5 Replies

2. Shell Programming and Scripting

Extract strings from XML files and create a new XML

Hello everybody, I have a double mission with some XML files, which is pretty challenging for my actual beginner UNIX knowledge. I need to extract some strings from multiple XML files and create a new XML file with the searched strings.. The original XML files contain the source code for... (12 Replies)
Discussion started by: milano.churchil
12 Replies

3. 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

4. UNIX for Dummies Questions & Answers

Grep content in xml file

I have an xml file with header as below. <Provider xmlns="http://www.xyzx.gov/xyz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xyzx.gov/xyz xyz.xsd" SCHEMA_VERSION="2.5" PROVIDER="5"> I want to get the schema version here that is 2.5 and put in a... (7 Replies)
Discussion started by: Ariean
7 Replies

5. Shell Programming and Scripting

Extracting content from xml file

Hello All, Hope you are doing well!!!!! I have a small code in the below format in xml file: <UML:ModelElement.taggedValue> <UML:TaggedValue tag="documentation" value="This sequence&#xA;&#xA;HLD_EA_0001X&#xA;HLD_DOORS_002X"/> <UML:TaggedValue tag="documentation" value="This... (11 Replies)
Discussion started by: suvendu4urs
11 Replies

6. Shell Programming and Scripting

Help required in Splitting a xml file into multiple and appending it in another .xml file

HI All, I have to split a xml file into multiple xml files and append it in another .xml file. for example below is a sample xml and using shell script i have to split it into three xml files and append all the three xmls in a .xml file. Can some one help plz. eg: <?xml version="1.0"?>... (4 Replies)
Discussion started by: ganesan kulasek
4 Replies

7. Shell Programming and Scripting

Need to replace particular content in a xml file

Hi, My requirement is to find a text and replace it with another in a XML file. I am new to Unix,Please provide some suggestion to achieve. Find: <Style ss:ID="ColumnHeader1"> Replace with: <Style ss:ID="ColumnHeader1"> <Borders> <Border ss:Position="Bottom"... (4 Replies)
Discussion started by: cnraja
4 Replies

8. Shell Programming and Scripting

Extract XML content from a file

310439 2012-01-11 03:44:42,291 INFO PutServlet:? - Content of the Message is:="1.0" encoding="UTF-8"?><ESP_SSIA_ACC_FEED> 310440 <BATCH_ID>12345678519</BATCH_ID> 310441 <UID>3498748823</UID> 310442 <FEED_TYPE>FULL</FEED_TYPE> 310443 <MART_NAME>SSIA_DM_TRANSACTIONS</MART_NAME> 310444... (11 Replies)
Discussion started by: arukuku
11 Replies

9. Shell Programming and Scripting

appending content in a xml file

Please help me on this..... i have a file which has following content: <IPCoreProducerConfig> <Producer> <config> <key>machineId</key> <value>machine1</value> </config> <config> ... (4 Replies)
Discussion started by: Aditya.Gurgaon
4 Replies

10. Shell Programming and Scripting

Parse an XML task list to create each task.xml file

I have an task definition listing xml file that contains a list of tasks such as <TASKLIST <TASK definition="Completion date" id="Taskname1" Some other <CODE name="Code12" <Parameter pname="Dog" input="5.6" units="feet" etc /Parameter> <Parameter... (3 Replies)
Discussion started by: MissI
3 Replies
Login or Register to Ask a Question