Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] dtd problems

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Harold <elharo AT metalab.unc.edu>
  • To: luca <passani AT eunet.no>
  • Cc: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: Re: [XOM-interest] dtd problems
  • Date: Mon, 20 Sep 2004 10:33:40 -0400

luca wrote:



mmmm, I don't get it. How hard could it be to have

Builder builder = new Builder();
builder.ignoreDtdNoMatterWhat();


But what do you do when you then encounter an entity reference to an entity whose replacement text is not available?

I really think it's safer (if not necessarily faster) to always read the external DTD subset. I wrote about this in Item 18 of Effective XML, which if somebody asks nicely I may put online, but here's the relevant part:

Consumers cannot assume that documents are self-contained. In the spirit of being liberal in what you accept but conservative in what you produce, when receiving a document from a third party you should do your utmost to read the external DTD subset, resolve all external entity references, and apply all default attribute values. You should only use parsers that can do this, especially for DTDs. While most APIs allow you to turn off resolution of external entity references and ignore the external DTD subset, you should almost never do so. Reading the external DTD subset will cost you little in the case where it isn’t necessary and may save your bacon in the case where it is. Programs that repeatedly read the same external DTD subsets can use the public identifiers, catalogs, and various caching strategies to cache the DTDs so repeated trips back to a server are not necessary. (See Item 47.)

This is especially useful with web browsers and XHTML, and indeed it’s sanctioned by the XHTML specification. Web browsers that support XHTML have, for practical intents and purposes, internally cached the XHTML DTD. Thus when they encounter a document whose public ID labels it as XHTML, they do not need to read the DTD. They already know how to resolve entity references like &Theta; and &alpha;. However, this option is not available to a general purpose XML parser that does not know which specific XML applications it will encounter. Such a processor must read the external DTD subset before it can confidently replace all entities.

--
Elliotte Rusty Harold
elharo AT metalab.unc.edu




Archive powered by MHonArc 2.6.24.

Top of Page