tags:

views:

61

answers:

3

My Java application's save files are in XML, and in certain cases, a user might want to merge two save files together. What packages have people used to do this? Any caveats to offer?

+1  A: 

This question is a little broad given we don't know the size of the files, what kind of data they store or what kind of data conflicts there could be between two files.

Given two files with no potentially conflicting items and no ordering requirements, you can load them both up as DOM documents, create a third output DOM document and import the children from the two source files into the root element of the third, before saving it.

For larger files this might be memory intensive, so you might want to use SAX or STAX processing (which is basically stream processing for XML).

If you can provide more details people can give you a better answer.

Jherico
A: 

"Merge" can be interpreted in many different ways and depends on the semantics of the data being merged. For instance, when merging two items do you choose one over the other or combine their attributes and contained items? Any intelligent solution will have to answer that question, and others, for each type of object and sub-object being merged.

Jim Garrison
+1  A: 

I came across this link on XML merging shortly after reading your post.

Strawberry