parsing the tags out of an XML file

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

parsing the tags out of an XML file

Post by adventuresofgreg » Wed Nov 10, 2010 1:26 am

Hello: What is the fastest way to parse out these XML tags from some futures price data?

<Date>11/3/2010</Date>
<Open>1197.5</Open>
<High>1198</High>
<Low>1196</Low>
<Last>1197.25</Last>
<Settle>1197.25</Settle>
<Volume>2361808</Volume>
<OpenInterest>2683550</OpenInterest>

It would be cool if you could set the itemdelimiter to an entire string rather than just one character - like in this case, if I could set the item delimiter to <anything>, then just replace all the item delimiters with ","'s

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: parsing the tags out of an XML file

Post by Mark » Wed Nov 10, 2010 1:35 am

adventuresofgreg,

Let's assume that fld 2 contains your XML...

Code: Select all

on mouseUp
     put "<p>" & fld 2 & "</p>" into myHtml
     replace cr with "</p><p>" in myHtml
     set the htmlText of fld 1 to myHtml
end mouseUp
Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

adventuresofgreg
Posts: 349
Joined: Tue Oct 28, 2008 1:23 am
Contact:

Re: parsing the tags out of an XML file

Post by adventuresofgreg » Wed Nov 10, 2010 1:49 am

wow - thanks Mark! That's so simple - and fast. Now I just have to try to understand it... I'll look up htmlText. I want to convert each date of prices to the standard:

date,prices,return
date, prices, return
etc...
Mark wrote:adventuresofgreg,

Let's assume that fld 2 contains your XML...

Code: Select all

on mouseUp
     put "<p>" & fld 2 & "</p>" into myHtml
     replace cr with "</p><p>" in myHtml
     set the htmlText of fld 1 to myHtml
end mouseUp
Kind regards,

Mark

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: parsing the tags out of an XML file

Post by Klaus » Sun Nov 14, 2010 12:30 pm

Hi Greg,

looks like you need to dive a bit deeper into XML :D
Of course you could do some chunk stuff within a repeat loop,
but to be prepared for the future you should take the dive!

Please check the wonderful stack "xmldemo1" on this site:
http://www.troz.net/rev/
This got me started with XML, too!


Best

Klaus

Post Reply