code: public static Document getResourceAsDocument(
              Class<?> requestingClass, String resource, boolean validate)
              throws ResourceMissingException, IOException, ParserConfigurationException,
                      SAXException {
          Document document = null;
          InputStream inputStream = null;
  
          try {
  
              DocumentBuilderFactory factoryToUse = null;
  
              if (validate) {
                  factoryToUse = ResourceLoader.validatingDocumentBuilderFactory;
              } else {
                  factoryToUse = ResourceLoader.nonValidatingDocumentBuilderFactory;
              }
              inputStream = getResourceAsStream(requestingClass, resource);
              DocumentBuilder db = factoryToUse.newDocumentBuilder();
  
              db.setEntityResolver(new DTDResolver());
              db.setErrorHandler(
                      new SAXErrorHandler("ResourceLoader.getResourceAsDocument(" + resource + ")"));
              document = db.parse(inputStream);
          } finally {
              if (inputStream != null) inputStream.close();
          }
          return document;
      }
docs: Get the contents of a URL as an XML Document
  
  @param requestingClass the java.lang.Class object of the class that is attempting to load the
  resource
  @param resource a String describing the full or partial URL of the resource whose contents to
  load
  @param validate boolean. True if the document builder factory should validate, false
  otherwise.
  @return the actual contents of the resource as an XML Document
  @throws ResourceMissingException
  @throws java.io.IOException
  @throws javax.xml.parsers.ParserConfigurationException
  @throws org.xml.sax.SAXException