Newbie XML Question

Bill Marriott wjm at wjm.org
Tue Dec 14 07:17:17 EST 2004


[reposted to fix the subject line and keep the thread together]

"Frank D. Engel, Jr." <fde101 at fjrhome.net> writes:

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

...

> 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.

I want to generate a file that looks like it was generated from a single
register, with the order numbers in sequential order (renumbering them as
necessary). And the "use Rev's XML Library to parse it all together..." is
the part I'm seeking assistance with. I basically want to grab a whole
section of Purchases based on the Order attribute and move them into a new
tree. Bob and the grocery store don't exist, it's just an illustration.

Truth be told I could probably have written a plain old fashioned text
parsing utility to do this but I wanted to do it the "right way" using the
XML library.

Here's some examples of my frustration:

Let's look at the XML again:

<?xml version="1.0"?>
<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>

Suppose I load this into a Rev tree and it gets the ID 5280.

put revXMLNodeContents(5280,"Register/Purchase/Description")

yields "Cherry Coca-Cola" which is the first purchase. Now, what do I use to
get the second one?

put revXMLChildContents(5280,"Register",tab,return,true,-1)

yields

Purchase[1]
Buyer[1]
Item[1]
Description[1] Cherry Coca-Cola
Purchase[2]
Buyer[1]
Item[1]
Description[1] Hershey's Chocolate Bar
Purchase[3]
Buyer[1]
Item[1]
Description[1] Marlboro Cigarettes

That's a good list of all the nodes, but I would still have to parse through
it to build a table I could sort.

revXMLMatchingNode(5280,"Register","Purchase","Order",2,-1)

tells me,

/Register/Purchase[3]

which i could use in the command,

revXMLText(5280,"/Register/Purchase[3]")

to grab the whole of the third Purchase... but I cannot then say,

put revXMLMatchingNode(5280,"Register","Purchase","Order",1,-1)

and get a list of all the purchases related to Order #1. It yields only the
first one. So how do I find the second and subsequent ones?

Thanks,
- Bill



More information about the use-livecode mailing list