diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 18:42:24 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-24 18:42:24 +0000 |
commit | f508189682b6fba62e08feeb1596f682bad5fff9 (patch) | |
tree | 28aeb0e6c19386c385c1ce5edf8a92c1bca15281 /src/devices/pic/xml_data/validate | |
download | piklab-f508189682b6fba62e08feeb1596f682bad5fff9.tar.gz piklab-f508189682b6fba62e08feeb1596f682bad5fff9.zip |
Added KDE3 version of PikLab
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/piklab@1095639 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/devices/pic/xml_data/validate')
-rw-r--r-- | src/devices/pic/xml_data/validate/Makefile | 4 | ||||
-rw-r--r-- | src/devices/pic/xml_data/validate/validate.cpp | 72 |
2 files changed, 76 insertions, 0 deletions
diff --git a/src/devices/pic/xml_data/validate/Makefile b/src/devices/pic/xml_data/validate/Makefile new file mode 100644 index 0000000..d235259 --- /dev/null +++ b/src/devices/pic/xml_data/validate/Makefile @@ -0,0 +1,4 @@ +all: validate + +validate: validate.cpp + g++ -o validate -lxerces-c validate.cpp diff --git a/src/devices/pic/xml_data/validate/validate.cpp b/src/devices/pic/xml_data/validate/validate.cpp new file mode 100644 index 0000000..7e733b0 --- /dev/null +++ b/src/devices/pic/xml_data/validate/validate.cpp @@ -0,0 +1,72 @@ +// Necessary includes. We refer to these as "common includes" +// in the following examples. +#include <xercesc/sax2/XMLReaderFactory.hpp> +#include <xercesc/sax2/SAX2XMLReader.hpp> +#include <xercesc/sax2/DefaultHandler.hpp> + +// Handy definitions of constants. +#include <xercesc/util/XMLUni.hpp> + +#include <iostream> + +using namespace std; +XERCES_CPP_NAMESPACE_USE + +class Handler : public DefaultHandler +{ +public: + virtual void error (const SAXParseException &exc) { + char* message = XMLString::transcode(exc.getMessage()); + cout << "Exception: " << message << "\n"; + XMLString::release(&message); + } + virtual void fatalError (const SAXParseException &exc) { + char* message = XMLString::transcode(exc.getMessage()); + cout << "Exception: " << message << "\n"; + XMLString::release(&message); + } +}; + +int main(int argc, char* argv[]) +{ +XMLPlatformUtils::Initialize(); + +// Create a SAX2 parser object. +SAX2XMLReader* parser = XMLReaderFactory::createXMLReader(); + +// Set the appropriate features on the parser. +// Enable namespaces, schema validation, and the checking +// of all Schema constraints. +// We refer to these as "common features" in following examples. +parser->setFeature(XMLUni::fgSAX2CoreNameSpaces, true); +parser->setFeature(XMLUni::fgSAX2CoreValidation, true); +parser->setFeature(XMLUni::fgXercesDynamic, false); +parser->setFeature(XMLUni::fgXercesSchema, true); +parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true); +//parser->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation, (void *)"pic.xsd"); + +// Set appropriate ContentHandler, ErrorHandler, and EntityResolver. +// These will be referred to as "common handlers" in subsequent examples. + +// You will use a default handler provided by Xerces-C++ (no op action). +// Users should write their own handlers and install them. +Handler handler; +parser->setContentHandler(&handler); + +// The object parser calls when it detects violations of the schema. +parser->setErrorHandler(&handler); + +// The object parser calls to find the schema and +// resolve schema imports/includes. +parser->setEntityResolver(&handler); + +// Parse the XML document. +// Document content sent to registered ContentHandler instance. +if ( argc==1 ) { printf("Needs one argument\n"); return -1; } +parser->parse(argv[1]); + +// Delete the parser instance. +delete parser; + +return 0; +} |