A method and apparatus are provided for merging two electronic documents,
one or both of which contain markup language. The source document and the
destination document are compared to identify the matching blocks and the
difference blocks. Each of the matching blocks containing a markup
language tag for which only a start tag or an end tag has been matched
are identified. The identified blocks are then split so that the matched
markup language tags are no longer matched. All matching blocks are also
split that contain a markup language tag for which either the start tag
or the end tag has been matched to a different tag in the other document.
Any matching blocks containing markup language tags that would create
overlapping tags when merged are then split. The matching and difference
blocks are then merged into a merged document in an order that ensures
that all markup language tags contained in the merged document are well
formed.