[Home] [By Thread] [By Date] [Recent Entries]

  • From: "Pete Cordell" <petexmldev@c...>
  • To: "Michael Kay" <mike@s...>,<xml-dev@l...>
  • Date: Thu, 9 Dec 2010 13:00:51 -0000

Original Message From: "Michael Kay"

> One thing I'd like to bring in from the JSON world is some basic duck 
> typing.
>
> <person age=90 dob=1920-03-04 name="Ronald" retired=true 
> children=["Barbara", "Michael"]/>
>
> There's no need for a DTD or schema to do simple type annotation.


I'm not convinced that the typing in JSON is a key feature.  If you don't 
know what a 'wibble' is, knowing it is an integer doesn't really help you 
much.  I think it's an artifact of JSON being based on Javascript that it 
has these different forms for integers vs. strings etc.  A program does need 
to know whether something is an integer.  A transfer format just needs to 
get across the wire some suitable representation of wibble that a program 
can use.  As part of knowing how to deal with a wibble, the program knows 
that a wibble is an integer.

I would say your sample is fairly exlicit typing.  (I guess there is 
ambiguity around whether 'age' is an integer, float or decimal.)  But I 
think duck typing would work pretty much as well if you had regular XML:

<person age='90' dob='1920-03-04' name="Ronald" retired='true'
children='["Barbara", "Michael"]'/>

In the case of Javascript it would be sensible to duck type age to a number 
as it doesn't need much provocation to convert a number to a string.  For 
example:

var json = { "Int" : 12, "Int2" : 14 };
var result = "The sum is: " + json.Int + json.Int2;
document.write( result );

yields:

The sum is: 1214

Pete Cordell
Codalogic Ltd
Interface XML to C++ the easy way using C++ XML
data binding to convert XSD schemas to C++ classes.
Visit http://codalogic.com/lmx/ or http://www.xml2cpp.com
for more info





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


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member