Init
This commit is contained in:
84
exchange/exchangesource/DumpFeatureTree/HXmlReport.cpp
Normal file
84
exchange/exchangesource/DumpFeatureTree/HXmlReport.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
#include "HXmlReport.h"
|
||||
|
||||
#include <fstream>
|
||||
|
||||
HXmlReport::HXmlReport()
|
||||
{
|
||||
HXmlElement* psXmlElement = new HXmlElement("Root");
|
||||
m_apPath.push_back(psXmlElement);
|
||||
psXmlElement->SetAttribute("rel", "stylesheet");
|
||||
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;
|
||||
m_sDocument.Accept(&printer);
|
||||
|
||||
// Write xst information + printer string into file
|
||||
std::ofstream ofs;
|
||||
ofs.open(pcReportPath, std::ofstream::out);
|
||||
ofs << "<?xml version=\"1.0\"?>" << std::endl;
|
||||
ofs << "<?xml-stylesheet href=\"" << pcXslFile << "\" type=\"text/xsl\"?>" << 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);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user