SDL_rwops and xml

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

and then to write the xml node i use

Code:
void EngineMaster::setValueForKey(const char* value, const char* key){

	XMLElement* rootNode;
	XMLDocument* doc;
	XMLElement* node;

	if (!key || !value){
		return;
	}

	//find node
	node = getXMLNodeForKey(key, &rootNode, &doc);

	//change node if exists
	if (node){
		if (node->FirstChild()){
			node->FirstChild()->SetValue(value);
		}
		else{
			XMLText* content = doc->NewText(value);
			node->LinkEndChild(content);
		}
	}
	else{
		if (rootNode){
			XMLElement* temp = doc->NewElement(key);
			rootNode->LinkEndChild(temp);
			XMLText* content = doc->NewText(value);
			temp->LinkEndChild(content);
		}
	}
}

the part i have trouble with is how to save the new node in the document