Menu

How to get text-representation of a xml doc ?

Clemens
2006-10-21
2013-05-20
  • Clemens

    Clemens - 2006-10-21

    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 ?

     
    • LangFox

      LangFox - 2007-03-23

      The same question...

      I'm wondering if TinyXml supports this function?

       
    • MA_Xx

      MA_Xx - 2007-05-26

      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

       
    • Dale

      Dale - 2007-06-26

      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;
      }

       

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.