import org.xml.sax.SAXParseException; import org.xml.sax.InputSource; import org.w3c.dom.Document; import oracle.xml.parser.v2.*; import java.io.*; import java.net.*; import URLUtils; public class ParseFAQWithValidation { public static void main(String[] args) throws Exception { String filename = "FAQWithMultipleEntities.xml"; // Use a URL directly from the beginning. No need to set SystemId URL fileURL = URLUtils.newURL(filename); // Create a new XML Parser DOMParser dp = new DOMParser(); // Validate the document against its DTD dp.setValidationMode(true); try { // Attempt to parse the URL dp.parse(fileURL); System.out.println("Parsed ok."); // Get the parsed document Document xmldoc = dp.getDocument(); // Print the document ((XMLDocument)xmldoc).print(System.out); } catch (SAXParseException spe) { System.out.println(spe.getMessage()); } } } |