Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


sub-elements with empty context vs. element text

From: DrDavey@-----.---
To: NULL
Date: 3/1/2007 4:11:00 PM

What are the advantages/disadvantages of using a choice of a several
"sub-"elements with empty content (and no attributes) vs. simple
content.  Here's an example:

Using simple content:
<process>xyz</process>

Using empty content sub-element:
<process><xyz/></process>

Assume in both cases the xyz part has a limited domain, i.e., it can
be xyz, abc, or efg, but no other values make sense.  Of course some
day, I might want to extend it to include rst.

The XML Schema for the empty content sub-element version looks
something like this:

<xsd:complexType name="ProcessType>
   <xsd:complexContent/>
</xsd:complexType>

This defines ProcessType as having empty content.  I can then use this
to define the types of processing I want to allow as follows:

<xsd:element name = "process" type="ProcessChoiceType"/>

<xsd:complexType name="ProcessChoiceType">
   <xsd:complexContent>
      <xsd:choice minOccurs="1" maxOccurs="1">
         <xsd:element name="abc" type="ProcessType"/>
         <xsd:element name="efg" type="ProcessType"/>
         <xsd:element name="xyz" type="ProcessType"/>
         <xsd:element name="extented_process" type="ProcessType"
abstract="true"/>
      </xsd:choice>
   </xsd:complexContent>
</xsd:complexType>

The abstract element extended_process is added to permit extension.
Then I can add new types of processing as follows:

<xsd:element name="rst" substitutionGroup="extended_process"/>

The XML Schema for the simple content version would replace the above
definition of ProcessChoiceType with the following:

<xsd:simpleType name="ProcessChoiceType">
   <xsd:restriction base="xsd:token">
      <xsd:enumeration value="abc"/>
      <xsd:enumeration value="efg"/>
      <xsd:enumeration value="xyz"/>
   <xsd:restriction/>
</xsd:simpleType>

My understanding is the only way to extend the enumeration is to
define a new type, NewProcessChoiceType, using a union.  However, I
don't know of any way to change the declaration of the <process>
element to use this new type.

So my initial analysis is that the empty content sub-elements are more
extensible.  However, I've only been seriously studying XML Schema for
about a week.  So I'm looking for guidance on these two choices.  I
understand that a third alternative would be to use an attribute,
e.g., <process name="xyz"/>, but I don't think I can restrict the
domain of the name attribute using XML Schema, which defeats the whole
point of this discussion.

Thanks in advance for your opinions.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent