Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

cheapest way to join several XML into a single one ... (XSLT vs JDOM)

Thread view: 
nospawn - 07 Apr 2006 15:50 GMT
Hi all,

I right now need to join several XML files sharing the same schema
into a single consolidated one e.g.

my_doc_1
<key1>
   <key2>
        my_value_doc_1_key_2
   </key2>
   <key3>
        my_value_doc_1_key_3
   </key3>
<key1>

my_doc_2
<key1>
   <key2>
        my_value_doc_2_key_2
   </key2>
   <key3>
        my_value_doc_2_key_3
   </key3>
<key1>

Would generate

my_consolidated_doc:
<key1>
   <key2>
        <my_doc_1>my_value_doc_1_key_2</my_doc_1>
        <my_doc_2>my_value_doc_2_key_2</my_doc_2>
   </key2>
   <key3>
        <my_doc_1>my_value_doc_1_key_3</my_doc_1>
        <my_doc_2>my_value_doc_2_key_3</my_doc_2>
   </key3>
<key1>

and the other way around too  ... having my_consolidated_doc
get to my_doc_1 and my_doc_2.

Cheapest way according to you? JDOM vs XLST another very
desirable feature is that the transformation does not rely on the
structure so this process will be agnostic to schema refactorings.

TIA,
Best Regards,
GA
Alex Hunsley - 07 Apr 2006 16:10 GMT
> Hi all,
>
[quoted text clipped - 39 lines]
>
> Cheapest way according to you? JDOM vs XLST

Neither choice screams out "obvious" to me. What would be easiest to put
into place in your current situation? JDOM or XSLT?
XSLT could be quite elegant (depending on what exact rules you have for
your merging).

> another very
> desirable feature is that the transformation does not rely on the
> structure so this process will be agnostic to schema refactorings.

You're still going to have to rely on some "facts" about your XML though
in order to do the merging. For example, what makes an element a valid
target for 'merging', as <key1> is in your example above? Its name? Its
depth in the XML? etc.
nospawn - 07 Apr 2006 16:20 GMT
Hi Alex,

First of all many thanks for your feedback.

For me was more obvious the JDO solution though. Because
doing something like this would become slightly of a nightmare
using XSLT, also because somehow with XSLT you would
always endup requiring to specify a XPath explicitly and this
is precisely what I would like to avoid.

Using JDOM on the other hand, you dont care about the
node names as long as they match. Structural differences
are treated as an union with complete empty values for the
missing keys in the document missing them something like
what xop does with its + operator:
http://www.living-pages.de/de/projects/xop/

Once more many thanks for your assistance.

Best Regards,
GA
Alex Hunsley - 08 Apr 2006 00:37 GMT
> Hi Alex,
>
[quoted text clipped - 5 lines]
> always endup requiring to specify a XPath explicitly and this
> is precisely what I would like to avoid.

It all depends on how much of a wiz you are at XSLT and all that jazz.
I would probably prefer JDOM myself as a more familiar, straightforward
option. OTOH, I'm sure there is some clever XSLT that would do things
generically without having to hard code paths...

> Using JDOM on the other hand, you dont care about the
> node names as long as they match. Structural differences
[quoted text clipped - 4 lines]
>
> Once more many thanks for your assistance.

Ah, thanks for that link, I hadn't heard of xop before!


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.