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]
Re: [xml-dev] XML design: don't use duplicate keys in XML objects

Describing this as a "duplicate key" seems very strange. It's a repeated property.

XML is not JSON, and good practice for JSON doesn't automatically translate to good practice for XML.

The use of wrapper elements in XML in this way is highly debatable. One excellent reason for NOT using them is for schema evolution. If you suddenly find that a book can have more than one ISBN, then it is less disruptive to existing applications to add a second child ISBN element than to add a wrapper around all the ISBNs. In fact it's a particular strength of XML that it allows this. XML works very well with properties that usually occur once but occasionally more often, because the "one" case extends naturally to the "more than one" without requiring a redesign.

Michael Kay
+44 (0) 118 946 5893

On 30 Apr 2015, at 14:30, Costello, Roger L. <costello@mitre.org> wrote:

Hi Folks,


An XML object is an element whose content is a collection of heterogeneous data items. For example, this Book element contains a collection of heterogeneous data items and therefore is an XML object:


<Title>The First and Last Freedom</Title>
<Author>J. Krishnamurti</Author>
<Publisher>Harper &amp; Row</Publisher>


The fact that it is an object becomes more apparent with this graphic:



Recommendation: Don’t create XML objects with duplicate keys. For example, this Book object has duplicate Author keys:


<Title>Parsing Techniques</Title>
<Author>Dick Grune</Author>
<Author>Ceriel Jacobs</Author>




Instead, create a single Authors element whose content is an array:


<Title>Parsing Techniques</Title>
<Authors><Author>Dick Grune</Author><Author>Ceriel Jacobs</Author></Authors>


Now the Book object contains a collection of unique keys. The value of the Authors key is an array of Author elements.


Why follow this recommendation? Here’s why:


1. It enables XML objects to evolve, using the Must-Ignore policy, as I described in yesterday’s message.


2. It enables conversion between XML and programming language objects and databases.


3. It is consistent with rfc 7493 (http://www.rfc-editor.org/rfc/rfc7493.txt) which recommends that no JSON object have duplicate keys.




[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