Merge XML file (to same root)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge XML file (to same root)
# 1  
Old 11-21-2012
Code [SOLVED] Merge XML file (to same root)

HI

I am looking for a easy way to merge 2 xml files like the following

file 1: will have a structure like this

Code:
<Group GID="TOTO" NAME="TOTO" UNITS="1.0">
               <Property NAME="Id" VALUE="TOTO"/>
               <Property NAME="Currency" VALUE="USD"/>

        <Group GID="ACG" NAME="ACG">
                  <Property NAME="Id" VALUE="ACG"/>
                  <Property NAME="Name" VALUE="ACG"/>

               <Group GID="ACG_1" NAME="ACG_1">
                     <Property NAME="Id" VALUE="ACG_1"/>
                     <Property NAME="Name" VALUE="ACG_1"/>
			<Position POS_SZ="-1" />
                  	<Position POS_SZ="-2" />
                  	<Position POS_SZ="-3" />
                  	<Position POS_SZ="-4" />
               </Group>

               <Group GID="ACG_2" NAME="ACG_2">
                     <Property NAME="Id" VALUE="ACG_2"/>
                     <Property NAME="Name" VALUE="ACG_2"/>
               </Group>
	</Group>
</Group>


file 2: will have a structure like this

Code:
<Group GID="TOTO" NAME="TOTO" UNITS="1.0">
               <Property NAME="Id" VALUE="TOTO"/>
               <Property NAME="Currency" VALUE="USD"/>

        <Group GID="ACG" NAME="ACG">
                  <Property NAME="Id" VALUE="ACG"/>
                  <Property NAME="Name" VALUE="ACG"/>

               <Group GID="ACG_1_bis" NAME="ACG_1_bis">
                     <Property NAME="Id" VALUE="ACG_1_bis"/>
                     <Property NAME="Name" VALUE="ACG_1_bis"/>
			<Position POS_SZ="-1" />
                  	<Position POS_SZ="-2" />
                  	<Position POS_SZ="-3" />
                  	<Position POS_SZ="-4" />
               </Group>
	</Group>

        <Group GID="ABC" NAME="ABC">
                     <Property NAME="Id" VALUE="ABC"/>
                     <Property NAME="Name" VALUE="ABC"/>
        </Group>

</Group>


and i would like an output file looking like this

Code:
<Group GID="TOTO" NAME="TOTO" UNITS="1.0">
               <Property NAME="Id" VALUE="TOTO"/>
               <Property NAME="Currency" VALUE="USD"/>

        <Group GID="ACG" NAME="ACG">
                  <Property NAME="Id" VALUE="ACG"/>
                  <Property NAME="Name" VALUE="ACG"/>

               <Group GID="ACG_1" NAME="ACG_1">
                     <Property NAME="Id" VALUE="ACG_1"/>
                     <Property NAME="Name" VALUE="ACG_1"/>
			<Position POS_SZ="-1" />
                  	<Position POS_SZ="-2" />
                  	<Position POS_SZ="-3" />
                  	<Position POS_SZ="-4" />
               </Group>

               <Group GID="ACG_1_bis" NAME="ACG_1">
                     <Property NAME="Id" VALUE="ACG_1"/>
                     <Property NAME="Name" VALUE="ACG_1"/>
			<Position POS_SZ="-1" />
                  	<Position POS_SZ="-2" />
                  	<Position POS_SZ="-3" />
                  	<Position POS_SZ="-4" />
               </Group>

               <Group GID="ACG_2" NAME="ACG_2">
                     <Property NAME="Id" VALUE="ACG_2"/>
                     <Property NAME="Name" VALUE="ACG_2"/>
	       </Group>
        </Group>

        <Group GID="ABC" NAME="ABC">
                     <Property NAME="Id" VALUE="ABC"/>
                     <Property NAME="Name" VALUE="ABC"/>
        </Group>

</Group>


any good ideas ?

