Stoppt die Vorratsdatenspeicherung! Jetzt klicken & handeln!Willst du auch bei der Aktion teilnehmen? Hier findest du alle relevanten Infos und Materialien:
 

About TinyXML

TinyXML is a small and IMHO a easy to use XML Library for C++. It cannot handle DTD‘s ! You can find more Informations at www.sourceforge.net/projects/tinyxml .

Using

Just add the cpp Files to your Project and include the tinyxml.h for usage. I think the best way is to copy all files in a subfolder of your Project.

Using with wxWidget

I changed only the following lines in the tinyxml.h : line 46 - 49

#if defined( DEBUG ) && defined( _MSC_VER )
//#include <windows.h>    // Because wxWidget got an error with FindWindow ... 
#define TIXML_LOG OutputDebugString
#else

I think this is an issue with VC7, so if you use another compiler this schould not be a issue.

Because I want to use the STL Streams, I also defined the TIXML_USE_STL Macro direct inside the tinyxml.h.

Basic Steps

Opening File

TiXmlDocument doc( "w:\\colinux\\_default.colinux.xml" );
if ( !doc.LoadFile() )	{
	wxLogDebug( "Open Error" );
	return;
}

Reading

The Sample XML file:

<root>
    <daten>
        <TrayIcon show="true" />
    </daten>
</root>
TiXmlNode* rootnode;
TiXmlNode* node;
wxString sTemp;
rootnode =  m_Document.FirstChildElement( "root" );  // Get Root Node
if(rootnode) {
  node =  rootnode->FirstChildElement( "daten" );
  if(node) {
    node =  node->FirstChildElement( "TrayIcon" );
    if(node) {
      sTemp = node->ToElement()->Attribute(sAttribute);  // sTemp is now : "true"
  }
}

Writing

TiXmlNode* node;
wxString sTemp;
node =  m_Document.FirstChildElement( "root" );  // Get Root Node
if(!node) {  // Ups didn't exist ? So create new Node
  TiXmlElement newnode("root");
  m_Document.InsertEndChild(newnode);
  node =  m_Document.FirstChildElement( "root" );
}
if(node) {
  node =  rootnode->FirstChildElement( "daten" );
  if(!node) {  // Ups didn't exist ? So create new Node
    TiXmlElement newnode("daten");
    m_Document.InsertEndChild(newnode);
    node =  m_Document.FirstChildElement( "daten" );
  }
  if(node) {
    long lValue=13;
    // If Attribute didn't exist, a new is automatically created.
    node->ToElement()->SetAttribute("month",lValue);  
  }
}
// Write to Disk
m_Document.SaveFile();

The XML File looks now:

<root>
    <daten month="13" />
</root>
 
tutorial/tinyxml.txt · Last modified: 2006/07/25 09:59
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki