#include "HXmlReport.h" #include HXmlReport::HXmlReport() { HXmlElement* psXmlElement = new HXmlElement("ModelFile"); m_apPath.push_back(psXmlElement); m_sDocument.LinkEndChild(psXmlElement); } HXmlReport::~HXmlReport() { } void HXmlReport::SaveFile(const char* pcReportPath, const char* pcXslFile) { m_sDocument.SetCondenseWhiteSpace(false); if (pcXslFile) { // stylesheet metadata are not supported by tinyXML // => we have to add xsl link manually at the beginning of the xml file // Instead of directly write into file, plug a printer to XML document, to "write" xml in a std::string TiXmlPrinter printer; printer.SetIndent("\t"); m_sDocument.Accept(&printer); // Write xst information + printer string into file std::ofstream ofs; ofs.open(pcReportPath, std::ofstream::out); ofs << "" << std::endl; ofs << "" << std::endl; ofs << printer.CStr(); ofs.close(); } else { if (m_sDocument.SaveFile(pcReportPath)) fprintf(stdout, "XML file saved as %s\n", pcReportPath); else fprintf(stdout, "Cannot create XML file %s\n", pcReportPath); fflush(stdout); } } void HXmlReport::closeSubNode() { if (m_apPath.empty()) { //can remove root note return; } m_apPath.pop_back(); } void HXmlReport::addNode(HXmlElement* psNewNode) { if(psNewNode == NULL) return; if (m_apPath.empty()) { //no tree create return; } m_apPath.back()->LinkEndChild(psNewNode); } void HXmlReport::createSubNode(const char* pcNameNode) { HXmlElement*psNewNode = new HXmlElement(pcNameNode); if (psNewNode == NULL) return; if (m_apPath.empty()) { //no tree create return; } m_apPath.back()->LinkEndChild(psNewNode); m_apPath.push_back(psNewNode); }