[Dev] XML Developer's on the list

Tom Bryan dev@trilug.org
Sun, 23 Jun 2002 21:17:24 +0500


This isn't specifically a Linux development question, but given the way Gnome 
and KDE have embraced XML, I thought it might be of interest...

I want to use some XML-based data exports/imports for a software product.  
There's one problem in the XML Schema design for which I haven't been able to 
find a good/"best practices"/recommended solution.  See the schema snippet 
below for an example of what I mean.

<?xml version = "1.0" encoding = "UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   elementFormDefault = "qualified">

   <!-- These roles are specific to each customer using the software  -->
   <!-- That is, two customers may have different sets of valid roles -->
   <xsd:simpleType name = "roleType">
     <xsd:restriction base = "xsd:string">
       <xsd:enumeration value = "CONSUMER"/>
       <xsd:enumeration value = "WHOLESALE"/>
     </xsd:restriction>
   </xsd:simpleType>

   <!-- This schema defines a set of customers, each with a role -->
   <xsd:element name="CustomerSet">
   <xsd:complexType>
     <xsd:sequence>
       <!-- Each customer has a name and a role -->
       <xsd:element name="Customer" minOccurs="0" maxOccurs="unbounded">
         <xsd:complexType>
           <xsd:attribute name="id" use="required" type="xsd:string"/>
           <xsd:attribute name="role" use="required" type="roleType"/>
         </xsd:complexType>
       </xsd:element>
     </xsd:sequence>
   </xsd:complexType>
   </xsd:element>
</xsd:schema>

An example document might look like this 
<?xml version="1.0" encoding="UTF-8"?>
<CustomerSet>
 <Customer id="123456789" role="CONSUMER" />
</CustomerSet>

I'd like the roles to be validated by the XML parser, but the set of 
valid roles varies depending upon which customer is using the software. 
Is there a way to do this without having a completely different version of the 
schema at each customer site?  Am I stuck with using xsd:string for the role 
attribute and doing all of the validation in the code (driven by a 
site-specific properties file)?  Would you somehow separate out the portions 
that change per customer and let those responsible for installing the system 
tweak the customer-specific portions of the schema?

Thanks,
---Tom