users@jaxb.java.net

best way to ignore DTD?

From: Andrew Ferguson <Andrew.Ferguson_at_arm.com>
Date: Tue, 27 May 2003 16:34:43 +0100

hi,

 I have an application that needs to process many xml files quickly. At the
moment they all point to one of two DTDs on the web, one of which doesn't
exist any more. This causes two problems

1) JAXB seems to fetch the DTD for each file processed, which slows
everything down quite a lot
2) XML files that point at the non-existent DTD file fail to be parsed even
if validation is disabled

to get round this I've added the following temporary hack

public static InputStream filterOutDTDRef(InputStream in) throws
IOException {
      BufferedReader iniReader = new BufferedReader(new
InputStreamReader(in));
      StringBuffer newXML = new StringBuffer();
      for(String line = iniReader.readLine(); line!=null; line =
iniReader.readLine())
         newXML.append(line+"\n");
      in.close();

      int s = newXML.indexOf("<!DOCTYPE ");
      if(s!=-1)
         newXML.replace(s,newXML.indexOf(">",s)+1,"");

      return new ByteArrayInputStream(newXML.toString().getBytes());
   }

This works (and is quite a lot faster than letting the DTD be fetched) but
I was wondering if there is a more straightforward way to do this?
thanks,
Andrew