How to remove this warning: com.sun.org.apache.xerces.internal.dom.DOMImplementationImpl is a patented Sun 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 meet warnings below 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 ) ); 
+4
source share
3 answers

Do not reference a specific DOMImplementation. Use instead:

 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 less flexible XML factory interface like JDOM :) (I always found the Java W3C DOM API - a complete pain to work with.)

Another alternative is to use a specific DOMImplementation, but make it external, rather than relying on an implementation built into the JDK. It can be Apache Xerces , only from the jar file.

+5
source

The way to remove a warning is to avoid using Sun's internal, undocumented classes and methods in your code.

+1
source

Do not try to remove the warning. Rather, remove the import statement and use another parser that you initialize using its factory parser.

0
source

Source: https://habr.com/ru/post/1344885/


All Articles