[jdom-interest] basic xml/jdom questions...

Alex Rosen arosen at novell.com
Mon Jul 21 07:07:37 PDT 2003


Some additional comments:

>What are the major API's I can use for XML parsing?
>  * JDOM
>  * DOM4J
>   ???

Check out http://www.xml.com/pub/a/2003/07/09/xmlapis.html

>Chapter 14 of the 'Processing XML with Java' book
>says:
>"It (JDOM) cannot check a Document object against a
>schema or a DTD."
>What exactly does this statement mean if JDOM can, in
>fact, generate an exception when reading a
>non-wellformed or invalid document?

JDOM relies on the underlying parser to validate the document (see
http://jdom.org/docs/faq.html#a0010). So it can check for validity
only during parse time. I don't know of any XML technology that can
check for validity except at parse time.

>I read in that same book that the author (??) is
>working on a patch to to be able to differentiate
>between well-formedness exceptions and validity
>exceptions.  Is this true, and if so, is it done?

[Elliotte said: Yes, it's done; and the patch was rejected so that
isn't going to happen.]

Unfortunately there's no way to know 100% of the time whether the
parser is giving a well-formedness error or a validity error, so Jason
decided to leave it out.

>I have received some xml files which I have to
>validate, parse, etc.  They do not have 'doctype' tags
>in them, but I know which dtd they're supposed to
>conform to.  Is it possible, with JDOM, to validate
>these xml files against my dtd even though they don't
>contain a DOCTYPE reference?

[Elliotte said: No, you'd need to step outside JDOM to hack this
together, or 
perhaps, parse, add a doctype, reserialize, and reparse. It's ugly 
and inefficient. This is a weak spot of DTD rules.]

XML schemas fix this weak spot. If you had a schema instead of a DTD
you could do this.

>Is it possible to validate a String of XML against a
>DTD, at all, or with JDOM?

Yes, parse it... subject to the limitations above.

Alex




More information about the jdom-interest mailing list