Re: XML Importing
- To: mathgroup at smc.vnet.net
- Subject: [mg48939] Re: XML Importing
- From: "Michel, Hans J.I." <HMiche at LSUHSC.EDU>
- Date: Thu, 24 Jun 2004 05:36:03 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
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