FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   reading XML from a URL
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: reading XML from a URL  (Read 833 times)
ed

WWW Email
reading XML from a URL
« on: Jun 22nd, 2003, 2:40pm »

Hello yawl,
 
I've been musing about doing something that'll involve sucking data at runtime from an xml source someplace out in the wilds of the www [ such as http://www.bbc.co.uk/syndication/feeds/news/ukfs_news/world/rss091.xml for example ]. Is there any functionality I've missed within the current processing that could read from a URL, and if not is it due in the next version [eta?]. Some very light XML parsing would be a boon too, of course you might just tell me to go and write java from scratch if I'm getting too pinnickity for processing.
 
keep up the great work,
 
ed [a processing advocate]
 
REAS


WWW
Re: reading XML from a URL
« Reply #1 on: Jun 23rd, 2003, 12:15pm »

to my knowledge there has been no plan to implement an XML parser, but you can download a file with a URL using loadStream().
 
http://www.proce55ing.net/reference/loadStream_.html
 
people have been known to plot behind my back, so there may be an XML parsin' plan out there somewhere.
 
the processing source will be available soon and i hope that someone will make it their mission in life to add some of this basic functionality so that everyone can benefit.
 
fry


WWW
Re: reading XML from a URL
« Reply #2 on: Jun 24th, 2003, 8:24pm »

when running inside the environment, the javax.xml stuff is imported, as are the org.xml.sax APIs.. so while it won't work from an exported applet (yet, seems we'll have to add a '1.1' or '1.3' or '1.4' selector for export.. yuk), some combination of loadStream() plus those classes will prolly get you what you want.
 
if it doesn't, let us know, as this is a frequent request, and we always want to keep our processing advocates happy
 
ed

WWW Email
Re: reading XML from a URL
« Reply #3 on: Jun 28th, 2003, 2:11pm »

thanks for the detailed replies. methinks all that javax.xml malarky would be overkill anyhoos, clientside parsing is best kept simple and efficient for most web delivered applications.
 
What I'd missed of course was that I'd forgotten that no applet will be allowed to read the contents of a URL from any old place that might be outside of its codebase, silly me. Methinks I'll need something like perl to periodically snaffle copies of the url's I want into an applets codebase and then try to cobble together the simplest possible "my first xml parser" in proce55ing to take the data from there. wish me luck!
 
benelek

35160983516098 WWW Email
Re: reading XML from a URL
« Reply #4 on: Jun 28th, 2003, 2:47pm »

kewlies, g'luck Ed. post us summin fun!
 
ed

WWW Email
Re: reading XML from a URL
« Reply #5 on: Jun 28th, 2003, 3:20pm »

ack, I seem to be falling at the first fence. I've simply pasted the loadStream reference example as follows...
 
void setup() {
  loadNews();
}
 
void loadNews() {
  InputStream input = loadStream("news.xml");
  InputStreamReader isr = new InputStreamReader(input);
  BufferedReader reader = new BufferedReader(isr);
  String line;
  while ((line = reader.readLine()) != null) {
    println("next line is: " + line);
  }
}
 
void loop() {
 
}
 
and am getting the compile error...
"Exception "java.io.IOException" is not catched and does not appear in throws list [JLS 8.4.4]"
 
A slap round the face with an obvious mistake I'm making would be gratefully received.
 
ed

WWW Email
Re: reading XML from a URL
« Reply #6 on: Jun 28th, 2003, 3:39pm »

doh, I get to slap myself. I didn't realise the extent to which processing allows me to still play with all the error trapping java has to offer. Incase my error has led anyone else astray here's what's merrily spitting out the file now...
 
try {
    InputStream input = loadStream("news.xml");
    InputStreamReader isr = new InputStreamReader(input);
    BufferedReader reader = new BufferedReader(isr);
    String line;
    while ((line = reader.readLine()) != null) {
 println("next line is: " + line);
    }
   } catch (IOException e) {println("warning, i/o error:"+e);}
 
*slap*
 
Pages: 1 

« Previous topic | Next topic »