I just started with TinyXml and I wondered how to get a string of a whole xml-document ?
There is e.g. the method TiXmlDocument::SaveFile() which writes the contents to a file. And now I want exactly these contents, but as a string. I searched the code and that tutorial but I didn't find a method how to get such a string.
Can anyone help ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I just started with TinyXml and I wondered how to get a string of a whole xml-document ?
There is e.g. the method TiXmlDocument::SaveFile() which writes the contents to a file. And now I want exactly these contents, but as a string. I searched the code and that tutorial but I didn't find a method how to get such a string.
Can anyone help ?
The same question...
I'm wondering if TinyXml supports this function?
I don't know if this will help, but I managed to get the content of a xml as a string this way:
#include <iostream>
#include <sstream>
#include "tinyxml.h"
int main()
{
TiXmlDocument doc( "demotest.xml" );
doc.LoadFile();
stringstream s;
s << doc;
string xmlAsString = s.str();
cout << xmlAsString << endl;
return 0;
}
Cheers
MA_Xx
I wanted to get out the xml for a given element, and all children. The following simple modification does that:
getXml(TiXmlElement* ele)
{
stringstream s;
s << *ele;
string ss = s.str();
return ss;
}