vdv@dyomedea.com, @evlist (identica, twitter, skype, ...)
The beauty of XML is that it can be self-documenting and easy to comprehend by humans.
Sorry, I disagree on the timing of this submission ... I think JSON has already been embraced ... we've moved on, for all the reasons that you state.
--Assigned_Reviewer_3
It remains an important topic and this proposed paper seems to make a useful contribution to the debate.
--Assigned_Reviewer_4
By accepting it I think we're putting a lot of trust in the author to create something where the detail is worthwhile.
--Assigned_Reviewer_4
But we have only 30 minutes...
Change, even slightly, your perspective on JSON and XML.
--Eric van der Vlist
<?xml version="1.0" encoding="UTF-8" ?> <person> <firstName>John</firstName> <lastName>Smith</lastName> <age>25</age> <address> <streetAddress>21 2nd Street</streetAddress> <city>New York</city> <state>NY</state> <postalCode>10021</postalCode> </address> <phoneNumber> <type>home</type> <number>212 555-1234</number> </phoneNumber> <phoneNumber> <type>fax</type> <number>646 555-4567</number> </phoneNumber> </person> |
{ "person": { "firstName": "John", "lastName": "Smith", "age": "25", "address": { "streetAddress": "21 2nd Street", "city": "New York", "state": "NY", "postalCode": "10021" }, "phoneNumber": [ { "type": "home", "number": "212 555-1234" }, { "type": "fax", "number": "646 555-4567" } ] } } |
When they describe the same object...
Their data models are different
Hmmm... Which one?
No data model there...
Its purpose is to provide a consistent set of definitions for use in other specifications that need to refer to the information in a well-formed XML document
--W3C
the augmented infoset which results from conformant processing as defined in this [XML Schema] specification
--W3C
When you hear the words "XML Data Model", always ask "which one?"
When you hear the word "XDM", always ask "which version? which flavor?"
The XML Data Model which we'll be considering here is the subset of the XML Infoset used by the various versions of flavors of the XDM.
They have
Legal characters are tab, carriage return, line feed, and the legal characters of Unicode and ISO/IEC 10646
This excludes "control" characters below #x20 other than tab, CR and LF.
JSON can represent four primitive types (strings, numbers, booleans, and null) and two structured types (objects and arrays).
--RFC4627
An object is an unordered collection of zero or more name/value pairs, where a name is a string and a value is a string, number, boolean, null, object, or array.
--RFC4627
A string is a sequence of zero or more Unicode characters.
.../... a name is a string.
--RFC4627
Not a data model issue...
Oh, no, not yet another JSON to XML mapping proposal!
--Michael Kay listening Steve Pemberton present JSON support in XForms 2.0 at XML Prague 2012
Acme Corporation has developed a set of RESTfull web services which sends and receives data oriented XML documents. Due to popular demand, they want to support JSON in addition to XML.
Acme Web Design has developed a set of RESTFull web services which sends and receives JSON documents. Their business users require the same information in XML.
<?xml version="1.0" encoding="UTF-8"?> <anvil reference="acme-5103"> <weight unit="pound">9.5</weight> <composition>best wrought iron</composition> <price currency="USD">.15</price> </anvil>
{ "anvil": { "-reference": "acme-5103", "weight": { "-unit": "pound", "#text": "9.5" }, "composition": "best wrought iron", "price": { "-currency": "USD", "#text": ".15" } } }
{ "anvil": { "reference": "acme-5103", "weight": { "unit": "pound", "value": 9.5 }, "composition": "best wrought iron", "prices": { "usd": 0.15, "eur": 0.12 } } }
<?xml version="1.0" encoding="UTF-8" ?> <anvil> <reference>acme-5103</reference> <weight> <unit>pound</unit> <value>9.5</value> </weight> <composition>best wrought iron</composition> <prices> <usd>0.15</usd> <eur>0.12</eur> </prices> </anvil>
<?xml version="1.0" encoding="UTF-8"?> <anvil reference="acme-5103"> <weight unit="pound">9.5</weight> <composition>best wrought iron</composition> <price currency="USD">.15</price> </anvil>
{ "anvil": { "reference": "acme-5103", "weight": { "unit": "pound", "value": 9.5 }, "composition": "best wrought iron", "prices": { "usd": 0.15, "eur": 0.12 } } }
Easy for a custom bridge (polyglotism required, see next use case)
David Lee presenting JXSON at Balisage 2011
ACME is developing an application which gets anvil descriptions in XML and prices lists in JSON.
Description and price of acme 5103?
<?xml version="1.0" encoding="UTF-8"?> <anvils> <anvil reference="acme 5103"> <weight unit="pound">9.5</weight> <composition>best wrought iron</composition> </anvil> <anvil reference="acme 5104"> <weight unit="pound">15</weight> <composition>ultimate best wrought iron</composition> </anvil> </anvils>
{ "acme 5103": { "usd": 0.15, "eur": 0.12 }, "acme 5104": { "usd": 0.20, "eur": 0.17 } }
var descriptions = <anvils> <anvil reference="acme 5103"> <weight unit="pound">9.5</weight> <composition>best wrought iron</composition> </anvil> <anvil reference="acme 5104"> <weight unit="pound">15</weight> <composition>ultimate best wrought iron</composition> </anvil> </anvils>; var prices = { "acme 5103": { "usd": 0.15, "eur": 0.12 }, "acme 5104": { "usd": 0.20, "eur": 0.17 } }; var anvil = "acme 5103"; print("Weight: " + descriptions.anvil.(@reference == anvil).weight + ", price: $" + prices[anvil].usd);
import json prices = json.loads(''' { "acme 5103": { "usd": 0.15, "eur": 0.12 }, "acme 5104": { "usd": 0.20, "eur": 0.17 } }''') import xml.etree.ElementTree as ET descriptions = ET.fromstring('''<?xml version="1.0" encoding="UTF-8"?> <anvils> <anvil reference="acme 5103"> <weight unit="pound">9.5</weight> <composition>best wrought iron</composition> </anvil> <anvil reference="acme 5104"> <weight unit="pound">15</weight> <composition>ultimate best wrought iron</composition> </anvil> </anvils>''') anvil = "acme 5103" print "Weight: " \ + descriptions.findall("anvil[@reference='" + anvil + "']/weight")[0].text \ + ", price: $%.2f" % prices[anvil]['usd']
Acme software needs to store JSON documents in their big XML database. These are arbitrary JSON documents which can be tough to map into XML. There is still a need to query the corpus and storing them as plain text in a root element is not an option either.
{ "anvil": { "reference": "acme-5103", "weight": { "unit": "pound", "value": 9.5 }, "composition": "best wrought iron", "prices": { "usd": 0.15, "eur": 0.12 } } }
Be prepared for a verbose next slide using χίμαιραλ (chimeral)
<?xml version="1.0" encoding="UTF-8"?> <χ:data-model xmlns:χ="http://χίμαιραλ.com#"> <χ:map> <χ:entry key="anvil" keyType="string"> <χ:map> <χ:entry key="weight" keyType="string"> <χ:map> <χ:entry key="unit" keyType="string"> <χ:atomic-value type="string">pound</χ:atomic-value> </χ:entry> <χ:entry key="value" keyType="string"> <χ:atomic-value type="number">9.5</χ:atomic-value> </χ:entry> </χ:map> </χ:entry> <χ:entry key="composition" keyType="string"> <χ:atomic-value type="string">best wrought iron</χ:atomic-value> </χ:entry> <χ:entry key="prices" keyType="string"> <χ:map> <χ:entry key="eur" keyType="string"> <χ:atomic-value type="number">0.12</χ:atomic-value> </χ:entry> <χ:entry key="usd" keyType="string"> <χ:atomic-value type="number">0.15</χ:atomic-value> </χ:entry> </χ:map> </χ:entry> <χ:entry key="reference" keyType="string"> <χ:atomic-value type="string">acme-5103</χ:atomic-value> </χ:entry> </χ:map> </χ:entry> </χ:map> </χ:data-model>
JSON is a popular format for exchange of structured data on the web: it is specified in [JSON]. This section describes facilities allowing JSON data to be processed using XSLT.
--XSL Transformations (XSLT) Version 3.0 - Working Draft 10 July 2012
Mike Kay at XML Prague 2012
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="3.0"> <xsl:output method="text"/> <xsl:variable name="descriptions"> <anvils> <anvil reference="acme 5103"> <weight unit="pound">9.5</weight> <composition>best wrought iron</composition> </anvil> <anvil reference="acme 5104"> <weight unit="pound">15</weight> <composition>ultimate best wrought iron</composition> </anvil> </anvils> </xsl:variable> <xsl:variable name="json-prices" as="xs:string"><![CDATA[ { "acme 5103": { "usd": 0.15, "eur": 0.12 }, "acme 5104": { "usd": 0.20, "eur": 0.17 } } </xsl:variable> <xsl:variable name="prices" select="parse-json($json-prices)"/> <xsl:variable name="anvil">acme 5103</xsl:variable> <xsl:template match="/"> <xsl:text>Weight: </xsl:text> <xsl:value-of select="$descriptions/anvils/anvil[@reference = $anvil]/weight"/> <xsl:text>, price: $</xsl:text> <xsl:value-of select="$prices($anvil)('usd')"/> </xsl:template> </xsl:stylesheet>
A polyglot approach.
XQuery is well suited for hierarchical semi-structured data. Many implementations exist, and can easily be adapted to add JSON support.
--Jonathan Robie XML Prague 2012
Jonathan Robie at XML Prague 2012
XForms allows the initialization, processing and serialization of instances whose data come from a JSON source by transforming the JSON value into an XML instance, and serializing it back out as JSON. The XML version of JSON has been designed to be round-trippable, and to allow XPath selectors that resemble the equivalent Javascript selectors.
Steven Pemberton at XML Prague 2012
A bridge
If XML is not as universal as it looked a few years ago – might we extend the language (no pun intended), restoring the universality?
--Hans-Jürgen Rennau Balisage 2012
Hans-Jürgen Rennau at Balisage 2012
Elements get 2 new properties
An element can be either:
If we take the pain to update the XML data model we deserve "fromage et dessert"!
That's the goal of χίμαιραλ (chimeral) / superset
Limitations are removed so that an element can be used as both as:
Use a spacebar or arrow keys to navigate