views:

84

answers:

1

I'm co-developing a vehicle information system that reads and presents data from a communication bus. Signaling information on the bus is stored on some kind of database (from the dark ages i'd guess) from which it's only possible to get data out of by extracting a xml-snapshot. Since that wasn't bad enough, someone in upper management thought it was a great idea to treat different parts of the system as different projects (it looked really nice in the organizational chart) which lead to more databases...

It is now my responsibility to merge these xml-files into one and before I start banging my head against the wall i thought it would be a good idea to check with you geniuses if there's any neat solution to my problem.

The structure of the xml is somewhat like this:

<data>
  <frame ID="1001">
    <attributes>
      <name>Frame 1</name>
      <description>The first frame</description>
    </attributes>
    <references/>
  </frame>
  <signal ID="1002">
    <attributes>
      <signalid>1</signalid>
      <name>Signal 1</name>
    </attributes>
    <references>
      <frame ID="1001"/>
    </references>
  </signal>
</data> 

All entities (signals, frames etc.) lies directly under the root element and there can be several of each. The ID is generated when the file is extracted from the database and changes everytime. The only purpose of the id is to link different entities together, "Signal 1" belongs to "Frame 1" and so on...

The unique identifier of an entity differ between the entities but it's often an id, name or combination of some elements.

Since there is an overlap between the projects the second xml-file can look like this:

<data>
  <frame ID="2001">
    <attributes>
      <name>Frame 1</name>
      <description>The first of many frames</description>
    </attributes>
    <references/>
  </frame>
  <signal ID="2002">
    <attributes>
      <signalid>1</signalid>
      <name>Signal 1</name>
    </attributes>
    <references>
      <frame ID="2001"/>
    </references>
  </signal>
  <signal ID="2003">
    <attributes>
      <signalid>2</signalid>
      <name>Signal 2</name>
    </attributes>
    <references>
      <frame ID="2001"/>
    </references>
  </signal>
</data>

As you can see there is now multiple instances of "Frame 1" and "Signal 1" but the second file adds another signal to "Frame 1".

What i'm trying to achieve is to add "Signal 2" to the first file and update the frame reference to 1001.

The best solution i've come up with so far is to do a plain merge (using linq), search the whole file for duplicates, store all related ID's and last but not least replace the deleted ID's with the correct ones.

I'm pretty sure there's no oneliner-solution to my problem (since the problem originates from the crappy database structure), but it'd be stupid not to ask.

A: 

Well as I suppose there was not any fancy solution too my problem. I ended up using the "solution" I described in the question.

Well, on to bigger things!

scim