Frequently Asked Questions

Why is Delphi complaining about missing packages after installing SAX for Pascal?

When Delphi compiles a package, it turns it into a special kind of DLL. Therefore, the same rules for locating DLLs apply to compiled packages. So, if you put a compiled package into a directory that is on your PATH, Delphi should be able to load the package.

A more convenient solution is provided by Delphi's library path. This is similar to your system's PATH environment variable, but specific to Delphi. You can set this on the Library tab of the Environment options dialog (select Environment options... from the Tools menu).

Why do I sometimes see question marks or strange looking characters when displaying the data reported by a SAX parser?

XML is based on Unicode, that is, XML documents can contain over a million different characters, for all major languages in the world. The VCL controls in a Delphi application are only capable of displaying the characters of the current Windows codepage, other characters are replaced with a question mark or small box. However, CLX controls should be capable of displaying Unicode characters. For both types of controls it is obviously necessary that the chosen font implements glyphs for all characters to be displayed.

More information can be found in Unicode in XML and other Markup Languages.

Note that the SAX for Pascal packages contain some conditional defines to facilitate handling different sorts of characters.

Why are sometimes not all characters returned in the OnCharacters event?

The way that SAX handles large files usually is by chunking the data. This means that you may get multiple characters callbacks for a single element. The trick is to buffer the character content. The easiest way to do this is to handle the OnStartElement event and do something like FCharBuffer := '';, where FCharBuffer is a SAXString. Then in the OnCharacters event, do FCharBuffer := FCharBuffer + ch;. And, finally, in the OnEndElement you can use FCharBuffer as you please.

You may need to maintain a stack of buffers if you have to buffer elements in elements with mixed content.

More questions...

More information can be found in the SAX FAQ.