[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

=?utf-8?Q?Re:_Should_XML_appl?==?utf-8?Q?ications_follow_Postel

  • From: Geert Bormans <geert@gbormans.telenet.be>
  • To: xml-dev <xml-dev@lists.xml.org>
  • Date: Thu, 12 Apr 2018 16:14:08 +0200 (CEST)

=?utf-8?Q?Re:_Should_XML_appl?==?utf-8?Q?ications_follow_Postel
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@l...>
Verzonden: Donderdag 12 april 2018 15:41:43
Onderwerp: 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]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.