diff -r c043377a757f -r 82ba555a97d1 src/XmlHandler.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/XmlHandler.h Sun Sep 16 14:39:10 2018 +0200 @@ -0,0 +1,86 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace relpipe { +namespace out { +namespace tabular { + +using namespace relpipe::reader; + +class XmlHandler : public handlers::RelationalReaderStringHadler { +private: + std::wstring_convert> convertor; // XML output will be always in UTF-8 + const char* INDENT = "\t"; + + std::ostream &output; + + std::vector columnTypes; + std::vector columnTypeCodes; + std::vector columnNames; + std::vector columnWidths; + std::vector values; // all values are saved here and processed at the end of the relation + integer_t columnCount = 0; + + + + const string_t escapeXmlText(const string_t &value, const char* color) { + std::wstringstream result; + + for (auto & ch : value) { + switch (ch) { + // FIXME: xml escaping + case L'&': result << L"&"; + break; + default: result << ch; + } + } + + return result.str(); + } + +public: + + XmlHandler(std::ostream& output) : output(output) { + } + + void startRelation(string_t name, std::vector attributes) override { + output << convertor.to_bytes(name) << ": (XML)" << endl; + columnCount = attributes.size(); + columnTypes.resize(columnCount); + columnTypeCodes.resize(columnCount); + columnNames.resize(columnCount); + columnWidths.resize(columnCount, 0); + for (int i = 0; i < attributes.size(); i++) { + columnNames[i] = attributes[i].getAttributeName(); + columnTypes[i] = attributes[i].getTypeId(); + columnTypeCodes[i] = attributes[i].getTypeName(); + } + } + + void attribute(const string_t& value) override { + integer_t i = values.size() % columnCount; + values.push_back(value); + columnWidths[i] = max(columnWidths[i], value.length()); + } + + void endOfPipe() { + + } + +}; + +} +} +}