code: public static Element getRootElement( InputStream input )
          throws ParserConfigurationException, IOException, SAXException
      {
          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          factory.setValidating( false );
          factory.setNamespaceAware( false );
          try
          {
              factory.setFeature( "http://xml.org/sax/features/namespaces", false );
              factory.setFeature( "http://xml.org/sax/features/validation", false );
              factory.setFeature( "http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false );
              factory.setFeature( "http://apache.org/xml/features/nonvalidating/load-external-dtd", false );
          }
          catch( Throwable ignore )
          {
              // ignore. we did our best.
          }
          DocumentBuilder builder = factory.newDocumentBuilder();
          try
          {
              // return an empty entity resolver if parser will ask for it, such disabling any validation 
              builder.setEntityResolver(
                  new EntityResolver()
                  {
                      public InputSource resolveEntity( java.lang.String publicId, java.lang.String systemId )
                          throws SAXException, java.io.IOException
                      {
                          return new InputSource(
                              new ByteArrayInputStream( "<?xml version='1.0' encoding='UTF-8'?>".getBytes() )
                          );
                      }
                  }
              );
          }
          catch( Throwable ignore )
          {
              // ignore. we did our best.
          }
          Document document = builder.parse( input );
          return document.getDocumentElement();
      }
docs: Return the root element of the supplied input stream.
  
  @param input the input stream containing a XML definition
  
  @return the root element
  
  @throws IOException                  If an underlying I/O problem occurred.
  @throws ParserConfigurationException if there is a severe problem in the XML parsing subsystem.
  @throws SAXException                 If the XML is malformed in some way.