Can anyone help me out. I have a set of xml documents and a dtd which
is not refered to in the xml documents themselves.
I've written the code to check that the xml is well formatted using
org.apache.xerces.parsers.DOMParser and i've created my own
entityResolver().
When i try and assign the DTD to the parser using the entityResolver
the parser does not throw any error indicating that the xml is
invalid.
This is driving me mad. Any help much appreciated.
================================================== =========================
private static void parseFile(File f)
{
DOMParser parser = new DOMParser();
parser.setEntityResolver(new MyResolver());
try
{
byte[] bytes = new byte[0];
FileInputStream fis = new FileInputStream(f);
bytes = new byte[(int) f.length()];
fis.read(bytes);
fis.close();
// Turn the the byte array into a InputSource for the
parser
final ByteArrayInputStream xmlByteStream = new
ByteArrayInputStream(bytes);
final InputSource xmlInputSource = new
InputSource(xmlByteStream);
parser.parse(xmlInputSource);
final Document document = parser.getDocument();
}
catch (SAXException e)
{
System.out.println(f.getName() + " " + e);
}
catch (IOException e)
{
System.out.println(f.getName() + " " + e);
}
}
================================================== =========================
public class MyResolver implements EntityResolver
{
public InputSource resolveEntity(String publicId, String systemId)
throws SAXException, IOException
{
File f = new File("h:\\xml\\article_dtd.dtd");
FileInputStream fis = null;
try
{
fis = new FileInputStream(f);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
return new InputSource(fis);
}
}
================================================== ===========================