views:

13

answers:

1

I am currently working with a large XML file which includes <Count>123</Count> for some elements and does not have them for others. For instance:

<Animals>
  <Pigs>
    <Pig ...>
      ...
    </Pig>
    <Pig ...>
      ...
    </Pig>
    <PricePerPound>13<PricePerPound>
    <Count>2</Count>
  </Pigs>
  <Chikens>
    <Chicken ...>
      ...
    </Chicken>
    <Chicken ...>
      ...
    </Chicken>
    <PricePerPound>12<PricePerPound>
    <!-- No Count -->
  </Chickens>
  ...
</Animals>

So, the actual file is a lot more complicated, and has nothing to do with animals. I just will not reveal all of the details. The file is loaded once at start and saved once on exit, it weighs about 2 to 5 Megabytes, depending on the content.

On one hand, having <Count> could potentially speed up loading time a bit, but maybe not. On the other, this value is not necessary, it is derived, and God forbid it deviates from what it should have been. It might not be that much work to compute/retrieve the count of nodes with particular name (note the <PricePerPound> node - it can screw up the count if one were to ignore the names of the nodes). I do not have too much flexibility in redesigning the XML, plus it would be too much work. Either adding or removing <Count> everywhere would be a lot of work (all of that bulky logic which reads and writes portions of the XML ...), but I want to pick an approach for the future now, so that I can do this in increments.

So, which way seems better - add or remove <Count> everywhere, or perhaps make it optional, and write it on Save, and eventually make it mandatory, or something else?

+1  A: 

Unless there is a good performance reason for having it there, I'd agree that it is not a good design decision and would vote for removing it from the structure - it can be easily calculated and can become corrupt.

bigtang