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

N

nospawn

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
 
A

Alex Hunsley

nospawn said:
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

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

nospawn

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
 
A

Alex Hunsley

nospawn said:
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.

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top