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]
Here's how to remove 'time' from a processing problem

Hi Folks,

I have a program that processes XML files in a folder. Some of the XML documents contain data about a car, like this:

<Car>
    <Make>Toyota</Make>
    <Model>Avalon</Model>
    <LicensePlate>12345</LicensePlate>
</Car>

At some point the program reads in that XML document and begins processing it. The objective of processing is to output the license plate number if the car is stolen and "" (not stolen) otherwise. However, the document does not contain the necessary information to make that decision. The information to make the decision arrives some time later, in another document: 

<PoliceReport>
    <Car>
        <LicensePlate>12345</LicensePlate>
        <Status>Stolen<Status>
    </Car>
</PoliceReport>

So the desired processing behavior is this:

Read the next XML document.
If the XML document contains data about cars then
    Wait until the police report arrives ....
    .......... time elapses ........... the police
    report arrives: if it says the car is stolen
    then output "stolen" else output ""

That algorithm involves dealing with time. 

Here's how to eliminate time from the equation.

The trick is to use something called a 'circulating state'. Let me explain what that means.

The Car.xml document is input and placed inside a <Document> element:
 
<Document>
    <Car>
        <Make>Toyota</Make>
        <Model>Avalon</Model>
        <LicensePlate>12345</LicensePlate>
    </Car>
    <State></State>
</Document>
 
The <State> element will be used to store Car inputs. Initially it is empty.
 
If there is no PoliceReport, output Document.xml and loop it back around as state. (The state circulates around) 
 
Read in the next Car.xml, along with Document.xml and put the next Car into <Document>

<Document>
    <Car>
        <Make>Honda</Make>
        <Model>Accord</Model>
        <License>abcde</License>
    </Car>
    <State>
        <Car>
            <Make>Toyota</Make>
            <Model>Avalon</Model>
            <LicensePlate>12345</LicensePlate>
        </Car>
    </State>
</Document>
 
Notice the first car is now inside <State> to reflect the state of the system; namely, we previously processed data for the Toyota Avalon. The current, active car data is Honda Accord.
 
Repeat this process until a PoliceReport.xml document arrives. When it arrives, query <State> for a matching <Car> element and output "Stolen" or "" for the car.
 
TaDa!

This approach avoids dealing with time. Time goes away as part of the definition of the system.

I am told that "circulating state" is the usual paradigm in functional programming for dealing with time.

/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