XML.orgXML.org
FOCUS AREAS |XML-DEV |XML.org DAILY NEWSLINK |REGISTRY |RESOURCES |ABOUT
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]
Three ways to organize data

Hi Folks,

Below are three ways of organizing data for searching. I have seen all three ways in a project that I am working. The first way is how text data was organized in the 1970s. The second way is how data is organized by a database-oriented shop. The third way is the XML way.

The first way embeds codes in the records. Searching involves using the codes to narrow the search. Below is an example that uses these codes: Type = B (Book), Subtype = C (Computer), Type = W (Watch), Subtype = Q (Quartz), Type = A (Author), Subtype = P (Professor), Type = E (battEry), Subtype = L (Lithium).

<Records>
    <Record>
        <Type>B</Type>
        <Subtype>C</Subtype>
        <Title>Programming Languages Application and Interpretation</Title>
        <Date>2007</Date>
        <Author>Krishnamurti</Author>
        <Type>A</Type>
        <Subtype>P</Subtype>
    </Record>
    <Record>
        <Type>W</Type>
        <Subtype>Q</Subtype>
        <Brand>Timex</Brand>
        <Model>Indiglo</Model>
        <Power>Battery</Power>
        <Type>E</Type>
        <Subtype>L</Subtype>
    </Record>
    <Record>
        <Type>A</Type>
        <Subtype>P</Subtype>
        <Name>Shriram Krishnamurti</Name>
        <Employer>Brown University</Employer>
    </Record>
    <Record>
        <Type>E</Type>
        <Subtype>L</Subtype>
        <Chemistry>Lithium</Chemistry>
        <Volts>3</Volts>
    </Record>
</Records>

 

Suppose we want to search for the computer book written by Shriram Krishnamurti and then find his employer.  To find the computer book, search for the record with Type = B (Book), Subtype = C (Computer) and the author field containing Shriram Krishnamurti. That yields the first record shown above. Then use its second set of Type/Subtype fields (Type = A, Subtype = P) to locate the record about the author. That yields the third record, which shows that he is a professor at Brown University.

The second way is to use multiple documents – a document containing book data, a document containing author data, a document containing watch data, a document containing battery data – and use primary/foreign keys to connect the documents together. Here are the four documents:

Books.xml

<Books>
    <Book>
        <PrimaryKey>PLAI</PrimaryKey>
        <Title>Programming Languages Application and Interpretation</Title>
        <Date>2007</Date>
        <Author>Krishnamurti</Author>
        <ForeignKey>SK</ForeignKey>
    </Book>
</Books>

 

Authors.xml

<Authors>
    <Author>
        <PrimaryKey>SK</PrimaryKey>
        <Name>Shriram Krishnamurti</Name>
        <Employer>Brown University</Employer>
    </Author>
</Authors>

 

Watches.xml

<Watches>
    <Watch>
        <PrimaryKey>TimexInd</PrimaryKey>
        <Brand>Timex</Brand>
        <Model>Indiglo</Model>
        <ForeignKey>Lit</ForeignKey>
    </Watch>
</Watches>

 

Batteries.xml

<Batteries>
    <Record>
        <PrimaryKey>Lit</PrimaryKey>
        <Chemistry>Lithium</Chemistry>
        <Volts>3</Volts>
    </Record>
</Batteries>

 

Again, suppose we want to search for the computer book written by Shriram Krishnamurti and find his employer.  To find the computer book, search Books.xml for the record with the author field containing Shriram Krishnamurti. Use its foreign key to reference a record in Authors.xml.

The third way is to use the ID-IDREF capability of XML.

<BooksAndWatches>
    <Book id="PLAI">
        <Title>Programming Languages Application and Interpretation</Title>
        <Date>2007</Date>
        <Author idref="SK">Shriram Krishnamurti</Author>
    </Book>
    <Watch id="TimexInd">
        <Brand>Timex</Brand>
        <Model>Indiglo</Model>
        <Power idref="Lit">Battery</Power>
    </Watch>
    <Author id="SK">
        <Name>Shriram Krishnamurti</Name>
        <Employer>Brown University</Employer>
    </Author>
    <Battery id="Lit">
        <Chemistry>Lithium</Chemistry>
        <Volts>3</Volts>
    </Battery>
</BooksAndWatches>

 

To find the computer book written by Shriram Krishnamurti we search for the Book element with Author = Shriram Krishnamurti. To find his employer follow the idref value on the Author element.

TaDa!

Three different ways to organize data: the old (1970s) way, the database way, and the XML way.

/Roger

 

 

 



[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