You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by "Wake, Chris" <Ch...@westgroup.com> on 2002/01/07 20:28:07 UTC

XMLReader.parse exception with StringReader as InputSource

Hi-

I am using xerces 1.4.1 and I get different behaviors based on the
InputSource that I pass to the parse method.  If I use the file name
directly [parser.parse("doctype2.xml");], it works fine.  If I pass in a
string containing the contents of the file [parser.parse(new InputSource(new
StringReader(s2)));], I get a NullPointerException at XMLParser.java:1094.
My simple java program and input files are below.  Any help or insight would
be greatly appreciated.

Zoo2.java:
import java.util.*;
import java.io.*;
import org.xml.sax.*;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;

public class Zoo2 extends DefaultHandler
{
  public static void main (String[] args)
  {
    try
    {
      XMLReader parser =
(XMLReader)Class.forName("org.apache.xerces.parsers.SAXParser").newInstance(
);

      // works
      System.out.println("Direct File");
      parser.parse("doctype2.xml");

      // exception: XMLParser.java:1094
      System.out.println("String");
      BufferedReader br = new BufferedReader(new
FileReader("doctype2.xml"));
      String s1;
      String s2 = "";
      while ((s1 = br.readLine()) != null)
        s2 += s1;
      br.close();
      System.out.println(s2);
      parser.parse(new InputSource(new StringReader(s2)));
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }
}

doctype2.xml:
<!DOCTYPE wrapper [
  <!ELEMENT wrapper (publication)>
  <!ENTITY % dtd SYSTEM "test2.dtd">
  %dtd;
  <!ENTITY segment SYSTEM "test2.xml">
]>
<wrapper>
  &segment;
</wrapper>

test2.dtd:
<!ELEMENT publication (#PCDATA)>

test2.xml:
<publication>
Hello
<bad_elem />
</publication>

Christopher Wake
West Group
716-546-5539 x3128


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org