[jdom-interest] Example of LocatedElement

Rolf Lear jdom at tuis.net
Thu Jun 7 16:06:31 PDT 2012

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() 

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':


For examples of error handlers.... the test harness will not help much, 
but this should help: 


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/youraddr@yourhost.com

More information about the jdom-interest mailing list