Blog Stats
  • Posts - 62
  • Articles - 11
  • Comments - 9
  • Trackbacks - 62

 

XML Next

Continuing my case for XML Next
Compare this:

<?xml version="2.0" ?>
<invoice>
    <number>123456789</number>
    <date>2004/01/01</date>
    <shipper>Fedex</shipper>
    <customer>Microsoft</customer>
    <address>
        <street>One Microsoft Way</street>
        <city>Redmond</city>
        <state>WA</state>
        <postal>12345</postal>
    </address>
    <items>
        <item>ABCD1233|LCD TV 60"|125|357.95</item>
        <item>ABCD1234|LCD TV 61"|126|358.95</item>
        <item>ABCD1235|LCD TV 62"|127|359.95</item>
        <item>ABCD1236|LCD TV 63"|128|360.95</item>
        <item>ABCD1237|LCD TV 64"|129|361.95</item>
        <item>ABCD1238|LCD TV 65"|130|362.95</item>
        <item>ABCD1239|LCD TV 66"|131|363.95</item>
        <item>ABCD1240|LCD TV 67"|132|364.95</item>
        <item>ABCD1241|LCD TV 68"|133|365.95</item>
        <item>ABCD1242|LCD TV 69"|134|366.95</item>
    </items>
    <totals>
        <amount>1234.56</amount>
        <discount>123.45</discount>
        <taxes>234.56</taxes>
        <total>2345.67</total>
    </totals>
</invoice>

to this:

<?xml version="1.0" ?>
<invoice>
    <number>123456789</number>
    <date>2004/01/01</date>
    <shipper>Fedex</shipper>
    <customer>Microsoft</customer>
    <address>
        <street>One Microsoft Way</street>
        <city>Redmond</city>
        <state>WA</state>
        <postal>12345</postal>
    </address>
    <items>
        <item>
            <code>ABCD1234</code>
            <description>LCD TV 60"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
        <item>
            <code>ABCD1235</code>
            <description>LCD TV 61"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
        <item>
            <code>ABCD1236</code>
            <description>LCD TV 62"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
        <item>
            <code>ABCD1237</code>
            <description>LCD TV 63"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
        <item>
            <code>ABCD1238</code>
            <description>LCD TV 64"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
        <item>
            <code>ABCD1239</code>
            <description>LCD TV 65"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
        <item>
            <code>ABCD1240</code>
            <description>LCD TV 66"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
        <item>
            <code>ABCD1241</code>
            <description>LCD TV 67"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
        <item>
            <code>ABCD1242</code>
            <description>LCD TV 68"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
        <item>
            <code>ABCD1243</code>
            <description>LCD TV 69"</description>
            <quantity>125</quantity>
            <unitprice>357.95</unitprice>
        </item>
    </items>
    <totals>
        <amount>1234.56</amount>
        <discount>123.45</discount>
        <taxes>234.56</taxes>
        <total>2345.67</total>
    </totals>
</invoice>

Now,

Beware of a much more powerful format with a parser already available in every single computer in the world, Javascript Objects:

invoice={
    number  :'123456789',
    date    :'2004/01/01',
    shipper :'Fedex',
    customer:'Microsoft',
    address:{
        street:'One Microsoft Way',
        city  :'Redmond',
        state :'WA',
        postal:'12345'
    },
    items:[
        ['ABCD1233','LCD TV 60"',125,357.95],
        ['ABCD1234','LCD TV 61"',126,358.95],
        ['ABCD1235','LCD TV 62"',127,359.95],
        ['ABCD1236','LCD TV 63"',128,360.95],
        ['ABCD1237','LCD TV 64"',129,361.95],
        ['ABCD1238','LCD TV 65"',130,362.95],
        ['ABCD1239','LCD TV 66"',131,363.95],
        ['ABCD1240','LCD TV 67"',132,364.95],
        ['ABCD1241','LCD TV 68"',133,365.95],
        ['ABCD1242','LCD TV 69"',134,366.95]
    ],
    totals:{
        amount  :1234.56,
        discount: 123.45,
        taxes   : 234.56,
        Total   :2345.67
    }
}

