XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]
=?utf-8?Q?Re:_[xml-dev]Should_XML_appl?==?utf-8?Q?ications_follow_Postel=E2=80=99s_Law=3F?=

improving data = "" data
strict on output: yes
strict on output by refusing input data and reporting: yes
strict on output by allowing a developer to change the data a business user or information owner entered: often not 


Van: "Roger L. Costello" <costello@mitre.org>
Aan: "xml-dev" <xml-dev@lists.xml.org>
Verzonden: Donderdag 12 april 2018 15:41:43
Onderwerp: [xml-dev]Should XML applications follow Postel’s Law?

Hi Folks,

Postel’s Law says this: Be generous on input, strict on output. This means that the code should be tolerant of variations in its input but should be strictly correct when outputting data. As an example, when you accept a boolean as a string, ignore the case and allow it to be expressed as “1, 0, T, F, Y, N, TRUE, FALSE, YES, NO, etc.”. But when outputting a boolean as a string, stick to one single convention and one single case religiously. [1]

So …………

Suppose an application validates XML inputs against an XML Schema. One part of the schema says that the <isFlyOver> element must contain a Boolean value. Here’s how that element is declared:

<xs:element name="isFlyOver">
   
<xs:simpleType>
       
<xs:restriction base="xs:string">
           
<xs:enumeration value="true" />
           
<xs:enumeration value="false" />
       
</xs:restriction>
   
</xs:simpleType>
</xs:element>

 

That element declaration says XML documents must contain either this:

<isFlyOver>true</isFlyOver>

or this:

<isFlyOver>false</isFlyOver>

Suppose an application receives an XML document containing this:

<isFlyOver>TRUE</isFlyOver>

or this:

<isFlyOver>1</isFlyOver>

Should the application follow Postel’s Law and accept those XML inputs? And then rebuild the XML so that the output strictly adheres to the schema:

<isFlyOver>true</isFlyOver>

That is, the application validates inputs against this slightly looser schema:

<xs:element name="isFlyOver">
   
<xs:simpleType>
       
<xs:restriction base="xs:string">
           
<xs:enumeration value="true" />
           
<xs:enumeration value="TRUE" />
           
<xs:enumeration value="T" />
           
<xs:enumeration value="YES" />
           
<xs:enumeration value="1" />
           
<xs:enumeration value="false" />
           
<xs:enumeration value="FALSE" />
           
<xs:enumeration value="F" />
           
<xs:enumeration value="NO" />
           
<xs:enumeration value="0" />
       
</xs:restriction>
   
</xs:simpleType>
</xs:element>

 

If the input validates against that schema, then the application rebuilds the XML to conform to the strict schema.

Thus, if the input arrives as this:

<isFlyOver>TRUE</isFlyOver>

then the application accepts it and outputs:

<isFlyOver>true</isFlyOver>

What do you think? Good idea for applications to follow Postel’s Law? Bad idea? Good in some applications and bad in others? Thoughts?

/Roger

[1] http://tedwise.com/2009/05/27/generous-on-input-strict-on-output

 

 




[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 1993-2007 XML.org. This site is hosted by OASIS