XML - Managing Data Exchange/Basic data structures

< XML - Managing Data Exchange



XML - Managing Data Exchange
Chapters
Appendices
Exercises
Related Topics
Computer Science Home
Library and Information Science Home
Markup Languages
Get Involved
To do list
Contributors list
Contributing to Wikibooks
Previous Chapter Next Chapter
A single entity The one-to-many relationship




Learning objectives
  • introduce the concept and uses of basic data structures
  • describe how XML may be used to represent basic data structures
  • enumerate common technical considerations

Introduction

In reviewing the four central problems in data management, (capture, storage, retrieval, and exchange) the typical user of XML encounters recurring fundamental structural patterns that apply to all sorts of data throughout the storage and exchange phases. These patterns recur consistently because their use transcends the particular contexts in which the underlying data are processed. We call these patterns "data structures" (or datatypes).

In this section, we discuss a few of the most fundamental "basic data structures" and explain why they are useful, as well as how to work with them using XML.

We start our introduction with a simple example. Consider an ordinary grocery shopping list for a single-person household.

Introductory Shopping List Example:

   Andy's shopping list:
   * eggs
   * cough syrup(pick up for granny)
   * orange juice  
   * bread
   * laundry detergent **don't forget this**

When analyzing aspects of the information contained in this shopping list, we can make some basic generalizations:

The fundamental concept of basic data structures

Given that we have the previous example for background, we can now introduce the fundamental concept of "basic data structures".

The concept of "basic data structures" describes the fundamental conventions we use to store our data, so that we can more easily exchange our data. When we follow these fundamental conventions, we help to ensure the portability, comprehensibility and adaptability of information.

Basic data structures defined

Now that we have introduced our concept of data structures, we can start with some concrete definitions, and then review those definitions in the context of our shopping list example.

Overview of "core" data structures

The following terms define some "core" data structures[1] that we use throughout this chapter. This list is ordered in ascending degrees of complexity:

An important point to remember while reviewing these "core" data structures is that they are elemental and complementary. That is, the core structures, when used in combination, can form even more complex structures. Once the reader comes to understand this fact, it will become apparent that there is no conceivable application or data specification that cannot be wholly described in XML using nothing more than these "core" data structures.

Once we understand the "core" data structures, we can use them in combination to represent any conceivable kind of structured information.

Now review the "Introductory Shopping List Example" above. When we compare it with the "core" data structures that we've just defined, we can make some fairly straightforward observations:

SimpleString

Different ways to represent a SimpleString in XML:

<Example>
    <String note="This XML attribute contains a SimpleString.">
    This XML Text Node represents a SimpleString.
    </String>

    <!-- This XML comment contains a SimpleString -->
    <![CDATA[ This XML CDATA section contains a SimpleString. ]]>
</Example>

SimpleSequence

Different ways to represent a SimpleSequence in XML:

<Example>
    <!-- use a single XML attribute with a space-delimited list of items -->
    <ShoppingList items="bread eggs milk juice" />

    <!-- use a single XML attribute with a semicolon-delimited list of items 
         (this allows us to add items with spaces in them) -->
    <ShoppingList items="bread;cough syrup;milk;juice;laundry detergent"  />

    <!-- yet another way (but not necessarily a good way) 
         using multiple XML attributes -->
    <ShoppingList item00="bread" item01="eggs" item02="cough syrup" />

    <!-- yet another way 
         using XML child elements -->
    <ShoppingList>
        <item>eggs</item><item>milk</item><item>cough syrup</item>
    </ShoppingList>
</Example>

SimpleTable

Side-by-side examples

SimpleTable (XML_Elem):

<table>
    <tr><item>eggs</item><getfor>andy</getfor><notes></notes></tr>
    <tr><item>milk</item><getfor>andy</getfor><notes></notes></tr>
    <tr><item>laundry detergent</item><getfor>andy</getfor><notes></notes></tr>
    <tr><item>cough syrup</item><getfor>granny</getfor><notes>try to get grape flavor</notes></tr>
</table>

SimpleTable (XML_Attr):

<table>
    <tr item="eggs"         getfor="andy"   notes=""    />
    <tr item="milk"         getfor="andy"   notes=""    />
    <tr item="laundry detergent"  getfor="andy"   notes=""  />
    <tr item="cough syrup"  getfor="granny" notes="try to get grape flavor"    />
</table>

SimpleTable (XML_Mixed):

<table>
    <tr>
        <item getfor="andy" >eggs</item><notes></notes>
    </tr>
    <tr>
        <item getfor="andy" >milk</item><notes></notes>
    </tr>
    <tr>
        <item getfor="andy" >laundry detergent</item><notes></notes>
        </tr>
    <tr>
        <item getfor="granny">cough syrup</item><notes>try to get grape flavor</notes>
    </tr>
</table>

Basic data structures in programming

To further illustrate how basic data structures apply in many different contexts, some of the basic data structures enumerated previously are examined and compared here in the context of computer programming.

For the first part of the comparison, we examine the generic terminology against that used commonly in programming languages:

Technical considerations

Now that we've introduced and discussed specific examples of the basic data structures, there are a few technical considerations that apply to all of the data structures, and are particularly important to those who may be responsible for implementing and designing XML schemas to deal with specific implementation scenarios.


Notes and references

  1. An important note: the basic terms used here are generalizations. Although they may coincide with terms used in specific software, specific programming languages, or specific applications, these are not intended as technically precise definitions. The concepts described here are presented to help emphasize the context-neutral principle of interoperability in XML.
This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.