2016-07-09 02:18:40 +00:00
|
|
|
#include "ReadXML.h"
|
|
|
|
#include "Base.h"
|
2019-03-17 23:50:56 +00:00
|
|
|
#include <sstream>
|
2016-07-09 02:18:40 +00:00
|
|
|
|
|
|
|
tinyxml2::XMLError readXML(const std::string& fn, tinyxml2::XMLDocument& doc)
|
|
|
|
{
|
|
|
|
unsigned long sz = 0;
|
|
|
|
char *buf = readFile(fn, &sz);
|
|
|
|
tinyxml2::XMLError err = doc.Parse(buf, sz);
|
|
|
|
delete [] buf;
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
tinyxml2::XMLDocument *readXML(const std::string& fn, tinyxml2::XMLError *perr /* = 0 */, bool keepEmpty /* = false */)
|
|
|
|
{
|
|
|
|
tinyxml2::XMLDocument *doc = new tinyxml2::XMLDocument();
|
|
|
|
tinyxml2::XMLError err = readXML(fn, *doc);
|
|
|
|
if(perr)
|
|
|
|
*perr = err;
|
|
|
|
if(err != tinyxml2::XML_SUCCESS && !keepEmpty)
|
|
|
|
{
|
2019-03-17 23:50:56 +00:00
|
|
|
const char *e1 = doc->GetErrorStr1();
|
|
|
|
const char *e2 = doc->GetErrorStr2();
|
|
|
|
std::ostringstream os;
|
|
|
|
os << "readXML(" << fn << ") failed!\n";
|
|
|
|
if(e1)
|
|
|
|
os << e1 << "\n";
|
|
|
|
if(e2)
|
|
|
|
os << e2 << "\n";
|
|
|
|
errorLog(os.str());
|
2016-07-09 02:18:40 +00:00
|
|
|
delete doc;
|
|
|
|
doc = NULL;
|
|
|
|
}
|
|
|
|
return doc;
|
|
|
|
}
|