[xml] DTDs


I have a general question about DTDs (which also applies to Schemas) :
as a program developer, validating an XML file against a DTD gives me
the assurance that the XML file follows a certain layout, and that I
don't have to check for any special cases or missing elements. Instead,
I can just go ahead and use the data in the XML file.

So my question : why then is the DTD or the reference to the external
DTD specified inside the XML file ? I certainly don't want let the
author of the XML file change the DTD. In my understanding, the DTD,
which the XML file is validated against, should be hardcoded / compiled
into the program that reads the XML file.

This is how I handle it now: I require an external DTD declaration in
the XML file. I also register an external entity loader with libxml2,
which checks for the specifiy id/url, and provides the DTD from memory.
Once loaded, I check the parse tree to make sure that indeed this
external DTD declaration has been specified, and with the correct URL /
id. Finally I have libxml2 validate the XML file. 

Any comments on this procedure ?



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]