mirror of
https://github.com/glest/glest-source.git
synced 2025-08-12 11:24:00 +02:00
- no need for xerces anymore? All XML is now done by rapidxml by default (loading and saving)
This commit is contained in:
@@ -3436,7 +3436,8 @@ void Game::toggleTeamColorMarker() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::saveGame(string name) {
|
void Game::saveGame(string name) {
|
||||||
XmlTree xmlTree(XML_XERCES_ENGINE);
|
//XmlTree xmlTree(XML_XERCES_ENGINE);
|
||||||
|
XmlTree xmlTree;
|
||||||
xmlTree.init("megaglest-saved-game");
|
xmlTree.init("megaglest-saved-game");
|
||||||
XmlNode *rootNode = xmlTree.getRootNode();
|
XmlNode *rootNode = xmlTree.getRootNode();
|
||||||
|
|
||||||
|
@@ -70,7 +70,7 @@ public:
|
|||||||
class XmlIoRapid {
|
class XmlIoRapid {
|
||||||
private:
|
private:
|
||||||
static bool initialized;
|
static bool initialized;
|
||||||
rapidxml::xml_document<> *doc;
|
xml_document<> *doc;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
XmlIoRapid();
|
XmlIoRapid();
|
||||||
@@ -153,6 +153,7 @@ public:
|
|||||||
XmlAttribute *addAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues);
|
XmlAttribute *addAttribute(const string &name, const string &value, std::map<string,string> mapTagReplacementValues);
|
||||||
|
|
||||||
XERCES_CPP_NAMESPACE::DOMElement *buildElement(XERCES_CPP_NAMESPACE::DOMDocument *document) const;
|
XERCES_CPP_NAMESPACE::DOMElement *buildElement(XERCES_CPP_NAMESPACE::DOMDocument *document) const;
|
||||||
|
xml_node<>* buildElement(xml_document<> *document) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
string getTreeString() const;
|
string getTreeString() const;
|
||||||
|
@@ -27,6 +27,7 @@
|
|||||||
#include "platform_util.h"
|
#include "platform_util.h"
|
||||||
#include "cache_manager.h"
|
#include "cache_manager.h"
|
||||||
|
|
||||||
|
#include "rapidxml_print.hpp"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
XERCES_CPP_NAMESPACE_USE
|
XERCES_CPP_NAMESPACE_USE
|
||||||
@@ -236,7 +237,7 @@ XmlIoRapid::XmlIoRapid() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
doc = new rapidxml::xml_document<>();
|
doc = new xml_document<>();
|
||||||
}
|
}
|
||||||
catch(const DOMException &ex) {
|
catch(const DOMException &ex) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while creating XML parser, msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.getMessage());
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while creating XML parser, msg: %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.getMessage());
|
||||||
@@ -318,48 +319,66 @@ XmlNode *XmlIoRapid::load(const string &path, std::map<string,string> mapTagRepl
|
|||||||
}
|
}
|
||||||
|
|
||||||
void XmlIoRapid::save(const string &path, const XmlNode *node){
|
void XmlIoRapid::save(const string &path, const XmlNode *node){
|
||||||
// try{
|
try {
|
||||||
// XMLCh str[strSize];
|
xml_document<> doc;
|
||||||
// XMLString::transcode(node->getName().c_str(), str, strSize-1);
|
|
||||||
|
// xml declaration
|
||||||
|
xml_node<>* decl = doc.allocate_node(node_declaration);
|
||||||
|
decl->append_attribute(doc.allocate_attribute(doc.allocate_string("version"), doc.allocate_string("1.0")));
|
||||||
|
decl->append_attribute(doc.allocate_attribute(doc.allocate_string("encoding"), doc.allocate_string("utf-8")));
|
||||||
|
decl->append_attribute(doc.allocate_attribute(doc.allocate_string("standalone"), doc.allocate_string("no")));
|
||||||
|
doc.append_node(decl);
|
||||||
|
|
||||||
|
// root node
|
||||||
|
xml_node<>* root = doc.allocate_node(node_element, doc.allocate_string(node->getName().c_str()));
|
||||||
|
for(unsigned int i = 0; i < node->getAttributeCount() ; ++i){
|
||||||
|
XmlAttribute *attr = node->getAttribute(i);
|
||||||
|
root->append_attribute(doc.allocate_attribute(
|
||||||
|
doc.allocate_string(attr->getName().c_str()),
|
||||||
|
doc.allocate_string(attr->getValue("",false).c_str())));
|
||||||
|
}
|
||||||
|
doc.append_node(root);
|
||||||
|
|
||||||
|
// child nodes
|
||||||
|
for(unsigned int i = 0; i < node->getChildCount(); ++i) {
|
||||||
|
root->append_node(node->getChild(i)->buildElement(&doc));
|
||||||
|
}
|
||||||
|
|
||||||
|
// std::string xml_as_string;
|
||||||
|
// // watch for name collisions here, print() is a very common function name!
|
||||||
|
// print(std::back_inserter(xml_as_string), doc);
|
||||||
|
// // xml_as_string now contains the XML in string form, indented
|
||||||
|
// // (in all its angle bracket glory)
|
||||||
//
|
//
|
||||||
// XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *document= implementation->createDocument(0, str, 0);
|
// std::string xml_no_indent;
|
||||||
// DOMElement *documentElement= document->getDocumentElement();
|
// // print_no_indenting is the only flag that print() knows about
|
||||||
// for(unsigned int i = 0; i < node->getAttributeCount() ; ++i){
|
// print(std::back_inserter(xml_no_indent), doc, print_no_indenting);
|
||||||
// XmlAttribute *attr = node->getAttribute(i);
|
// // xml_no_indent now contains non-indented XML
|
||||||
//
|
|
||||||
// XMLCh strName[strSize];
|
#if defined(WIN32) && !defined(__MINGW32__)
|
||||||
// XMLString::transcode(attr->getName().c_str(), strName, strSize-1);
|
FILE *fp = _wfopen(utf8_decode(path).c_str(), L"wt");
|
||||||
// XMLCh strValue[strSize];
|
ofstream xmlFile(fp);
|
||||||
// XMLString::transcode(attr->getValue("",false).c_str(), strValue, strSize-1);
|
#else
|
||||||
//
|
ofstream xmlFile(path.c_str());
|
||||||
// documentElement->setAttribute(strName,strValue);
|
#endif
|
||||||
// }
|
if(xmlFile.is_open() == false) {
|
||||||
//
|
throw runtime_error("Can not open file: [" + path + "]");
|
||||||
// for(unsigned int i=0; i<node->getChildCount(); ++i){
|
}
|
||||||
// documentElement->appendChild(node->getChild(i)->buildElement(document));
|
|
||||||
// }
|
//xmlFile << xml_no_indent;
|
||||||
//
|
// xmlFile << xml_as_string << '\0';
|
||||||
// LocalFileFormatTarget file(path.c_str());
|
xmlFile << doc << '\0';
|
||||||
//#if XERCES_VERSION_MAJOR < 3
|
|
||||||
// DOMWriter* writer = implementation->createDOMWriter();
|
#if defined(WIN32) && !defined(__MINGW32__)
|
||||||
// writer->setFeature(XMLUni::fgDOMWRTFormatPrettyPrint, true);
|
if(fp) {
|
||||||
// writer->writeNode(&file, *document);
|
fclose(fp);
|
||||||
//#else
|
}
|
||||||
// DOMLSSerializer *serializer = implementation->createLSSerializer();
|
#endif
|
||||||
// DOMLSOutput* output=implementation->createLSOutput();
|
}
|
||||||
// DOMConfiguration* config=serializer->getDomConfig();
|
catch(const exception &e){
|
||||||
// config->setParameter(XMLUni::fgDOMWRTFormatPrettyPrint,true);
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while saving: [%s], %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),e.what());
|
||||||
// output->setByteStream(&file);
|
throw runtime_error("Exception while saving [" + path + "] msg: " + e.what());
|
||||||
// serializer->write(document,output);
|
}
|
||||||
// output->release();
|
|
||||||
// serializer->release();
|
|
||||||
//#endif
|
|
||||||
// document->release();
|
|
||||||
// }
|
|
||||||
// catch(const DOMException &e){
|
|
||||||
// SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Exception while saving: [%s], %s\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,path.c_str(),XMLString::transcode(e.msg));
|
|
||||||
// throw runtime_error("Exception while saving: " + path + ": " + XMLString::transcode(e.msg));
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -670,6 +689,23 @@ DOMElement *XmlNode::buildElement(XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument *do
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xml_node<>* XmlNode::buildElement(xml_document<> *document) const {
|
||||||
|
xml_node<>* node = document->allocate_node(node_element, document->allocate_string(name.c_str()));
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < attributes.size(); ++i) {
|
||||||
|
node->append_attribute(
|
||||||
|
document->allocate_attribute(
|
||||||
|
document->allocate_string(attributes[i]->getName().c_str()),
|
||||||
|
document->allocate_string(attributes[i]->getValue().c_str())));
|
||||||
|
}
|
||||||
|
|
||||||
|
for(unsigned int i = 0; i < children.size(); ++i) {
|
||||||
|
node->append_node(children[i]->buildElement(document));
|
||||||
|
}
|
||||||
|
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
|
||||||
string XmlNode::getTreeString() const {
|
string XmlNode::getTreeString() const {
|
||||||
string str;
|
string str;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user