Problems when loading XML

A load will not work if the document contains a DTD / Schema definition where the validation file cannot be found!

Ex. a XML containing the following will not be able to be loaded because the DTD does not use a URI path.

<!DOCTYPE TXP SYSTEM “example.dtd”>

Uniform Ressource Identifier (URI) Ex. “http://mysite.com/ex.dtd”

A load can be done any way by ignoring parsing errors ;-)

XMLDoc.validateOnParse := FALSE;
XMLDoc.resolveExternals := FALSE;

Loading a XML document with a DTD / Schema is possible if the DTD / XSD file is placed in the same directory as the XML file.

Luckily load errors can be captured!

validateOnParse and resolveExternals must be enabled when loading the document (they are by default true)

XMLDoc.validateOnParse := TRUE;
XMLDoc.resolveExternals := TRUE;
XMLDoc.load(FileName);

Parse Errors can be saved in a variable (Microsoft XML IXMLDOMParseError)

XMLErr := XMLDoc.parseError;

XMLErr can return a error code and a reason description

Message('Error: %1 %2',XMLErr.errorCode,XMLErr.reason);

Error: -1072898028
Element content is invalid according to the DTD/Schema

You can leave a response, or trackback from your own site.

Leave a Reply


four × 7 =