W3C home > Mailing lists > Public > xmlschema-dev@w3.org > January 2008

RE: Repeating elements with fixed attribute values

From: King, Jeffrey (Mission Systems) <Jeff.King@ngc.com>
Date: Mon, 7 Jan 2008 06:54:44 -0600
Message-ID: <2A77548F22867A4B8C38F7608F3B40CC572501@XMBIL132.northgrum.com>
To: <xmlschema-dev@w3.org>

Thank you everybody for your valuable comments, it's helping me to think
through this.  This is a great forum.

I think I have done a poor job of explaining the exact scenario I am
working with.  In the example I posted:

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

The attribute "name" would be the field name in the database, and the
"field1" is the value from stored in that field.  I do not think that
the "field" or "word" element has many roles-- the "name" attribute
always contains data from the "name" field, and the "number" attribute
always contains data from the "number" field etc.

The thing I am struggling with is that the alternative seems to be to
put the data that is contained in the attribute values into the element
names.  I would have to do it for both the "word" element and the
"field" elements so the example above would look like this:

<one>
    <field1  number="1">any string here</field1>
    <field2  number="2">any string here</field2>
    <field3  number="3">any string here</field3>
</one>
<two>
    <field4 number="4">any string here</field4>
    <field5 number="5">any string here</field5>
    <field6 number="6">any string here</field6>
</two>

Actually, the reality is not as neat as it looks here.  "field1" would
be whatever is in the "name" field for that record.  It could be
anything, even multiple words such as "SOURCE INDICATOR"-- in which case
I would have to translate this into a valid element name like
"SOURCE_INDICATOR" before using it.  Every document would have it's own
set of element names so there would be no commonality among the
documents.  I also think that looking at an xml document formed in this
manner would be difficult to understand, and it would be more tricky to
create stylesheets that work for all of the documents.

Thank you all for your comments.


Jeffrey King

-----Original Message-----
From: Boris Kolpackov [mailto:boris@codesynthesis.com] 
Sent: Saturday, January 05, 2008 10:21 AM
To: King, Jeffrey (Mission Systems)
Cc: xmlschema-dev@w3.org
Subject: 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 Monday, 7 January 2008 12:54:57 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:15:01 GMT