Re: XML Importing

  • Follow


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

0
Reply HMiche (6) 6/24/2004 9:57:17 AM

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@LSUHSC.EDU> wrote in message
news:cbe8ht$rl6$1@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
>

0
Reply umdougmm (19) 7/7/2004 6:26:30 AM


1 Replies
33 Views

(page loaded in 0.077 seconds)

Similiar Articles:













7/16/2012 8:59:38 PM


Reply: