MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: XML Importing

  • To: mathgroup at
  • 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


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

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

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

getYahooData[ticker_] := Module[ {data, s, result},
data = ImportString["<?xml version='1.0' encoding='UTF-8'?><!DOCTYPE data
'"; <>
ToString[ticker] <> "'><!ELEMENT data (#PCDATA)>]><data>&text;</data>",
"XML", ConversionOptions -> {"NormalizeWhitespace" -> False}];
	s = StringToStream[First[Cases[data, XMLElement["data",{}, ___],
	result = ReadList[s,  Word, RecordSeparators -> {"\n"}, RecordLists
-> True, WordSeparators -> ","];


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

  • Prev by Date: RE: basic question about plotting 2 functions in one graph
  • Next by Date: Re: Solve question
  • Previous by thread: Re: XML Importing
  • Next by thread: Mathematica on Linux gives errors