Menu

How to create TiXMLDocument() with XML in mem

2004-07-12
2004-07-25
  • karam_chand

    karam_chand - 2004-07-12

    Hello,

    I have XML data in memory. Can I create an TiXMLDOcument() of it and work with it?

    Basically, my XML data is in memory and not in file, so I just want to use it?

    Karam

     
    • Ellers

      Ellers - 2004-07-12

      There is a Parse( const char* ) method just for this.

       
    • Anonymous

      Anonymous - 2004-07-15

      I was also trying to figure out how to parse an encrypted XML file, if it's decrypted in memory, i have seen this Parse( const char* ) function but there's no explanation nor anything for it.

      I don't know what is this for. any example of how to use it would help..

       
    • Ellers

      Ellers - 2004-07-15

      This code shows how to use Parse() with a plain, unencrypted, normal char array.

      It is taken out of tinyxml_2_2_1*.tar.gz tinyxml\xmltest.cpp, just below where main() starts (anything beginning with "//" is my editing):

          const char* demoStart =
              "<?xml version=\&quot;1.0\&quot;  standalone='no' >\n"
              "<!-- Our to do list data -->"
              "<ToDo>\n"
              "<!-- Do I need a secure PDA? -->\n"
              "<Item priority=\&quot;1\&quot; distance='close'> Go to the <bold>Toy store!</bold></Item>"
              "<Item priority=\&quot;2\&quot; distance='none'> Do bills   </Item>"
              "<Item priority=\&quot;2\&quot; distance='far &amp; back'> Look for Evil Dinosaurs! </Item>"
              "</ToDo>";

          //... irrelevant stuff edited out for clarity
         
          TiXmlDocument doc( "demotest.xml" );
          doc.Parse( demoStart );

          if ( doc.Error() )
          {
              // document failed to load - handle in whatever way is best for your app
              printf( "Error in %s: %s\n", doc.Value(), doc.ErrorDesc() );
              exit( 1 );
          }
         
          // document loaded ok now

      I recently wrote some code to read a gzip'd xml file (.svgz) into memory, uncompress it in memory, then pass the raw pointer to TinyXml. Works wonderfully.

       
    • Anonymous

      Anonymous - 2004-07-25

      OK that's nice now, i understand but i wish if tiny had some interactive tuts explaining every thing Frequently asked here in forums :(

       

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.