Has any one and experience writing to and xml file using SDL_rwops??
Have it reading form the file but cant seem to manage to get it to write to the file using tinyxml-2
This is what i do to load the file:
Code:
bool FileIO::loadDocument(const char* filepath, char** doc_contents) {
// const char* path;
SDL_RWops *file;
file = SDL_RWFromFile(filepath, "rb");
size_t file_length = SDL_RWseek(file, 0, SEEK_END);
(*doc_contents) = new char[file_length + 1]; // allow an extra character for '\0'
SDL_RWseek(file, 0, SEEK_SET);
int n_blocks = SDL_RWread(file, (*doc_contents), 1, file_length);
SDL_RWclose(file);
(*doc_contents)[file_length] = '\0';
return true;
}
then to parse it with xml
Code:
XMLDocument* xmlDoc = new XMLDocument;
if (xmlDoc->Parse(contents) == XML_SUCCESS) {
SDL_Log("Doc Parsed");
// get root node
*rootNode = xmlDoc->RootElement();
//*rootNode = xmlDoc->FirstChildElement();
if (nullptr == *rootNode) {
SDL_Log("read root node error ");
// break;
}
// find the node
curNode = (*rootNode)->FirstChildElement();
while (curNode != nullptr)
{
const char* nodeName = curNode->Value();
if (!strcmp(nodeName, pKey))
{
break;
}
curNode = curNode->NextSiblingElement();
}
}
else{
SDL_Log("Could not load doc: ");
}
delete[] contents;
return curNode;
but cant seem to figure out how to write to the file and safe it