Saving and Caching a DOMIT Document

To save a DOMIT_Document as an XML text file, you can use the saveXML method:

$success =& $cdCollection->saveXML("/xml/cdcollection.xml");

true or false will be returned, depending on the success of the save operation.

saveXML has a second parameter which, when set to true, will save the xml representation using toNormalizedString:

$success =& $cdCollection->saveXML("/xml/cdcollection.xml", true);

saveXML_utf8

saveXML also has a UTF-8 compliant counterpart, saveXML_utf8, which will save the xml representation in UTF-8 encoded format:

As with loadXML_utf8 and saveXML_utf8, there are several preconditions to using these methods:

  • Your xml must use ISO-8859-1 encoding. Any other encoding, including UTF-8 encoding, will likely produce corrupted text.
  • Expat must be included in your PHP distribution, since these functions use Expat's UTF8_encode function.

For these reasons, it is no longer recommended that these methods be used. Refer instead to the appendEntityTranslationTable method.

If you still want to use these methods, here is an example:

$success =& $cdCollection->saveXML_utf8("/xml/cdcollection.xml");

DOMIT_Cache

An experimental class has been added that will allow you to to cache a DOMIT_Document for quick retrieval.

Caching is performed using the DOMIT_Cache class. An xml document passed to this class is serialized and saved as a .dch (DOMIT! Cache) file in the same directory as the .xml text file:

DOMIT_cache::toCache("myxmlfile.xml", $xmldoc);

To reload the document from its cache, use the fromCache method:

$xmldoc =& DOMIT_cache::fromCache("myxmlfile.xml");

Warning! This class is experimental! It does not do safety checking of any sort. There is no file locking, expiry mechanism, and the class does not ensure that the cached file is not based on an old version of DOMIT!

Please use at your own risk, and send any bug reports to me if you find anything wrong! A more robust caching mechanism is being worked on and may be available soon.


Documentation generated by ClassyDoc, using the DOMIT! and SAXY parsers.
Please visit Engage Interactive to download free copies.