Use as easy as:

write( invoice.customer );
write( invoice.totals.taxes );
write( invoice.items[1][3] );

So simple it looks dangerous huh?

XML 2.0 is not just about CSV++ see?
It is all about messages, whichever shape they take: circle, rectangle or triangle ;-)


Feedback

# re: XML Next

Gravatar Compare your first example at +/-813 bytes to this:

<?xml version="1.0" ?>
<invoice number="123456789" date="2004/01/01" shipper="Fedex" customer="Microsoft">
<address street="One Microsoft Way" city="Redmond" state="WA" postal="12345" />
<items>
<item i="ABCD1233" d="LCD TV 60" w="125" p="357.95" />
<item i="ABCD1234" d="LCD TV 61" w="126" p="358.95" />
<item i="ABCD1235" d="LCD TV 62" w="127" p="359.95" />
<item i="ABCD1236" d="LCD TV 63" w="128" p="360.95" />
<item i="ABCD1237" d="LCD TV 64" w="129" p="361.95" />
<item i="ABCD1238" d="LCD TV 65" w="130" p="362.95" />
<item i="ABCD1239" d="LCD TV 66" w="131" p="363.95" />
<item i="ABCD1240" d="LCD TV 67" w="132" p="364.95" />
<item i="ABCD1240" d="LCD TV 67" w="132" p="364.95" />
<item i="ABCD1242" d="LCD TV 69" w="134" p="366.95" />
</items>
<totals amount="1234.56" discount="123.45" taxes="234.56" total="2345.67" />
</invoice>

Sure, I'm 825 bytes. But then, I'm not left guessing that you columns mean as much and I can do it *today.* There's your rectangle.

Oh, by the way, I'll be looking in the owner's manual for my PocketIE to see how it works... My guess is "not so well." It will probably work better there than it does on my C-64 though. Or in Lynx.

I agree that XML 2.0 isn't just about CSV++ and its more than its about saving bytes on the wire. Its about multiple use cases made easy -- semantically rich ones included. Its medium, message and meaning. 2/16/2005 3:50 PM | Kent Tegels

# re: XML Next

Gravatar Compare your version to this one, which is more realistic:

<?xml version="1.0" ?>
<invoice number="123456789" date="2004/01/01" shipper="Fedex" customer="Microsoft">
<address street="One Microsoft Way" city="Redmond" state="WA" postal="12345" />
<items>
<item code="ABCD1233" description="LCD TV 60" quantity="125" unitprice="357.95" />
<item code="ABCD1234" description="LCD TV 61" quantity="126" unitprice="358.95" />
<item code="ABCD1235" description="LCD TV 62" quantity="127" unitprice="359.95" />
<item code="ABCD1236" description="LCD TV 63" quantity="128" unitprice="360.95" />
<item code="ABCD1237" description="LCD TV 64" quantity="129" unitprice="361.95" />
<item code="ABCD1238" description="LCD TV 65" quantity="130" unitprice="362.95" />
<item code="ABCD1239" description="LCD TV 66" quantity="131" unitprice="363.95" />
<item code="ABCD1240" description="LCD TV 67" quantity="132" unitprice="364.95" />
<item code="ABCD1240" description="LCD TV 67" quantity="132" unitprice="364.95" />
<item code="ABCD1242" description="LCD TV 69" quantity="134" unitprice="366.95" />
</items>
<totals amount="1234.56" discount="123.45" taxes="234.56" total="2345.67" />
</invoice>

That is 1.11Kb, and that is the way you would do it in XML today.
If you are concerend about space, compress the bloody thing.
Zipping the files give me ~500 bytes for all of them, with a 100 bytes difference.

2/18/2005 7:21 AM | Ayende Rahien

Post a comment





 

 

 

Copyright © RebelGeekz