Newbie XML Question

Frank D. Engel, Jr. fde101 at fjrhome.net
Mon Dec 13 16:12:02 EST 2004


In other words, to navigate between <Register> blocks?

I would suggest creating a new tag and use it to encase all of the 
orders; something like this:

<Tape>
<Register Station="A">
     (...)
</Register>
<Register Station="A">
     (...)
</Register>

(...)
</Tape>

Do that for each of the registers, then use Rev's XML library to parse 
it all together and to navigate the resulting XML trees, rather than 
trying to pull each of them individually out of the text.


On Dec 13, 2004, at 3:29 PM, Bill Marriott wrote:

> Hi Everyone!
>
> I'm just warming up on the Revolution XML library, and I would love 
> the groups's input on how to handle a particular problem I'm trying to 
> figure out.
>
> Hypothetical Scenario:
>
> Bob runs a grocery store with two cash registers. Only one is running 
> at any given time. But sometimes he uses register A and sometimes he 
> uses register B. The registers happen to spit out receipts in XML. The 
> recipts look like this:
>
> <Register Station="A">
>    <Purchase Date="12/13/2004" Time="14:26:03" 
> DateTime="20041213142603" Order="1">
>        <Buyer CustomerID="1234" />
>        <Item UPC="04905004" Price="0.40"/>
>        <Description>Cherry Coca-Cola</Description>
>    </Purchase>
>    <Purchase Date="12/13/2004" Time="14:26:14" 
> DateTime="20041213142614" Order="1">
>        <Buyer CustomerID="1234" />
>        <Item UPC="03424005" Price="0.65"/>
>        <Description>Hershey's Chocolate Bar</Description>
>    </Purchase>
>    <Purchase Date="12/13/2004" Time="15:09:25" 
> DateTime="20041213150925" Order="2">
>        <Buyer CustomerID="4567" />
>        <Item UPC="02880125" Price="6.95"/>
>        <Description>Marlboro Cigarettes</Description>
>    </Purchase>
> </Register>
>
> In other words, Bob had two customers. The first customer bought two 
> items (Order 1), and the second customer bought one item (Order 2).
>
> Each register spits out a tape like this, starting with Order=1 and 
> continuing until the store closes. At the end of the day, Bob would 
> like to feed these tapes into his computer running Revolution and get 
> one "tape" of all his items, re-numbered sequentially.
>
> * Bob can't just tape them together (append them) because the Order 
> numbers would conflict. Each register starts numbering at "1" when the 
> store opens.
> * There will never be overlapping orders; only one cash register is 
> active at any given time. (Bob is a sole proprietor who runs from one 
> to the other.)
>
> My approach to this would be something like this:
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> "on mouseup"
> put tape A into XMLTree called aTree
> put tape B into XMLTree called bTree
> make a new, empty XML tree called combinedTree
>
> put the total number of orders in aTree into aOrders
> put the total number of orders in bTree into bOrders
>
> put 1 into newOrderNumber
> put 1 into aCompare
> put 1 into bCompare
>
> repeat while (aCompare <= aOrders) and (bCompare <= bOrders)
>
>    put the block of purchases related to order aCompare in aTree into 
> aBlock
>    put the block of purchases related to order bCompare in aTree into 
> bBlock
>
>    if the earliest DateTime in aBlock < the earliest DateTime in 
> bBlock, then
>        put aBlock after combinedTree
>        put newOrderNumber into the Order attribute for the Purchase 
> nodes of that block
>        increment newOrderNumber by 1
>        increment aCompare by 1
>    else
>        put bBlock after combinedTree
>        put newOrderNumber into the Order attribute for the Purchase 
> nodes of that block
>        increment newOrderNumber by 1
>        increment bCompare by 1
>    end if
>
>    if aCompare > aOrders then
>        put the rest of bTree after combinedTree
>        exit repeat
>    end if
>
>    if bCompare > bOrders then
>        put the rest of aTree after combinedTree
>        exit repeat
>    end if
>
> end repeat
> write out combinedTree
> "end mouseup"
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Ok, so I hope my "FunkyTalk" hyperscripting isn't too obscure.
>
> The problem is, I don't know how to manipulate blocks of XML like 
> this. Do I have to convert the whole XML file into some kind of table 
> first? Do I have to walk through each and every node and every 
> attribute? Is there nothing like "sort lines of foobar ascending by 
> item 5 of each?" Actually, I don't even know how to walk through the 
> nodes since the functions only seem to return the first instance...
>
> I really would like to do something like select/extract all the 
> Purchases where the Order ID = n and bring along all the related 
> attributed and child elements. But I haven't a clue how to do that.
>
> I've gotten as far as I have through reading the "XML Demo 1" stack 
> and "XML construction kit" but I've hit a wall now. Some helpful 
> advice would be very welcome... and posisbly helpful for other XML 
> newbies on the list.
>
> Bill
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>
>
-----------------------------------------------------------
Frank D. Engel, Jr.  <fde101 at fjrhome.net>

$ ln -s /usr/share/kjvbible /usr/manual
$ true | cat /usr/manual | grep "John 3:16"
John 3:16 For God so loved the world, that he gave his only begotten 
Son, that whosoever believeth in him should not perish, but have 
everlasting life.
$



___________________________________________________________
$0 Web Hosting with up to 120MB web space, 1000 MB Transfer
10 Personalized POP and Web E-mail Accounts, and much more.
Signup at www.doteasy.com



More information about the use-livecode mailing list