Results 1 to 8 of 8
- 11-26-2008, 01:26 PM #1
Member
- Join Date
- Nov 2008
- Posts
- 5
- Rep Power
- 0
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.
- 11-30-2008, 07:11 PM #2
Member
- Join Date
- Nov 2008
- Posts
- 5
- Rep Power
- 0
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
- 02-26-2009, 07:44 AM #3
Member
- Join Date
- Jun 2008
- Posts
- 56
- Rep Power
- 0
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.
- 02-26-2009, 10:45 AM #4
Member
- Join Date
- Nov 2008
- Posts
- 5
- Rep Power
- 0
hi,
Well i used jdom to complete the task ...
- 02-26-2009, 11:00 AM #5
Member
- Join Date
- Jun 2008
- Posts
- 56
- Rep Power
- 0
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.
- 02-26-2009, 11:03 AM #6
Member
- Join Date
- Nov 2008
- Posts
- 5
- Rep Power
- 0
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...
- 02-26-2009, 11:05 AM #7
Member
- Join Date
- Nov 2008
- Posts
- 5
- Rep Power
- 0
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 :-(
- 04-10-2010, 11:46 AM #8
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
Merge Two Xml files ????
By alwz_nikhil in forum XMLReplies: 5Last Post: 01-18-2011, 09:18 AM -
Behaving text files like binary files
By Farzaneh in forum New To JavaReplies: 2Last Post: 08-27-2008, 03:20 PM -
Java Application Interface similar with Windows Themes
By Heracles Choe in forum AWT / SwingReplies: 9Last Post: 05-02-2008, 03:47 AM -
Does OS intervene when reading Java text files
By Tina G in forum Advanced JavaReplies: 1Last Post: 04-07-2008, 02:29 PM -
How do merge two xml files into one xml?
By veera in forum XMLReplies: 1Last Post: 03-27-2008, 05:06 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks