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

Re: XML data interchange format: Flatter is better

  • From: Mukul Gandhi <gandhi.mukul@gmail.com>
  • To: "Costello, Roger L." <costello@mitre.org>
  • Date: Wed, 29 Oct 2014 20:43:29 +0530

Re:  XML data interchange format: Flatter is better
Hi Roger,
    I think the proposed idea is perhaps nice. I hadn't heard it earlier. For the uses cases you've mentioned, I agree to the benefits you've discussed.

Having said that I think a certain hierarchical XML design is always desirable for domain specific requirements. XML Schema languages have so many features to design XML hierarchies.


On 28 October 2014 01:07, Costello, Roger L. <costello@mitre.org> wrote:
Hi Folks,

Designing data interchange formats can be quick, easy, and inexpensive.

The comments made in this message are intended for this environment:

        The XML is distributed to a broad spectrum of consumers,
        each consumer might perform widely different operations
        on the XML.

I recommend making flat XML. Design your XML to just have a root element, containing a linear sequence of elements.

Be a markup minimalist.

Here are the reasons for my recommendation:

1. Consumers of flat XML can apply powerful parsing techniques to the linear sequence of elements. Thus, consumers can add whatever structure is appropriate for their particular applications to process the data efficiently.

2. XML Schema design and implementation of flat XML is trivial: simply create an XML Schema with a sequential list of element declarations.

3. If, on the other hand, you were to design the XML to have lots of structure, it is a near certainty that the structure will not be suitable for many of your consumer's applications. Further, its structure is likely to hamper powerful parsing techniques.

The "flatter is better" philosophy may be summarized this way:

        I can't predict how my consumers will want the data structured,
        so I won't try to predict. I will let them apply their own structure
        to the data.

Let's take an example. Suppose that you want to model a grape vineyard, with pickers scattered about on the various lots. The following XML is not flat. It's probably a design that most people would come up with. I assert it is a bad design.

<Vineyard>
    <Lot id="1">
        <ripe-grapes>4</ripe-grapes>
        <Picker id="John">
            <metabolism>2</metabolism>
            <grape-wealth>20</grape-wealth>
        </Picker>
    </Lot>
    <Lot id="2">
        <ripe-grapes>3</ripe-grapes>
    </Lot>
    ...
</Vineyard>

That design is well-suited to operations such as this:

        What Pickers are on lot 23?

But it is horrible for operations such as this:

        Move Picker John to Lot 2.

Don't design XML that way. Design XML to be flat, like this:

<Vineyard>
    <lot-number>1</lot-number>
    <ripe-grapes>4</ripe-grapes>
    <picker>John</picker>
    <metabolism>2</metabolism>
    <grape-wealth>20</grape-wealth>
    <lot-number>1</lot-number>
    <ripe-grapes>3</ripe-grapes>
    ...
</Vineyard>

That's a beautiful design. It enables powerful parsing techniques to be applied to it. For instance, one consumer may parse it to generate the above structuring. Another consumer may parse it to generate this radically different structuring:

<Lot id="1">
      <ripe-grapes>4</ripe-grapes>
</Lot>
<Lot id="2">
      <ripe-grapes>3</ripe-grapes>
</Lot>
<Picker id="John" locatedOn="1">
      <metabolism>2</metabolism>
      <grape-wealth>20</grape-wealth>
</Picker>
...

And another consumer may parse it to generate still another structuring.

Each consumer parses the flat XML to create a structuring that is well-suited to their particular application processing.

Are you creating XML "for the long haul"?

Are you creating XML "for a broad, diverse set of clients"?

Are you a manager and don't want to dump a lot of time and money into creating "the perfect XML Schema design"?

Then create flat XML.

Flatter is better!

For more info on parsing flat XML see my recent posts:

Recursive Descent Parsing for XML Developers: http://lists.xml.org/archives/xml-dev/201410/msg00017.html

Bottom-up Parsing for XML Developers: http://lists.xml.org/archives/xml-dev/201409/msg00016.html

Comments welcome.

/Roger




--
Regards,
Mukul Gandhi


[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.