4

While parsing the XML files my documentbuilder was looking for the DTD and sometimes it use to throw error (server crashes). So when I googled I got the following solution from here Ignoring the DTD while parsing XML (the solution which I used is with VOTE---90). Letter in my IDE show the following error.

The method setFeature(String, boolean) is undefined for the type DocumentBuilderFactory

Then I thought its the problem with my maven version then I found the following link.

What is the jar file I should download and from where?

Which says its inbuilt in JDK so that the IDE itself will suggest me the imports.

My JDK version is

java version "1.8.0_121" Java(TM) SE Runtime Environment (build 1.8.0_121-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Maven reference for DocumentBuilder

The code in class from jar file Looks like the class doesn't have the method

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
goodyzain
  • 683
  • 2
  • 8
  • 21
  • there's something wrong with your IDE, that method is present in `DocumentBuilderFactory`. Provide your imports and everything should be fine – Eugene Jun 19 '17 at 06:25
  • 1
    Do you maybe have your own class in your project that also happens to be named `DocumentBuilderFactory`, so that the compiler picks that up instead of the standard class `javax.xml.parsers.DocumentBuilderFactory`? – Jesper Jun 19 '17 at 06:39
  • @Jesper no i dont have any class with that name...my imports...import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; – goodyzain Jun 19 '17 at 06:54
  • this is the source .m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2-sources.jar – goodyzain Jun 19 '17 at 06:56
  • that `xml-api-….jar` is not part of the jdk and hence the contained `DocumentBuilderFactory` class is not the `DocumentBuilderFactory` class provided by the JRE. It’s not clear which one the compiler uses is your setup, but normally, it should prefer the JRE’s, as that the one, the JRE will prefer too (which raises questions about the purpose of delivering that redundant copy in the classpath)… – Holger Jun 19 '17 at 07:25
  • As the [question you linked to](https://stackoverflow.com/questions/18173731/what-is-the-jar-file-i-should-download-and-from-where) says, you do not need any extra JAR file to use these classes, they are part of the standard JDK. You don't need any dependency on any xml-apis JAR. Get rid of the dependency on `xml-apis-1.0.b2.jar`. – Jesper Jun 19 '17 at 07:25
  • @Holger its working now all i did is just removed the Extra maven jar...IDE automatically imported the class and setFeature works :) – goodyzain Jun 19 '17 at 07:31

1 Answers1

7

The answer to the following questing fixed this for me.

Node.getTextContent() is undefined in Node

Basically, you need to move JRE library to the top of your dependencies in eclipse.

Bahadır Yağan
  • 5,577
  • 3
  • 35
  • 39
  • Correct. I moved my JRE System Library to the top of the build order and the IDE picked up the correct one. – Obaid Jul 13 '23 at 17:14