Re: jdom2 runtime
"Craig Christophersen" <[email protected]> Tue, 21 Aug 2012 13:10:31 -0600
| Newsgroups | gmane.comp.java.jdom.general |
|---|---|
| Message-ID | <[email protected]> |
Thanks Rolf. I am able to run new SAXBuilder(new XMLReaderSAX2Factory(false, "org.apache.xerces.parsers.SAXParser")); OK. I do have xercesImpl and xml-apis in my classpath. But I cannot yet get the no arg constructor (new SAXBuilder()) to run. Is there some advantage to using the no arg constructor? Thanks, Craig From: Rolf Lear [mailto:[email protected]] Sent: Tuesday, August 21, 2012 12:39 PM To: Craig Christophersen Cc: [email protected] Subject: Re: [jdom-interest] jdom2 runtime In JDOM 2.x the new SAXBuilder() (no arguments) will use regular JAXP API's to get the right SAX Parser for your system. The JAXP process is described here: http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/SAXParserFactory. html#newInstance%28%29 In most cases, if you want to use a particular parser (xerces, for example), all you need to do is add the jar to the classpath. As a fallback mechanism, the standard JRE has an XML Parser built in already (an older version of xerces with some customizations - one of which is that it is not in the regular apache package.... so you cannot call it org.apache.xerces.parsers.SAXParser). So, you do not need to have any third-party jar unless you want one. I would still recommend adding xerces to your classpath though (and with it, you will want the xml-apis.jar). So, in your 'old' code, if you used to do: ... = new SAXBuilder("org.apache.xerces.parsers.SAXParser"); then I suggest you either: - add (only) xerces (with xmlapis.jar) to the classpath, and use the plain ... = new SAXBuilder(); constructor.... - add xerces to the classpath, use ... = new SAXBuilder(new XMLReaderSAX2Factory(false, "org.apache.xerces.parsers.SAXParser")); Note though, that the deprecated/'old' constructor new SAXBuilder("org.apache.xerces.parsers.SAXParser"); will still work (with a deprecated warning) if you have the xerces.jar in your classpath. I recommend that you use the (newer) JAXP API for constructing SAXBuilders. You can still customize it with a particular library. I note that there is a lack of functionality in JDOM for using JAXP with a custom factory.... I will add that.... I think.... see issue #89 For what it's worth, the documentation on the org.jdom.input.sax is fairly comprehensive: http://www.jdom.org/docs/apidocs/org/jdom2/input/sax/package-summary.html even though it does not have an example of what you want (although it has other examples). Also, the source code for the deprecated constructor is educational... : https://github.com/hunterhacker/jdom/blob/master/core/src/java/org/jdom2/inp ut/SAXBuilder.java#L266 and https://github.com/hunterhacker/jdom/blob/master/core/src/java/org/jdom2/inp ut/SAXBuilder.java#L288 I will consider the usage of a JAXP custom factory using the 'other' JAXP constructor: http://docs.oracle.com/javase/6/docs/api/javax/xml/parsers/SAXParserFactory. html#newInstance%28java.lang.String,%20java.lang.ClassLoader%29 Issue #89: https://github.com/hunterhacker/jdom/issues/89 Rolf On 21/08/2012 1:23 PM, Craig Christophersen wrote: Hello; While I now have jdom2 compiling OK in an application, I am running into runtime problems with SAXBuilder. With previous jdom both SAXBuilder builder = new SAXBuilder(); and SAXBuilder builder = new SAXBuilder("org.apache.xerces.parsers.SAXParser"); worked for constructing a SAXBuilder. Question: So now to use new SAXBuilder() (which uses JAXP) do I need something additional in my classpath?? Or is there somewhere I can see an example of what is mentioned in the migration guide --- Deprecated. use <http://www.jdom.org/docs/apidocs/org/jdom2/input/SAXBuilder.html#SAXBuilder %28org.jdom2.input.sax.XMLReaderJDOMFactory%29> SAXBuilder(XMLReaderJDOMFactory) with <http://www.jdom.org/docs/apidocs/org/jdom2/input/sax/XMLReaderSAX2Factory.h tml#XMLReaderSAX2Factory%28boolean,%20java.lang.String%29> XMLReaderSAX2Factory.XMLReaderSAX2Factory(boolean, String)? Thanks, Craig Christophersen Software Developer Synesis7 [email protected] _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/[email protected] _______________________________________________ To control your jdom-interest membership: http://www.jdom.org/mailman/options/jdom-interest/[email protected]