kvr_audio_plugin_news_468x60
C++ TinyXML visual studio | PLUGIN TUTOR

C++ TinyXML visual studio setup

TinyXML is a very small and simple xml library (xml parser ).  If you are using visual studio SDK and c++ language here is a very simple program for you to read and write the XML file.

Step One :

Download the library from

http://www.grinninglizard.com/tinyxml/

Step Two:

Create a new project ( File >> New >> Project )

Select Win32 Project click next

Step Three:

Select Console Application and Empty Project click Finish

Step Four:

Copy the following files to your project folder

  • tinystr.h
  • tinyxml.h
  • tinyxmlparser.cpp
  • tinystr.cpp
  • tinyxml.cpp
  • tinyxmlerror.cpp

from solution explorer add these file to your  project as  (Add >> Existing Item)

Step Five:

create a new .cpp file

(Add >> New Item)

Copy the following code into your new .cpp file – (This example has taken from TinyXML library but slightly modified for your better understand)


#ifdef TIXML_USE_STL

#include <iostream>

#include <sstream>

using namespace std;

#else

#include <stdio.h>

#endif

#include "tinyxml.h"

#if defined( WIN32 ) && defined( TUNE )

#include <crtdbg.h>

_CrtMemState startMemState;

_CrtMemState endMemState;

#endif

// load the named file and dump its structure to STDOUT

void loadEffectXML(const char* pFilename)

{

TiXmlDocument doc(pFilename);

bool loadOkay = doc.LoadFile();

TiXmlNode* node = 0;

if (loadOkay)

{

//Print whole xml file

printf("\n%s:\n\n", pFilename);

doc.Print( stdout );

//Print the Root

node = doc.RootElement();

assert( node );

printf("\n\n%s",node->Value()); // Print the root

node = node->FirstChild();

node = node->NextSibling("child"); // Print the child item

node = node->FirstChild("child1");    //Print the item value

node = node->FirstChild();

printf("\n\n%s",node->Value());

}

else

{

printf("Failed to load file \"%s\"\n", pFilename);

}

}

void saveEffectXML()

{

TiXmlDocument doc;

TiXmlElement* msg;

TiXmlDeclaration * decl = new TiXmlDeclaration( "1.0", "", "" );

doc.LinkEndChild( decl );

TiXmlElement * root = new TiXmlElement( "testproject" );

doc.LinkEndChild( root );

TiXmlComment * comment = new TiXmlComment();

comment->SetValue(" Settings for MyApp " );

root->LinkEndChild( comment );

TiXmlElement * volume = new TiXmlElement( "child" );

root->LinkEndChild( volume );

msg = new TiXmlElement( "child1" );

msg->LinkEndChild( new TiXmlText( "child1" ));

volume->LinkEndChild( msg );

msg = new TiXmlElement( "child2" );

msg->LinkEndChild( new TiXmlText( "child2" ));

volume->LinkEndChild( msg );

doc.SaveFile("test.xml");

}

int main(void)

{

char c;

saveEffectXML();

loadEffectXML("test.xml");

c=getchar();

}

Step Six:

Build the application and run it.

Output

Thanks to TinyXML



Leave a Reply

Spam Protection by WP-SpamFree