Kbase P95901: How to parse an XML document using SAX parser when the DTD is not available
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  5/27/2010 |
|
Status: Verified
GOAL:
How to parse an XML document using SAX parser when the DTD is not available
GOAL:
How to use a different DTD file when parsing a document with the SAX parser
GOAL:
How to overwrite the DTD location specified in the XML document when using SAX parser
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
FIX:
Even if the value of the VALIDATION-ENABLED parameter is NO, the SAX parser reads any specified DTD (internal or external) in order to get information on entities. If SAX parser cannot find the DTD file specified in the XML document, it will return an error:
(Error: SAX-PARSE-NEXT, Unexpected error)
To avoid this, use the ResolveEntity callback procedure to override the XML DTD file with a local one. If VALIDATION-ENABLED is set to NO, so that the SAX parser is not doing any validations, then the local DTD can be just an empty file.
/*------------------------------------*/
PROCEDURE ResolveEntity:
DEFINE INPUT PARAMETER publicID AS CHARACTER.
DEFINE INPUT PARAMETER systemID AS CHARACTER.
DEFINE OUTPUT PARAMETER filePath AS CHARACTER.
DEFINE OUTPUT PARAMETER memPointer AS MEMPTR.
filePath = 'myDefault.dtd'.
END.
/*------------------------------------*/
In the above example, "myDefault.dtd" represents an existing file in the Progress working directory.
To specify the new DTD location, an absolute path, a relative path or an HTTP URL can be used.