This module provides the Qgar library user with a SAX parser to process XML documents. It does not directly implement the parser, but rather offers a set of interfaces and wrappers allowing to plug any external SAX parser.
The choice of the parser implementation depends on the configuration options set when building the library. It is completely invisible to the user. The user creates a parser with the qgxml::XMLReaderFactory factory class and registers call back functions using the appropriate interfaces.
For more information about SAX parsers, see the documentation to the orginal SAX parser at www.saxproject.org.
Here is a basic example of the way to use this module.
// STL #include <fstream> #include <iostream> // QGAR #include <sax/Attributes.H> #include <sax/DefaultHandler.H> #include <sax/InputSource.H> #include <sax/XMLReaderFactory.H> #include <sax/XMLReader.H> using namespace qgxml; using namespace std; // The class handling the parsing events. class MyHandler : public DefaultHandler { // Method called by the parser every time beginning tag is found. // The local name of the tag is printed. void startElement(const std::string& uri, const std::string& localName, const std::string& qName, const Attributes& atts) { cout << "Found tag: " << localName << endl; } }; int main(int argc, char **argv) { // Create input source from file ifstream stream(argv[1]); InputSource source(stream); // Create XML reader. XMLReader * reader = XMLReaderFactory::createXMLReader(); // Register our own content handler MyHandler * handler = new MyHandler(); reader->setContentHandler(handler); try { reader->parse(source); } catch(...) { cout << "Error while parsing document" << endl; } delete handler; delete reader; }
Classes | |
| class | qgxml::Attributes |
| Interface for a list of XML attributes. More... | |
| class | qgxml::ContentHandler |
| Receive notification of the logical content of a document. More... | |
| class | qgxml::DefaultHandler |
| Default base class for SAX2 event handlers. More... | |
| class | qgxml::DTDHandler |
| Receive notification of basic DTD-related events. More... | |
| class | qgxml::EntityResolver |
| Basic interface for resolving entities. More... | |
| class | qgxml::ErrorHandler |
| Basic interface for SAX error handlers. More... | |
| class | qgxml::InputSource |
| A single input source for an XML entity. More... | |
| class | qgxml::Locator |
| Interface for associating a SAX event with a document location. More... | |
| class | qgxml::SAXException |
| Encapsulate a general SAX error or warning. More... | |
| class | qgxml::SAXParseException |
| Encapsulate an XML parse error or warning. More... | |
| class | qgxml::XMLReader |
| Interface for reading an XML document using callbacks. More... | |
| class | qgxml::XMLReaderFactory |
| Factory for creating an XML reader. More... | |