getDOMImplementation()
returns a
DOMImplementation
object that supports the features given in the argument,
or null if no such implementation can be found.
Request a DOMImplementation
that supports XML DOM Level 1, any version of the traversal module, and DOM Level 2 events:
try {
DOMImplementation impl = DOMImplementationRegistry
.getDOMImplementation("XML 1.0 Traversal Events 2.0");
if (impl != null) {
DocumentType svgDOCTYPE = impl.createDocumentType("svg",
"-//W3C//DTD SVG 1.0//EN",
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd");
Document svgDoc = impl.createDocument(
"http://www.w3.org/2000/svg", "svg", svgDOCTYPE
);
// work with the document...
}
}
catch (Exception ex) {
System.out.println(ex);
}
Be sure to check whether the implementation returned is null before using it. Many installations may not be able to support all the features you ask for.
DOMImplementationRegistry
searches for DOMImplementation classes by reading the value of the
org.w3c.dom.DOMImplementationSourceList
Java system property.
This property should contain a white space separated list of DOMImplementationSource