Приглашаем посетить
Спорт (www.sport-data.ru)

SML

Table of Contents
Previous Next

SML

Some developers prefer to use the Simplified Markup Language (SML) format when writing XML. SML is a subset of XML that simplifies an XML document. SML (also know as Minimal XML or Simplified XML) greatly simplifies the structure of an XML document by removing many parts of an XML document. SML is XML without:

More information on SML can be found at: http://www.docuverse.com/smldev/minxml.html.

Converting XML into SML

The XML document, sample.xml, contains multiple data types, elements with attributes, and four levels of nested elements. In this sample document the second element, <Country>, has an attribute of name. The value of the attribute is Cuba. The element <Resort> supports multiple attributes:

    <?xml version="1.0"?>
    <!DOCTYPE Travelpackages SYSTEM "sample.dtd">
    <Travelpackages>
      <Country name="Cuba">
        <City name="Cayo Coco">
          <Resort name="Club Tryp Cayo Coco" rating="4" typeofholiday="beach"
                     watersports="true" meals="true" drinks="true">
            <Package dateofdep="5/8/98" price="879"/>
            <Package dateofdep="5/1/98" price="879"/>
          </Resort>
        </City>
        <City name="Varadero ">
          <Resort name="Sol Club Paleras" rating="3" typeofholiday="beach"
                     watersports="false" meals="true" drinks="false">
            <Package dateofdep="5/30/98" price="799"/>
            <Package dateofdep="5/23/98" price="879"/>
            <Package dateofdep="5/16/98" price="889"/>
          </Resort>
        </City>
      </Country>
    </Travelpackages>

To convert this XML to SML format, the attributes should be changed to elements. Let's take a look at the sample.xml document in SML format:

    <Travelpackages>
      <Country>
         <Country_name>Cuba</Country_name>
         <City>
           <City_name>Cayo Coco</City_name>
           <Resort>
             <Resort_name>Club Tryp Cayo Coco</Resort_name>
             <Resort_rating>4</Resort_rating>
             <Resort_typeofholiday>beach</Resort_typeofholiday>
             <Resort_watersports>true</Resort_watersports>
             <Resort_meals>true</Resort_meals>
             <Resort_drinks>true</Resort_drinks>

             <Package>
               <Package_dateofdep>5/8/98</Package_dateofdep>
               <Package_price>879</Package_price>
             </Package>
             <Package>
               <Package_dateofdep>5/1/98</Package_dateofdep>
               <Package_price>879</Package_price>
             </Package>
           </Resort>
         </City>
       </Country>
    </Travelpackages>
Important 

In XML white space is ignored unless you explicitly preserve it.

This sample XML document while short is sufficiently complex to show the differences in how the different APIs handle XML. This sample has most of the characteristics that we will find in most XML documents. We will change the XML format a little bit when dealing with the different APIs so we can get the code to work. You'll need to remember to check your XML to ensure that it works with the API that you choose.


Table of Contents
Previous Next