Plugin XML Reader
I am writing a plugin and I need to do some XML parsing. Since I am writing a wrapper around an existing library I tried to use their classes (already written) to do so.
They use dom4j (not jdom) and I keep getting a problem when loading the SAXParser. The following line runs fine if I run it through a main function but fails when I run the plugin from the sandbox:
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser
..
SAX2 driver class org.apache.xerces.parsers.SAXParser does not implement XMLReader
I guess this is because it is loadig the SAXParser from the JDK or an Intellij lib directory and not the one I have on my classpath (version 2.6.2). Is there any way to overcome this issue? Or am I forced to use to rewrite the parsing using JDOM?
I tried looking at the Version class through a debugger and it reports the correct version so I am not sure where it is getting the SAXParser from??
Any help would be much appreciated...
Laurence
Please sign in to leave a comment.
I seemed to have solved it by removing xerces and xml-apis off the classpath to my plugin. Not sure why that was causing it problems?? but it is solved now...
It was causing problems because IDEA has it's own xerces and xml-api jars. Now when you're using a class which has already been loaded by IDEA, you will get the one from IDEA. But when you're using a new class, then it is loaded from your own jars. You'll end up with a mix of classes from two different implementations.
See also the discussion here: http://www.intellij.net/forums/thread.jspa?threadID=260672