Xan-Kun Clark-Davis
Xan-Kun Clark-Davis

Reputation: 2843

Why is this a bad idea (and is it?)

I am working on this project and someone came up with an XML strucutre. I am quite sure, that this is not the way XML is supposed to be used, but I am also aware, that this is quite a matter of perspective.

The sequence in question is

 <TestDetailsProperties>
    <Property Type="String"           Name="TestDetails_String1"     ValueChar="TestDetails - AdditionalText1"/>
    <Property Type="Decimal"          Name="TestDetails_Decimal1"    ValueNum="1.23"/>
    <Property Type="Time"             Name="TestDetails_Time2"       ValueTime="10:11:12"/>
    <Property Type="Date"             Name="TestDetails_Date2"       ValueDate="2000-01-01"/>
    <Property Type="Integer"          Name="TestDetails_Integer2"    ValueInt="234"/>
    <Property Type="String"           Name="TestDetails_String2"     ValueChar="TestDetails - ZusatzText2"/>
    <Property Type="Decimal"          Name="TestDetails_Decimal2"    ValueNum="4.33"/>
    <Property Type="DateTime"         Name="TestDetails_DateTime1"   ValueDateTime="2000-01-03T01:01:01"/>
    <Property Type="Integer"          Name="TestDetails_Integer1"    ValueInt="42"/>
    <Property Type="Date"             Name="TestDetails_Date1"       ValueDate="2000-01-02"/>
    <Property Type="Time"             Name="TestDetails_Time1"       ValueTime="10:30:12"/>
    <Property Type="DateTime"         Name="TestDetails_DateTime2"   ValueDateTime="2000-01-12T20:34:12"/>
 </TestDetailsProperties>

My question is, what are the technical reasons why not to do it this way. Are there plausible arguments what problems should be expected?

I am aware, that this might not be a good stackoverflow question but I searched for the matter and everything I could find just says it's bad and you shouldn't do it, but not exactly why. I couldn't find another place to turn to and if you have any suggestion for a better place I will be glad to move this question.

The purpose is to store data about an automated test and this is the part where the details about the test are stored.

I have the feeling I am missing something, but I can't tell what.

Upvotes: 1

Views: 60

Answers (1)

Eric Duminil
Eric Duminil

Reputation: 54263

There could be a few improvements :

  • Name before Type, for readability.
  • If Name always starts with TestDetails_ and this prefix could be read from a parent node, the prefix could be removed.
  • Value attribute for every node instead of a different attribute name for each different type. This would greatly simplify the logic for parsing the XML

Other than that, it looks fine and would be parsed in a few lines with any C#/Java/Python/Ruby library.

Upvotes: 1

Related Questions