Re: Example of LocatedElement
Rolf Lear <[email protected]> Thu, 07 Jun 2012 19:06:31 -0400
| Newsgroups | gmane.comp.java.jdom.general |
|---|---|
| Message-ID | <[email protected]> |
Hi Jose. If you want to locate just the first error then you should just check the JDOMException returned when parsing. If you want to locate all the errors/warnings, then you should create an ErrorHandler instance, and override the respective methods, and get the location of the parsing error when the respective error-handler method is called, and make sure you do not throw an excepion from the ErrorHandler method. If you just want to get the location of all the content (not just the errors), then you should use the ortg.jdom2.located.LocatedJDOMFactory for your SAXBuilder and all the resulting content will implement the org.jdom2.located.Located interface (with a getLine() and getColumn() method). If you want to have both LocatedElement results as well as trapping each error, you may want to experiment with using both an ErrorHandler and LocatedJDOMFactory for the SAXBuilder. As for examples, well, the test-cases for locatedJDOMFactory would be a logical place I guess, but since the functionality is new in JDOM 2, I don't think that there are many examples 'in the wild': https://github.com/hunterhacker/jdom/blob/master/test/src/java/org/jdom2/test/cases/located/TestLocatedJDOMFactory.java#L51 For examples of error handlers.... the test harness will not help much, but this should help: http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html and http://www.jdom.org/docs/apidocs/org/jdom2/input/SAXBuilder.html#getErrorHandler%28%29 Rolf On 07/06/2012 6:50 PM, JOSE L MARTINEZ-AVIAL wrote: > Hello, > Has somebody an example of how LocatedElement can be used? I use Jdom > to parse an XML using SAXBuilder, and I'd like to pinpoint to the user > the location of an error in the file, but so far I haven't seen any > example of how to get the LocatedElement of an element. > > Thanks > > JL > > > _______________________________________________ > 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]