Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-26-2008, 02:26 PM
Member
 
Join Date: Nov 2008
Posts: 5
Rep Power: 0
sakhawn is on a distinguished road
Default Merge 2 different XML files in Java with similar text values
Hi,

I have two files to merge using Java based on a similar text identifier:

File 1:
<ListRecords>
<record>
<header>
<identifier>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</identifier>
<datestamp>2007-05-29T15:55:00Z</datestamp>
<datestampasdatetime>2007-05-29T17:55:00+02:00</datestampasdatetime>
</header>
<metadata>
<lom xsi:schemaLocation="some url">
<general >
<identifier>
<catalog>oai</catalog>
<entry>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</entry>
</identifier
<title>
<langstring>
<value>Graduation mw. S. de Caralt</value>
<language>en</language>
</langstring>
</title>
<catalogentry>
<catalog>nl.wur.wurtv</catalog>
<entry>
<langstring>
<value>2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</value>
<language>x-none</language>
</langstring>
</entry>
</catalogentry>
<grouplanguage>en</grouplanguage>
<description>
<langstring>
<value>Sponge Culture: Learning from Biology and Ecology</value>
<language>en</language>
</langstring>
</description>
</general>
<lifecycle xmlns="" />
<metametadata >
<metadatascheme>LORENET</metadatascheme>
</metametadata>
</lom>
</metadata>
</record>
<….More Records here…..!>
</ListRecords>

File 2:
<ListRecords>
<record>
<header>
<identifier>some value herer</identifier>
<datestamp>2008-07-14T09:23:25Z</datestamp>
</header>
<metadata>
<group xsi:schemaLocation="some url">
<title>User manipulating this</title>
<feed>
<title>My feed</title>
<url>no.url.available</url>
<item>
<guid>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</guid>
<events>
<event>
<dateTime>2008-03-26T13:27:49.00</dateTime>
<action>
<actionType>doSomeAtcion</actionType>
</action>
</event>
</events>
</item>
</feed>
</group>
</metadata>
</record>
<....More Records here....!>
</ListRecords>

I want to merge <metadata> element and all its sub elements from file 1 into the file 2 within its <metadata> element based on unique text of element "<identifier>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</identifier>" in file 1and similarly <guid>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</guid> in file 2.
There are almost 10 records to merge in a similar way..

Any suggestions and guidelines will be highly appreciated.

Thnx.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-30-2008, 08:11 PM
Member
 
Join Date: Nov 2008
Posts: 5
Rep Power: 0
sakhawn is on a distinguished road
Default
I didn't got any reply from anybody :-( The task might not be clear i clarify it again.. I want to do it in XSLT...

Both files have top elements <ListRecords> and then <record> This means that this <record> is one unique record based on <identifer> value in file1 (line 4) and <guid> value in file2 (line 14). This unique record of these similar id's in both files have different data elements i mean different fields. I want to merge this unique record of mentioned ID from file 1 into file 2.

There is this <metadata> element in both files, file1 (line 8 to 42) and in file2 (line 7 to 26) so i want to simply copy this <metadata> element and elements in between (sub-elements) till line 43 from file 1 into file 2 after file2's <metadata> element ends at line 26 and after that last elements would be then simply be <record> and <ListRecords>
There are 10 unique records in both files and final file should mention all of them in a similar way so i hope if one is correctly merged others follow the same template match.

Output file might look like:
<ListRecords>
<record>
<header>
<identifier>some value herer</identifier>
<datestamp>2008-07-14T09:23:25Z</datestamp>
</header>
<metadata>
<group xsi:schemaLocation="some url">
<title>User manipulating this</title>
<feed>
<title>My feed</title>
<url>no.url.available</url>
<item>
<guid>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</guid>
<events>
<event>
<dateTime>2008-03-26T13:27:49.00</dateTime>
<action>
<actionType>doSomeAtcion</actionType>
</action>
</event>
</events>
</item>
</feed>
</group>
</metadata>
<!...Metadata elements and sub elements from file 1 merged here based on unique id...>
<metadata>
<lom xsi:schemaLocation="some url">
<general >
<identifier>
<catalog>oai</catalog>
<entry>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</entry>
</identifier
<title>
<langstring>
<value>Graduation mw. S. de Caralt</value>
<language>en</language>
</langstring>
</title>
<catalogentry>
<catalog>nl.wur.wurtv</catalog>
<entry>
<langstring>
<value>2c7ba037-52a6-4323-97dd-b6ea1cdbfd18</value>
<language>x-none</language>
</langstring>
</entry>
</catalogentry>
<grouplanguage>en</grouplanguage>
<description>
<langstring>
<value>Sponge Culture: Learning from Biology and Ecology</value>
<language>en</language>
</langstring>
</description>
</general>
<lifecycle xmlns="" />
<metametadata >
<metadatascheme>LORENET</metadatascheme>
</metametadata>
</lom>
</metadata>
<!....The data from file 1 that is copied ends here...>
</record>
</ListRecords>

I hope this is clear and someone will help me and provide guidelines as i am totally new to XSLT ...

Best Regards

Please help me as i am really worried and first task in a new language is always such a headache

Best Regards
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-26-2009, 08:44 AM
Member
 
Join Date: Jun 2008
Posts: 55
Rep Power: 0
devunion is on a distinguished road
Default
I've done similr thing with StAX XML API. May be you can use DOM in your case. Why do you want to use XSLT?
__________________
Try Controls4J - Advanced Swing Components.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-26-2009, 11:45 AM
Member
 
Join Date: Nov 2008
Posts: 5
Rep Power: 0
sakhawn is on a distinguished road
Default
hi,

Well i used jdom to complete the task ...
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 02-26-2009, 12:00 PM
Member
 
Join Date: Jun 2008
Posts: 55
Rep Power: 0
devunion is on a distinguished road
Default
I've found interstting article on ibm.com. Type in google "Merge XML documents with StAX". You can use it when size of files that need to be merget is significant. Or when you need to improve performance.
__________________
Try Controls4J - Advanced Swing Components.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 02-26-2009, 12:03 PM
Member
 
Join Date: Nov 2008
Posts: 5
Rep Power: 0
sakhawn is on a distinguished road
Default
well its almost similar to what i did with Jdom, comparing the unique id's and then merging the cloned data from file 2 into file 1 and outputting it to a new file...
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 02-26-2009, 12:05 PM
Member
 
Join Date: Nov 2008
Posts: 5
Rep Power: 0
sakhawn is on a distinguished road
Default
now i have to transform that merged file (bascically LOM data instances) into another metadata schema (Dublin Core) and for that i definitley need XSLT and i have no experience with XSLT :-(
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge Two Xml files ???? alwz_nikhil XML 4 12-30-2009 03:59 PM
Behaving text files like binary files Farzaneh New To Java 2 08-27-2008 04:20 PM
Java Application Interface similar with Windows Themes Heracles Choe AWT / Swing 9 05-02-2008 04:47 AM
Does OS intervene when reading Java text files Tina G Advanced Java 1 04-07-2008 03:29 PM
How do merge two xml files into one xml? veera XML 1 03-27-2008 06:06 PM


All times are GMT +2. The time now is 08:56 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org