I need to merge two XML log files. One log file contains a trace with position updates. The other log file contains the received messages. There can be multiple received messages without having a position update inbetween.
Both logs have timestamps:
- The trace log uses <date> (eg. 14.7.2012 11:08:07)
- The message log uses a unix timestamp <timeStamp> (eg. 1342264087)
The structure of the trace looks like:
<item>
<date>14.7.2012 11:08:07.222</date>
<MyPosition>
// Position data
</MyPosition>
</item>
<item>
<date>14.7.2012 12:13:07.112</date>
<MyPosition>
// Position data
</MyPosition>
</item>
...
The structure of the messages is like that:
<Message>
// some content of the message
<subTag>
<timeStamp>1342264087</timeStamp>
</subTag>
// other content of the message
</Message>
<Message>
// same as above
</Message>
...
When doing the merging, the timestamps should be read (also converting/comparing "date" and "timestamp") and all positions and messages added in the right order.
The position data can just be added as it is. However, the message should be placed inside of <item> tags, a <date> tag should be added (based on the messages' unix time) and the <Message> tag should be replaced by <m:Message type="received"> tags.
Unfortunately not a "simple" merging, especially as the size of the log files lays between 5 MB and 700 MB... :-/
A result could look like this:
<item>
<date>14.7.2012 11:08:07.222</date>
<MyPosition>
// Position data
</MyPosition>
</item>
<item>
<date>14.7.2012 11:09:10.867</date>
<m:Message type="received">
// content of the <Message>
</m:Message>
</item>
<item>
<date>14.7.2012 12:10:11.447</date>
<m:Message type="received">
// content of the former <Message>
</m:Message>
</item>
<item>
<date>14.7.2012 12:13:07.112</date>
<MyPosition>
// Position data
</MyPosition>
</item>
<item>
<date>14.7.2012 12:17:11.227</date>
<m:Message type="received">
// content of the former <Message>
</m:Message>
</item>
...
Are there any tools which support a merging like that? Or is there any simple way to solve this using java?
I really appreciate any tips on how to solve this matter.
This XSLT 2.0 transformation (for convenience containing the small message-log sample inline):
when performed on the provided Trace-log XML document:
merges the two logs as required:
Note: In the real case the Message-log will be obtained using the
document()
function.