Beispiel #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;
  }
Beispiel #2
0
  public void init() {
    root = new Element("cdi");

    // add schema definitions
    root.setAttribute(
        "noNamespaceSchemaLocation", // NOI18N
        "http://openlcb.org/trunk/specs/schema/cdi.xsd", // NOI18N
        org.jdom2.Namespace.getNamespace(
            "xsi", // NOI18N
            "http://www.w3.org/2001/XMLSchema-instance")); // NOI18N

    doc = new Document(root);

    // no DOCTYPE defined; this is a schema-only format

    // add XSLT processing instruction
    // <?xml-stylesheet type="text/xsl"
    // href="http://openlcb.org/trunk/prototypes/xml/xslt/cdi.xsl"?>
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    m.put("type", "text/xsl");
    m.put("href", "http://openlcb.org/trunk/prototypes/xml/xslt/cdi.xsl");
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
  }