XML: what to use as list separator

There are two ways to specify lists of values ​​in XML. Option 1:

<Database Name="myDatabase">
    <Table Name="myTable1" />
    <Table Name="myTable2" />
    <Table Name="myTable3" />
    ...
</Database>

      

Option 2:

<Database Name="myDatabase" Tables="myTable1 myTable2 myTable3 ..." />

      

It is clear that Option 1 is cleaner and can be extended to a simpler one, but in many cases Option 2 is more readable and "user friendly".

When using option 2, what should be used as the separator? The XML Schema standard seems to prefer spaces, whereas some real world examples use commas instead.

Is there any special reason to choose one over the other (assuming the values ​​contain neither whitspaces nor commas)?

+2


a source to share


4 answers


No!

I think you should use option 3:

<Database Name="myDatabase"> 
    <Tables>myTable1 myTable2 myTable3</Tables>
    ... 
</Database> 

      

Seriously!



If you have a bunch of metadata owned by an entity represented by an element <Database>

, then there is little justification for putting "some" of that data into an attribute, while "other" data is represented as additional children as specified ...

.

I believe the main criterion for the shape of your XML should be useful:

  • If you have other data specific to each table - like the names and types of the columns in the table - then you want the table items to be items so that you can attach all of that data to a specific table and you can apply a schema to that data ... This means option 1.

  • If the tables are the only "leaf" nodes in the view - in other words, if there is no ancillary data defined for each table, and there is no additional data defined for the database - then the list of tables is stored as a xs:list

    in the XML attribute (option 2) it seems me beautiful.

  • if the tables are leaf nodes, but there are other leaf nodes at the same level, then you should use option 3.

The objection that some people have with "the way it looks" seems completely unfounded to me as well, like a general rationalization of why infant boys should be circumcised. There is an irrational bias there.

+1


a source


As a programmer, I seem to ignore whitespace when looking through the list. It looks like there is something wrong with that.

I would go for a wrist more natural for me as dividers.

On the other hand, XML (or other markup languages) prefer spaces as separators, as in



<Database Name="myDatabase" Tables="myTable1 myTable2 myTable3 ..." />

      

There is no comma separating different attributes (name, tables), etc.

There is no clear parsing advantage for either option, since in both cases you will need to get rid of the extra whitespace between the elements (myTable1, myTable2, myTable3) or (myTable1 myTable2 myTable3).

+2


a source


For separating a value to be done with a programming language ideally (even though XPath and XSLT provide functions), space seems to be a natural delimiter in XML, but CSS uses a semicolon and the other common delimiter is a comma, although neither them is not like XML as a white space, since the W3C XML Schema Recommendation has something for lists ( <xs:list>

) in which allowed values ​​are separated by a space.

To make this problem pointless, skip to option 1. As mentioned by someone else, it is much more accessible and will make it easier to program as well.

+2


a source


Your Option 1 allows for much more efficient extraction of XPath structural information and analysis.

Option 2 might make it a little easier for a human to read, but I'll definitely go for # 1.

If you prefer to use the attribute, I doubt the choice of delimiter matters.

Also, you probably want to avoid using the '<' character, which is invalid in attribute values ​​...

+1


a source







All Articles