[jdom-interest] SAXBuilder bug::build(URL or Reader) (part 2)

Emmanuel Gilmont emmanuel at isc.be
Thu Oct 9 00:41:50 PDT 2003


Hi all,

I tested the solution provided by Bill Woodward but it doesn't work and 
I don't know why.

I give a sample code and my xml file here after.

What is strange is that I can read the file when on disk but not trough 
a url, nor in a jar file nor from a website.

I think I will revert to beta 8 version until it's corrected. Except if 
someone has a solution :)

Thanks for all,
Emmanuel

----[XML file : tpc.xml]----------------------------------------------------
<?xml version="1.0" encoding="ISO-8859-1"?>
<docroot>
  <tpc version="1.0">
    <profile name="item1" value="1" />
    <profile name="item2" value="2" />
    <profile name="item3" value="3" />
    <profile name="item4" value="4" />
  </tpc>
</docroot>
----[java code]----------------------------------------------------
import java.io.*;
import java.net.*;
import org.jdom.*;
import org.jdom.input.*;

public class testjdom
{
  public testjdom()
  {
  }
 
  private void readFileFromDisk()
  {
    try
    {
      System.out.println("------ Reading from file : start ------");
      File f = new File("c:/tpc.xml");
      SAXBuilder sb = new SAXBuilder();
      Reader schemaReader = new InputStreamReader(new FileInputStream(f));
      System.out.println("-------------------");
      int x = schemaReader.read();
      while (x != -1)
      {
        System.out.print((char)x);
        x = schemaReader.read();
      }
      System.out.println("-------------------");
      sb.build(f);
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
 
  private void readFileFromUrl()
  {
    try
    {
      System.out.println("------ Reading from URL : start ------");
      File f = new File("c:/tpc.xml");
      SAXBuilder sb = new SAXBuilder();
      URL schemaUrl = new URL("http://localhost/tpc.xml");
      Reader schemaReader = new InputStreamReader(schemaUrl.openStream());
      System.out.println("-------------------");
      int x = schemaReader.read();
      while (x != -1)
      {
        System.out.print((char)x);
        x = schemaReader.read();
      }
      System.out.println("-------------------");
      sb.build(schemaReader);
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
  public static void main(String args[])
  {
    testjdom job = new testjdom();
    job.readFileFromDisk();
    job.readFileFromUrl();
  }
}
----[stdout dump]----------------------------------------------------
------ Reading from file : start ------
-------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<docroot>
  <tpc version="1.0">
    <profile name="item1" value="1" />
    <profile name="item2" value="2" />
    <profile name="item3" value="3" />
    <profile name="item4" value="4" />
  </tpc>
</docroot>
-------------------
------ Reading from URL : start ------
-------------------
<?xml version="1.0" encoding="ISO-8859-1"?>

<docroot>
  <tpc version="1.0">
    <profile name="item1" value="1" />
    <profile name="item2" value="2" />
    <profile name="item3" value="3" />
    <profile name="item4" value="4" />
  </tpc>
</docroot>
-------------------
org.jdom.input.JDOMParseException: Error on line 1: ElÚment racine de 
document manquant.
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:381)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:764)
        at testjdom.readFileFromUrl(testjdom.java:62)
        at testjdom.main(testjdom.java:81)
Caused by: org.xml.sax.SAXParseException: ElÚment racine de document 
manquant.
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3339)
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3327)
        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:635)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:333)
        at 
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)
        ... 3 more
Caused by: org.xml.sax.SAXParseException: ElÚment racine de document 
manquant.
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3339)
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3327)
        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:635)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:333)
        at 
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:764)
        at testjdom.readFileFromUrl(testjdom.java:62)
        at testjdom.main(testjdom.java:81)
Caused by: org.xml.sax.SAXParseException: ElÚment racine de document 
manquant.
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3339)
        at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3327)
        at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:635)
        at org.apache.crimson.parser.Parser2.parse(Parser2.java:333)
        at 
org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:370)
        at org.jdom.input.SAXBuilder.build(SAXBuilder.java:764)
        at testjdom.readFileFromUrl(testjdom.java:62)
        at testjdom.main(testjdom.java:81)





More information about the jdom-interest mailing list