Subject: [Dev] XML Developer's on the list

From: Tom Bryan <[email-masked]>
Date: 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

---

From: Kevin Sonney <[email-masked]>
Date: 23 Jun 2002 22:26:38 -0400

> valid roles varies depending upon which customer is using the software. 

Hmm. that can make things tricky.

> tweak the customer-specific portions of the schema?

I expect you'll need an xml schema per site if they don't all share the
same role information. One thing that could make this really do-able,
though, is the use of name spaces in your data,  like so:

<?xml version="1.0">
<roles xmlns:sitea="http://sitea.org/schema"
       xmlns:siteb="http://siteb.com/schema"
  <sitea:customerinfo>
      <sitea:customer name="foo"/>
          <sitea:info>DATA</sitea:info>
      </sites:customer>
  </sitea:customerinfo>
  <siteb:customerdata>
      <siteb:customer name="bar"/>
          <siteb:custinfo>DATA2</sitea:custinfo>
      </siteb:customerdata>
  </siteb:cusotmerdata>
</roles>

Each site has it's own name space, and can define their own schema as
needed. 

You probably aught to read the spec at
http://www.w3.org/TR/REC-xml-names/ for complete information.....

-- 
----------------------------------
--         Kevin Sonney         --
--  ICQ: 4855069  AIM: ksonney  --
----------------------------------
320C 0336 3BC4 13EC 4AEC  6AF2 525F CED7 7BB6 12C9
 Crispy Fries -- Neil, http://www.goats.com