/* * XMLWriter.cc * * Created on: 7 août 2013 * Author: CS */ #include "XMLWriter.hh" #include #include namespace TimeTableCatalog { XMLWriter::XMLWriter(const std::string& pPath, const std::string& pName) : AbstractWriter(pPath, pName) { } XMLWriter::~XMLWriter() { } // ----------------- PUBLIC -------------------------- std::string XMLWriter::write(const TimeTable& pTT, const char* pEncoding) { /* * this initialize the library and check potential ABI mismatches * between the version it was compiled for and the actual shared * library used. */ LIBXML_TEST_VERSION xmlTextWriterPtr writer; // -- create a new XmlWriter for uri, with no compression. std::string filePath = getFile(pTT); writer = xmlNewTextWriterFilename(filePath.c_str(), 0); if (writer == NULL) { LOG4CXX_WARN(logger, "Error creating the xml writer"); return ""; } // -- write input(out, &out_size, (const xmlChar *) in, &temp); if ((ret < 0) || (temp - size + 1)) { if (ret < 0) { LOG4CXX_WARN(logger, "Error while converting : converting failed for " + getFile(pTT)); } else { std::ostringstream os; os << temp; LOG4CXX_WARN(logger, "Error while converting : converting failed (" + os.str() + " octets) for " + getFile(pTT)); } xmlFree(out); out = 0; } else { out = (unsigned char *) xmlRealloc(out, out_size + 1); out[out_size] = 0; /*null terminating out */ } } else { LOG4CXX_WARN(logger, "Error while converting : no mem for " + getFile(pTT)); } return out; } void XMLWriter::logEndTagError(const std::string& pTag, const std::string& pTTPath) { LOG4CXX_WARN(logger, "Error while writing end of " + pTag + " element for " + pTTPath); } void XMLWriter::logStartTagError(const std::string& pTag, const std::string& pTTPath) { LOG4CXX_WARN(logger, "Error while writing start of " + pTag + "element for " + pTTPath); } void XMLWriter::logTagError(const std::string& pTag, const std::string& pTTPath) { LOG4CXX_WARN(logger, "Error while writing tag " + pTag + "element for " + pTTPath); } void XMLWriter::logAttributeError(const std::string& pAttribute, const std::string& pTTPath) { LOG4CXX_WARN(logger, "Error while writing attribute " + pAttribute + "element for " + pTTPath); } } /* namespace TimeTableCatalog */