Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove this warning: com.sun.org.apache.xerces.internal.dom.DOMImplementationImpl is Sun proprietary API and may be removed in a future release

import com.sun.org.apache.xerces.internal.dom.DOMImplementationImpl;
public static Document newDocument( String pName ) {

    return DOMImplementationImpl.getDOMImplementation().createDocument(
        null,
        pName,
        DOMImplementationImpl.getDOMImplementation().createDocumentType( pName, null, null ) );

}

I have encounter with below warnings in netbeans

warning: com.sun.org.apache.xerces.internal.dom.DOMImplementationImpl is Sun proprietary API and may be removed in a future release
return DOMImplementationImpl.getDOMImplementation().createDocument(


warning: com.sun.org.apache.xerces.internal.dom.DOMImplementationImpl is Sun proprietary API and may be removed in a future release DOMImplementationImpl.getDOMImplementation().createDocumentType( pName, null, null ) );                
like image 288
Mohsin Avatar asked Mar 23 '11 07:03

Mohsin


2 Answers

Don't refer to a concrete DOMImplementation. Instead, use:

DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance();
DOMImplementation implementation = registry.getDOMImplementation("XML 1.0");
DocumentType type = implementation.createDocumentType(pName, null, null);
Document document = implementation.createDocument(null, pname, type);    

Alternatively, use a rather less factory-heavy XML API, like JDOM :) (I've always found the Java W3C DOM API to be a complete pain to work with.)

Yet another alternative would be to use a concrete DOMImplementation, but make it an external one rather than relying on an implementation built into the JDK. This could still be Apache Xerces, just from a jar file.

like image 91
Jon Skeet Avatar answered Oct 07 '22 06:10

Jon Skeet


The way to remove the warning is to avoid using internal, undocumented classes and methods from Sun in your code.

like image 34
Ted Hopp Avatar answered Oct 07 '22 06:10

Ted Hopp