Menu

Print to string

Anonymous
2004-09-15
2004-09-16
  • Anonymous

    Anonymous - 2004-09-15

    Is there any easy known way to print the entire TiXmlDocument out to a string?  I know how to do it through saving it to a file, but need the ability to pass it to a string without having to access files.

    Thanx.

     
    • Lee Thomason

      Lee Thomason - 2004-09-15

      The easy way (requires STL mode on of course)

      std::string str;
      str << document0;

      lee

       
    • Anonymous

      Anonymous - 2004-09-16

      ok, I tried adding the #define TIXML_USE_STL above the include of tinyxml.h, but I still get linking errors.  Any ideas as to how to fix this, I've looked through the forum and tried some of the ideas that have fixed this for others but none seem to work.  Not using MFC.

      Thanx

       
      • Yves Berquin

        Yves Berquin - 2004-09-16

        There's a way to do this without STL :

        TiXmlString get_xml_string (const TiXmlNode * node)
        {
        TiXmlString s;
        TiXmlOutStream os_stream;

        os_stream << * node;
        s = os_stream;
        return s;
        }

        This returns a TiXmlString, on which you can call the .c_str () method to have the C-string.

         
    • Ellers

      Ellers - 2004-09-16

      are you sure you recompiled the library after #define TIXML_USE_STL? I've sometimes put it in there only to recompile my own program but not the library...

       
    • Anonymous

      Anonymous - 2004-09-16

      that worked pretty well actually.  Thanks for the quick responses.  Hate to keep being a bother, this will work, but is there a way to save the formatting(tabs, new lines), or does tinyxml just dump all those when it dumps to the stream?

      Thanx again!

       
    • Ellers

      Ellers - 2004-09-16

      Indents are just text nodes containing whitespace - if there are text nodes in your document tree they should write out as-is.

      I have a vague memory of some whitespace eliminating switch though... can't remember for sure, but check that out.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.