[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()
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/youraddr@yourhost.com
More information about the jdom-interest
mailing list