Re: Repeating elements with fixed attribute values

Hi Jeffrey,

King, Jeffrey (Mission Systems) <Jeff.King@ngc.com> writes:

> However, I am wondering that if XML Schema 1.0 does not support it,
> then maybe it's trying to tell me it's not good approach.  Are there
> any reasons (other than XML Schema 1.0 does not support it) why using
> the design I presented below is poor?

You are overloading the same entity (the 'field' element) with many
"roles" (e.g., it can be field1, field2, etc.). The different roles
are distinguished by a combination of values in attributes/elements.
A simpler design would be to have one element for one and only one
role and make this role explicit in element's name, for example:

<root>
  <word name="one">
    <field1 number="1">any string here</field>
    <field2 number="2">any string here</field>
    <field3 number="3">any string here</field>
    ...
  </word>
  <word name="two">
    <field4 number="4">any string here</field>
    <field5 number="5">any string here</field>
    <field6 number="6">any string here</field>
    ...
  </word>
</Thanks>

Now you can use the XML Schema 1.0 mechanisms to make the 'number'
attribute fixed to a specific value. In fact, because there appears
to be a 1-to-1 relationship between element's name and attribute's
value, you can get rid of the attribute all together since it does
not carry any useful information (its value is implied by element's
name).

Boris

-- 
Boris Kolpackov
Code Synthesis Tools CC
http://www.codesynthesis.com
XML Parsing and XML Schema Validation for Embedded Systems

Received on Saturday, 5 January 2008 15:34:54 UTC