Last edited by kykyboss; 11-21-2012 at 07:31 PM..
# 2  
Old 11-21-2012
Post the actual data, warts and all, not a simplified tree. XML is notorious for inspiring solutions that work for our data but not yours...
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 11-21-2012
Hi
I reedit my post to put better data as example
# 4  
Old 11-22-2012
Effectively what you want is to merge the two input documents so that equivalent nodes only appear once in the output document. The best way to do this is to use XSLT. Oliver Becker's merge.xslt stylesheet will probably do what you want.

See Merging two XML Documents.
This User Gave Thanks to fpmurphy For This Post:
# 5  
Old 11-22-2012
effectivement cela fonction merci
# 6  
Old 11-22-2012
Quote:
Originally Posted by kykyboss
effectivement cela fonction merci
Google translate gives me 'this function actually thank you'.

I'm not sure what this means.

Could you please post in English?
# 7  
Old 11-22-2012
lol
funny google translator.

it actually mean,
"it is working, thanks" (in french) by Oliver Becker's merge.xslt

for one sec i forgot to wrote in English
This User Gave Thanks to kykyboss For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grepping multiple XML tag results from XML file.

I want to write a one line script that outputs the result of multiple xml tags from a XML file. For example I have a XML file which has below XML tags in the file: <EMAIL>***</EMAIL> <CUSTOMER_ID>****</CUSTOMER_ID> <BRANDID>***</BRANDID> Now I want to grep the values of all these specified... (1 Reply)
Discussion started by: shubh752
1 Replies

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

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

4. Shell Programming and Scripting

How to add the multiple lines of xml tags before a particular xml tag in a file

Hi All, I'm stuck with adding multiple lines(irrespective of line number) to a file before a particular xml tag. Please help me. <A>testing_Location</A> <value>LA</value> <zone>US</zone> <B>Region</B> <value>Russia</value> <zone>Washington</zone> <C>Country</C>... (0 Replies)
Discussion started by: mjavalkar
0 Replies

5. Shell Programming and Scripting

Merge different xml files in one

Dear all, I have a big number of .xml files (130GB) and I would like merge them in one. The problem is that I don't want all tags and all the xml files are the same. Is there any script that I can use? Thank you in advance for your helping! Some files are like: <doctype>TA</doctype>... (0 Replies)
Discussion started by: corfuitl
0 Replies

6. Shell Programming and Scripting

Need to find root element name of XML file

Given this XML: <?xml version="1.0"?> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> <cd> <title>Hide your heart</title> ... (2 Replies)
Discussion started by: ricksj
2 Replies

7. Shell Programming and Scripting

Extracting the Root Element from the XML File

Any help to extract the root element from an XML file will be appreciated. Example: test.xml <?xml version="1.0" encoding="utf-8" ?> <TestXMLMessage> <TestRec> <ID>1000</ID> </TestRec> </TestXMLMessage> Wanted to extract the TestXMLMessage. Regards, Chari (6 Replies)
Discussion started by: sree_chari
6 Replies

8. Shell Programming and Scripting

shell call xalan to transform xml with xslt, but can not find root node

hi experts: i am using xslt to transform xml in shell. But can not find root node of source xml, if i remove the naming space definition in source xml, it works fine. So our the question is how to let xslt know the naming space of srouce xml file? Thanks for your kindly help in... (0 Replies)
Discussion started by: summer_cherry
0 Replies

9. Shell Programming and Scripting

script to merge xml files with options

Hi, I have a very basic knowledge of shell scripting & would like some help with a little problem I have. I sometimes use a program calle phronix & sometimes like to compare its results which are *.xml files. Which is easy enough but a friend wants to avoid typing the path to the files.... (2 Replies)
Discussion started by: ptrbee
2 Replies

10. Shell Programming and Scripting

XML root element

Hi All Can someone please help me with this awk to search an element in a XML file with a particular value and then change the root element. Thanks & Regards Karan (9 Replies)
Discussion started by: karansachdeva
9 Replies
Login or Register to Ask a Question