Re: XML Importing
- To: mathgroup at smc.vnet.net
- Subject: [mg49210] Re: XML Importing
- From: Doug <umdougmm at hotmail.com>
- Date: Wed, 7 Jul 2004 01:43:15 -0400 (EDT)
- References: <cbe8ht$rl6$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Thanks to both you guys...it turns out the mathematica people noticed the error and supposedly fixed it... I just got an email yesterday, but haven't had time yet to look at it Doug "Michel, Hans J.I." <HMiche at LSUHSC.EDU> wrote in message news:cbe8ht$rl6$1 at smc.vnet.net... > Doug: > > When I went to the following web site I did not get any xml data. I got some > Perl code and apparently directory browsing is enabled. It could be that the > site is under going maintenance > > http://www.xmltoday.com/examples/stockquote/getxmlquote.vep?s=ba+lmt+ibm+int > +amd+mmm > > Even the sites homepage is down. > > As a result of the site being down the Perl code was available for browsing. > So I took a look at the code. I came away with one central point. This site > just reformats yahoo finance stock quote code from cvs to xml. > > The crucial url is > > http://finance.yahoo.com/d/quotes.csv?f=sl1d1t1c1ohgv&e=.csv&s= > tickersymbol+tickersymbol > > Long of the short is You can use the Import with GetURL function which uses > J/Link to retrieve stream from web via http. Or you can use the following > trick > > getYahooData[ticker_] := Module[ {data, s, result}, > data = ImportString["<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE data > [<!ENTITY text SYSTEM > 'http://finance.yahoo.com/d/quotes.csv?f=sl1d1t1c1ohgv&e=.csv&s=" <> > ToString[ticker] <> "'><!ELEMENT data (#PCDATA)>]><data>&text;</data>", > "XML", ConversionOptions -> {"NormalizeWhitespace" -> False}]; > s = StringToStream[First[Cases[data, XMLElement["data",{}, ___], > Infinity]][[3]][[1]]]; > result = ReadList[s, Word, RecordSeparators -> {"\n"}, RecordLists > -> True, WordSeparators -> ","]; > Close[s]; > TableForm[result] > ]; > > getYahooData["msft+ibm"] > > As long as the cvs file does not contain the five unescaped SGML/XML > entities {&,<,>,',",} well in this case {"} comes through. > > I output the result in table form but you can keep it as a list. Then use > traditional Mathematica code to process and graph. > > Follows the following field format > symbol ask qdate qtime change open dayhigh daylow volume > > good luck > > Hans Michel >