The DocumentBuilder class from the basic usage tutorial is an example of a ContentHandler. It builds DOM-like tree based on the events it gets sent. We passed an instance of it to the XmlFileReader. All the XmlFileReader did was call the corresponding ContentHandler methods for each node and attribute it encountered in the document. So, for the following file:
<customers> <customer> <company>Al Bundy's shoes</company> <address>No hope lane 34</address> <phone>55528974637</phone> </customer> </customers>the XmlFileReader does the following:
// The content handler variable is the DocumentBuilder we passed to the XmlFileReader contentHandler->startDocument(); contentHandler->startNode("customer"); contentHandler->writeNode("company", "Al Bundy's shoes"); contentHandler->writeNode("address", "No hope lane 34"); contentHandler->writeNode("phone", "55528974637"); contentHandler->endNode(); contentHandler->endDocument();
File readers for other formats work roughly the same way. The exact way they treat files is (or will be) documented in the API for the corresponding classes.
To summerize, file readers take ContentHandlers which could do virtually anything you want. You can link a reader directly to a writer to convert between different formats. You can use ContentHandlers directly to write your own data into a file and you could even chain ContentHandlers if you want for complex processing of data or on the fly conversions (which we'll do in the next tutorial).
For more examples, look through through the Tests directory and the SDX sources (don't be afraid, it is well organized ;)). Also, an interesting class to look at is the ContentPrinter. With it, you can observe what classes send to ContentHanders you pass them.