RSSCategory: Others

The method getTextContent() is undefined for the type Node

The method getTextContent() is undefined for the type Node

| May 3, 2012 | 18 Comments


The method getTextContent() is undefined for the type Node
You can get this kind of error when your develop a system that use xml manipulation using library xml-apis. If you try to find a solution by a search in google you can find solutions like:

org.w3c.dom.Node.getTextContent() is only available as of Java 1.5

But, you are running and compile your project using Java 1.5. If yo
u are using Eclipse as IDE you can check this by right clicking on the project, Properties -> Java Compiler, and confirm that 1.5 or above are in the drop down lists. You also can see the projects facets to be sure.

Spotting the problem The method getTextContent() is undefined for the type Node in Eclipse

In the Eclipse “Problems” tab where you saw the  error (one time for each coincidence in the workspace).  If you don’t see that tab, go to Window -> Show View -> Problems.

The line with the problem may had the next apparence:


Node node = .....
.... node.getTextContext()...


Mouse over the capitalized word “Node” on the previous line, the yellow balloon assist should show “org.w3c.dom.Node”.

Now highlight the word Node. Right click, select Declarations -> Workspace.

In a moment a new “Search” tab should appear and report 2 declarations for org.w3c.dom.Node, in:

  • classes.jar in jdk libs.
  • xml-apis-1.0.b2.jar

It’s the second entry that’s causing the problem, it’s being pulled in from the contrib/extraction area, which Eclipse included but ant doesn’t.

The root cause of The method getTextContent() is undefined for the type Node

There are many jars packaged in the jdk libs and they sometimes contain the same library routines that xml-apis, but at different versions.  When Eclipse created the  project it tries to create a reasonable default classpath to build with, but the order matters, and in this case the list and order is different than what the ant build utility would have created.

The solution

The order of the classpath needs to be tweaked in Eclipse project; shove the xml-apis-1.0.b2.jar all the way to the bottom, past the built in JVM libraries. Probably if you use maven to deploy or package projects or ant you don´t have this problem.

¿How can i fix it in Eclipse?

Right click project, select Properties -> Java Build Path. The problem would stay with xml-apis-1.0.b2.jar and others related libraries such as xerces.

Go to Order and Export Tab, select the jdk library and click on buttom top to move it all the way up, so that have to be the first libraries to use.And it should not have a checkmark.

Save the settings with the OK button and Eclipse should recompile everything, it might take it a second to wake up.  But the Problems tab should now have no Errors, although still a ton of warnings.  But those are a matter for another day!