Implementation strategy about External Entity in XML DTD check.

xiaoxiao2021-03-05  23

In the implementation of XML Parser, the implementation of DTD is a more troublesome place. The trouble is not the logical part of the DTD, but how to handle the external Entity of DTD, such as mutual calls between DTD files.

For example, the following DTD declaration:

% Imported-file;

The above two DTD statements, first declare a parameterized External Entity, follow the External Entity, indicating that the imported DTD file is part of the entire DTD. So, what should I deal with when XML Parser encounters this DTD declaration?

One solution is that it does not go to the content of PARSE, but simply as an external entity, pass it to the application processing. This scheme is the most simpler, the problem is the imported file logic is an integral part of the DTD, which may declare Element, Attlist, etc., not PARSE This file will cause DTD Validate to fail.

The second solution is that attempts to put the external entity. OK, if the external entity is indeed a DTD file, there is no problem, but if the object points to the Entity is just a simple text file, it is not a valid The DTD file is likely to generate an error. This PARSE error can be handled instantly, but also to prevent other problems, such as loop references between files. Most trouble is that there is a possibility that the user does not want the file corresponding to the Entity as part of the DTD. When the XML file does not match the DTD check, the file is like a correct DTD declaration, it is possible to cause invalidation of DTD Validate. This should have an error, and now it has become the correct XML file.

Of course, the correct approach is that each time I find the declaration of External Entity, send it to the user, specifies a specific action by the user. When this scheme is troublesome, the interface is more troublesome when using XML Parser, and must first specify an Entity action for Parser first, and then start PARSE.

I use the OpenOffice XML file as an example, using .NET's XML Parser and Xerces C for PARSE, no problem in .NET Parser without specifying any Entity Handler, and Xerces C will report. The wrong place is the DTD's calibration section. It can be seen that these two Parser have significant differences in the Handling of External DTD. In addition, XMLSPY 2004 can also verify normally.

转载请注明原文地址:https://www.9cbs.com/read-34796.html

New Post(0)