Here's why I use XML Schemas ... Why do you use XML Schemas?

Hi Folks,

I use XML Schemas to check that data meets the expectations and constraints of my business. 

For example, my business supports these credit cards: MasterCard, Visa, and American Express. My business expects purchase orders it receives to use one of those credit cards. My business transmits purchase requests using one of those credit cards. To express my business expectation/constraint in a way that is machine-processable, I created an XML Schema which enumerates the supported credit cards:

    <xs:simpleType name="CreditCards">
        <xs:restriction base="xs:string">
            <xs:enumeration value="MasterCard" />
            <xs:enumeration value="Visa" />
            <xs:enumeration value="American Express" />
        </xs:restriction>
    </xs:simpleType>

Using that simpleType, these datum can be identified as not acceptable:

     Diners Club
     Hello World
     delete * from * 

So, I use XML Schemas to ensure (as best I can) that my business applications receive legitimate data and don't receive bad data (and conversely, that my business applications transmit legitimate data and not bad data).

As a corollary, I don't create XML Schemas with unconstrained data types like this:

    <xs:simpleType name="CreditCards">
        <xs:restriction base="xs:string" />
    </xs:simpleType>

That does not specify my business expectation/constraint. The consequence of its use is that it will unnecessarily expose my business applications to potentially undesirable data such as: 

     Diners Club
     Hello World
     delete * from *

Strong data typing helps me to ensure that my business applications receive legitimate data and don't receive bad data (and conversely, that my business applications transmit legitimate data and not bad data).

I create XML Schemas with strong data typing. I use XML Schemas to ensure that inbound and outbound data meets my expectations and business constraints.

Why do you use XML Schemas?

/Roger

Received on Monday, 18 April 2011 14:00:55 UTC