[Biojava-l] JAXP

Schreiber, Mark mark.schreiber@agresearch.co.nz
Wed, 27 Jun 2001 11:25:52 +1200


> -----Original Message-----
> From: Thomas Down [mailto:td2@sanger.ac.uk]
> Sent: Tuesday, June 26, 2001 8:05 PM
> To: Schreiber, Mark
> Cc: 'Biojava-L (E-mail)
> Subject: Re: [Biojava-l] JAXP
> 
> 
> On Tue, Jun 26, 2001 at 10:36:11AM +1200, Schreiber, Mark wrote:
> > Hi,
> > 
> > I've been trying to use JAXP for XML parsing with the 
> following snippet of
> > code:
> > 
> > 
> >         InputStream is = new FileInputStream(args[0]);
> >         InputStreamReader isr = new InputStreamReader(is);
> >         char[] data = new char[is.available()];
> >         isr.read(data);
> >         String xmldata = new String(data);
> >         InputSource source = new InputSource(new 
> StringReader(xmldata));
> >         //System.out.print(xmldata);
> >         saxParser.parse(xmldata, this);
> 
> Um...  You seem to be constructing an InputSource (the normal
> way to invoke SAX-ish parsers, then calling the 
> parse(String, DefaultHandler) method.  This interprets the
> String argument as a URI, and will be trying to load data
> from that.
> 
> If you try saxParser.parse(source, this) you might have a bit
> more luck...
> 

Oh, I keep getting confused with the classes that refer to URI's as Strings.
I'm not sure why they dont just use a URL as the argument and do a
.toString() internally.
 
> 
> (PS.  Why are you loading the data into memory first?  The parser
> works perfectly well parsing data directly from a stream)
> 

Ahem, well as we are at an early stage our XML on the server is not quite up
to scratch and needs a bit of processing before parsing (very embarissing
really).

Anyhow thanks for helping the XML neophyte

Mark