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

Elliotte Rusty Harold elharo at metalab.unc.edu
Mon Jul 21 05:56:49 PDT 2003


At 5:39 AM -0700 7/21/03, Peter Smith wrote:


>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 can check an actual XML document for validity as it's being 
parsed to build a Document object. However, a Document object is not 
an XML document (any ore than a Person object is a real person) and 
JDOM cannot check the Document object for validity.


>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?

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

>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?

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.

>I will be pulling out sections of xml files
>(individual transactions) and validating each
>individual transaction against a separate dtd -
>depending on the type of transaction.  At least,
>that's what I gather I'm going to have to do.  Does
>this scenario make sense?  I was under the impression
>that an xml file, once validated by a dtd, was valid -
>which means that everything in that xml file was
>valid.  Could there be another, more detailed level,
>of validation that might occur?

Depends on how you define validation. If you mean strictly DTD 
validation, then no. That's all you can do.

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

Yes, parse it.

>When sending xml files to another system/party, is it
>customary to use a well-known URL for the DOCTYPE
>command/instruction, or a simple one, or is it
>customary to include one at all - especially if the
>file naming convention implies the DTD type?
>     e.g.  <!DOCTYPE chapter SYSTEM "docbookx.dtd">
>                  vs.
>     e.g.  <!DOCTYPE chapter SYSTEM
>"http://www.foo.com/docbookx.dtd">
>
>
>I noticed my command-line Java program was unable to
>load/validate an XML file because, due to
>firewall/proxy issues, it was unable to load a DTD
>referenced on the web, where the DOCTYPE URL pointed.
>Of course, I'd rather use a local copy of the DTD.
>Can I force JDOM to use a local copy of a DTD?

Yes. It's time to learn about catalogs.

>Is a DTD supposed to be well-formed?

Yes.

>Is there such a thing as a 'valid' DTD, as opposed to
>just 'well-formed'?

No.
-- 

   Elliotte Rusty Harold
   elharo at metalab.unc.edu
   Processing XML with Java (Addison-Wesley, 2002)
   http://www.cafeconleche.org/books/xmljava
   http://www.amazon.com/exec/obidos/ISBN%3D0201771861/cafeaulaitA



More information about the jdom-interest mailing list