示例#1
0
  public Element getFileRoot(String filename) {

    // find file & load file
    Element root = null;

    boolean verify = false;

    try {
      SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser", verify);

      builder.setFeature("http://apache.org/xml/features/xinclude", true);
      builder.setFeature("http://apache.org/xml/features/xinclude/fixup-base-uris", false);
      builder.setFeature("http://apache.org/xml/features/allow-java-encodings", true);
      builder.setFeature("http://apache.org/xml/features/validation/schema", verify);
      builder.setFeature("http://apache.org/xml/features/validation/schema-full-checking", verify);
      builder.setFeature("http://xml.org/sax/features/namespaces", true);

      Document doc =
          builder.build(new BufferedInputStream(new FileInputStream(new File(filename))));
      root = doc.getRootElement();
    } catch (Exception e) {
      System.out.println("While reading file: " + e);
    }
    return root;
  }