In the implementation of XML parser, the implementation of DTD is quite troublesome. The trouble lies not in the logic of the DTD, but in how to process the external entity of the DTD, for example, the mutual calls between the DTD files.
For example, the following DTD declaration:
<! Entity imported-File System "imported-file">
% Imported-file;
In the above two DTD statements, a parameterized external entity is first declared, and then the external entity is referenced to import the DTD file as part of the entire DTD. So what should I do when XML Parser encounters such a DTD declaration?
One solution is not to parse the entity content, but simply as an external entity and pass it to the application.ProgramProcessing. This solution is the simplest. The problem is that the imported file is a logical part of the DTD, where element and ATTLIST may be declared. If this file is not parse, The DTD validate will fail.
The second solution is to try parse the external entity. OK. If the external entity indicates that it is indeed a DTD file, there is no problem, but if the object pointed to by the entity is only a simple text file, but it is not a valid DTD file, so errors may occur. This Parse error can be processed in real time, and several other problems should be prevented, such as circular references between files. The most troublesome thing is that users may not want to take the file corresponding to the entity as a part of the DTD. When the XML file does not comply with the DTD verification, and the file contains a correct DTD declaration, it may cause the invalidity of the DTD validate. This should have reported an error. Now it has become the correct XML file.
Of course, the correct method is to send a message to the user each time the external entity statement is found, and the user specifies a specific action. In this case, the interface is troublesome when XML parser is used. You must specify an entity action for parser before starting parse.
Take the XML file of OpenOffice as an example.. Net XML Parser and xerces C ++ for parse, without specifying any entity handler ,.. Net parser. xerces C ++ reports an error. The error is the Validation Part Of The DTD. It can be seen that the two parser have significant differences in the processing of the external DTD. In addition, xmlspy 2004 can also be properly verified.