[jdom-interest] SAXBuilder.build(java.io.Reader characterStream) Error

Jochen Kirn j.kirn at gmx.de
Fri Feb 16 10:31:51 PST 2001


Hi Kevin,

probably the FileReader takes the default encoding of the plattform which
won't match
the actual encoding of the XML-file.
once i run into similar problems (well it wasn't a FileReader) but try this
instead
new InputStreamReader(new FileInputStream("file.xml"));
or
new BufferedReader(newInputStreamReader(new FileInputStream("file.xml")));


sers

Jochen

----- Original Message -----
From: "Kevin Baynes" <kbaynes at renex.com>
To: <jdom-interest at jdom.org>
Sent: Friday, February 16, 2001 9:22 PM
Subject: [jdom-interest] SAXBuilder.build(java.io.Reader characterStream)
Error


>
> I've run into a problem building a JDOM document by passing a Reader into
> the SAXBuilder (today's snapshot).
>
> In the sample application included below, I can pass two direct subclasses
> of java.io.Reader into the SAXBuilder.build(java.io.Reader
characterStream)
> method and get success  - BufferedReader and InputStreamReader.
>
> However, when I try to pass the FileReader subclass of InputStreamReader,
I
> get a failure.
>
> I even tried upcasting the FileReader to InputStreamReader and Reader,
which
> both fail.
>
> I'm getting an error that appears to be similar to the EOF Socket error:
> org.jdom.JDOMException: The root element is required in a well-formed
> document.: Error on line 1: The root element is required in a well-formed
> document.
>
> It seems to me that if I can pass a two subclasses of Reader and get
> success, that all the subclasses should work. (all subclasses should have
> all features of superclass).
>
> Am I wrong in this thought? Can you see some error I am making?
>
> You can download the following files to check me:
> ftp://ftpGuest:ftpGuest@hemlock.renex.com/RequestParser2.java
> ftp://ftpGuest:ftpGuest@hemlock.renex.com/RequestParser2.class
> ftp://ftpGuest:ftpGuest@hemlock.renex.com/trace.txt (pass this file to
> RequestParser)
>
> Pass through the file to parse as command line args: java RequestParser2
> trace.txt
>
> Thanks!
>
> -Kevin Baynes
> kbaynes at renex.com
>
>
> Here is the file that will generate the errors:
>
>
> import java.io.*;
>
> import org.jdom.*;
> import org.jdom.input.*;
> import org.jdom.output.*;
>
> import java.util.*;
>
> public class RequestParser2 {
>
> public static void main(String[] args) {
>
>
>
> file://if ( "Reader".equalsIgnoreCase(args[1]) )
>
> try {
>
> File theFile = new File(args[0]);
> FileReader file = new FileReader(theFile);
> BufferedReader buff = new BufferedReader(file);
> FileInputStream fis = new FileInputStream(new File(args[0]));
> InputStreamReader isr = new InputStreamReader(new FileInputStream(new
> File(args[0])));
>
> SAXBuilder builder = new SAXBuilder();
> XMLOutputter fmt = new XMLOutputter();
> Document doc;
> int i;
>
> try {
> // build and output with FileInputStream
> System.out.println("\n\n******************\nbuild and output with
> FileInputStream. Ready? (hit 'Enter')");
> System.in.read();System.in.read();
> doc = builder.build(fis);
> fmt.output(doc,System.out);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> try {
> // build and output with BufferedReader
> System.out.println("\n\n******************\nbuild and output with
> BufferedReader. Ready? (hit 'Enter')");
> System.in.read();System.in.read();
> doc = builder.build(buff);
> fmt.output(doc,System.out);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> try {
> // build and output with FileReader
> System.out.println("\n\n******************\nbuild and output with
> FileReader. Ready? (hit 'Enter')");
> System.in.read();System.in.read();
> doc = builder.build( file);
> fmt.output(doc,System.out);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> try {
> // build and output with FileReader cast to Reader
> System.out.println("\n\n******************\nbuild and output with
> FileReader cast to Reader. Ready? (hit 'Enter')");
> System.in.read();System.in.read();
> doc = builder.build((java.io.Reader)file);
> fmt.output(doc,System.out);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> try {
> // build and output with FileReader cast to InputStreamReader
> System.out.println("\n\n******************\nbuild and output with
> FileReader cast to InputStreamReader. Ready? (hit 'Enter')");
> System.in.read();System.in.read();
> doc = builder.build((java.io.InputStreamReader)file);
> fmt.output(doc,System.out);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> try {
> // build and output with InputStreamReader
> System.out.println("\n\n******************\nbuild and output with
> InputStreamReader. Ready? (hit 'Enter')");
> System.in.read();System.in.read();
> doc = builder.build( isr );
> fmt.output(doc,System.out);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> try {
> // build and output with File
> System.out.println("\n\n******************\nbuild and output with File.
> Ready? (hit 'Enter')");
> System.in.read();System.in.read();
> doc = builder.build(theFile);
> fmt.output(doc,System.out);
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> } catch (Exception e) {
> e.printStackTrace();
> }
>
> }
>
> } // end RequestParser2 class
>
>
>
>
> Here is the file being parsed:
>
> <?xml version="1.0"
>
encoding="UTF-8"?><WMREQUEST><ACTION>adminLogin</ACTION><PAYLOAD><LOGINID>ke
> vin</LOGINID><PWORD>kegvin</PWORD></PAYLOAD></WMREQUEST>
>
> _______________________________________________
> To control your jdom-interest membership:
>
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com
>




More information about the jdom-interest mailing list