Reputation: 1
Could you please help to solve the issue "setXIncludeAware is not supported on this JAXP implementation or earlier: class org.apache.xerces.jaxp.SAXParserFactoryImpl"
Java version used in server : 1.8.0_361 JVM rumtime version : 8.1.092 11.0.18+000
and the project is build using : saxon-he-12.5.jar
code snippet:
public class PositionalXMLReader {
final static String LINE_NUMBER_KEY_NAME = "lineNumber";
final static String END_LINE_NUMBER_KEY_NAME = "endLineNumber";
public static Document readXML(final InputStream is) throws IOException, SAXException {
final Document doc;
SAXParser parser;
try {
final SAXParserFactory factory = SAXParserFactory.newInstance();
parser = factory.newSAXParser();
factory.setXIncludeAware(true);
factory.setNamespaceAware(true);
final DocumentBuilderFactory docBuilderFactory=DocumentBuilderFactory.newInstance();
final DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
doc = docBuilder.newDocument();
} catch (final ParserConfigurationException e) {
throw new RuntimeException("Can't create SAX parser / DOM builder.", e);
}
Code execution on server without the following error :
"Details: java.lang.UnsupportedOperationException; setXIncludeAware is not supported on this JAXP implementation or earlier: class org.apache.xerces.jaxp.SAXParserFactoryImpl, UnsupportedOperationException: setXIncludeAware is not supported on this JAXP implementation or earlier: class org.apache.xerces.jaxp.SAXParserFactoryImpl"
Upvotes: -1
Views: 84
Reputation: 163342
Looks like you're picking up the Apache version of Xerces rather than the JDK version, and it's possible you're picking up a rather old version. Check what's on your classpath.
And frankly, using the JAXP methods like SAXParserFactory.newInstance()
is thoroughly dangerous. It means you'll pick up whatever implementation is lying around on the classpath at the time the program runs, which might be quite different from any implementation that you tested your code against.
I used to recommend using Apache Xerces in preference to the JDK version because it was better maintained, the JDK version had some serious bugs. That situation is now reversed, and the JDK version is to be preferred.
Upvotes: 0