report SAX events in a single relation v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Fri, 11 Jan 2019 12:04:45 +0100
branchv_0
changeset 4 1363ec0879ca
parent 3 4b566dee1a57
child 5 e5cf88ce91ac
report SAX events in a single relation
src/XMLCommand.h
src/relpipe-in-xml.cpp
--- a/src/XMLCommand.h	Fri Jan 11 01:13:40 2019 +0100
+++ b/src/XMLCommand.h	Fri Jan 11 12:04:45 2019 +0100
@@ -51,32 +51,33 @@
 		RelpipeSaxHandler(std::ostream& output) : DefaultHandler(), writer(Factory::create(output)) {
 		}
 
-		void startElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname, const Attributes& attrs) override {
+		void startDocument() override {
 			//XMLString::
 			// TODO: remove demo
-			writer->startRelation(L"xml_startElement",{
-				{L"s", TypeId::STRING},
+			writer->startRelation(L"xml",{
+				{L"event", TypeId::STRING},
+				{L"data", TypeId::STRING},
 			}, true);
+		}
 
-			writer->writeAttribute(L"a");
+		void startElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname, const Attributes& attrs) override {
+			writer->writeAttribute(L"startElement");
+			writer->writeAttribute(L"");
 		}
 
 		void endElement(const XMLCh * const uri, const XMLCh * const localname, const XMLCh * const qname) override {
-			// TODO: remove demo
-			writer->startRelation(L"xml_endElement",{
-				{L"s", TypeId::STRING},
-			}, true);
+			writer->writeAttribute(L"endElement");
+			writer->writeAttribute(L"");
+		}
 
-			writer->writeAttribute(L"a");
+		void characters(const XMLCh * const chars, const XMLSize_t length) override {
+			writer->writeAttribute(L"characters");
+			writer->writeAttribute(to_wstring(length));
 		}
 
 		void endDocument() override {
-			// TODO: remove demo
-			writer->startRelation(L"xml_endDocument",{
-				{L"s", TypeId::STRING},
-			}, true);
-
-			writer->writeAttribute(L"a");
+			writer->writeAttribute(L"endDocument");
+			writer->writeAttribute(L"");
 		}
 
 	};
--- a/src/relpipe-in-xml.cpp	Fri Jan 11 01:13:40 2019 +0100
+++ b/src/relpipe-in-xml.cpp	Fri Jan 11 12:04:45 2019 +0100
@@ -56,6 +56,12 @@
 		fwprintf(stderr, L"Caught xercesc::XMLException\n");
 		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
 		resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
+	} catch (const xercesc::SAXParseException& e) {
+		// TODO: print message
+		// char* message = xercesc::XMLString::transcode(e.getMessage());
+		fwprintf(stderr, L"Caught xercesc::SAXParseException\n");
+		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
+		resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
 	}
 
 	return resultCode;