Download
here a example usage for reading the config.xml in the media folder.
Code: Select all
#include "XMLread.h"
int main(int argc, char* argv[])
{
XMLread read("media/config.xml"); //parsing is actually done now....
//there are two ways getting the rootnode either call
XMLread::Node* RootNode = read.getRoot();
//or you call
RootNode = read.getNode("config"); ///if this returns NULL the rootNode is not called "config" and none of its children
///this also returns the first children of the rootNode called "config" if root is not called "config"
///now lets get the startup model
XMLread::Node* StartUpModelNode = RootNode->getNode("startUpModel");
///print the model name
printf("Model used: %s\n", StartUpModelNode->getValue("file"));
///now get the messageText
XMLread::Node* messageTextNode = RootNode->getNode("messageText");
///print the text with captn
printf("Info Text[]: %s\n", messageTextNode->getValue("caption"), messageTextNode->Text.c_str());
///cleanup is automatic when XMLread goes out of scope
return 0;
}
Code: Select all
#include "XMLread.h"
int main(int argc, char* argv[])
{
XMLread writer(""); ///create the writer without loading a file first
XMLread::Node* RootNode = writer.addNode("XMLConfig"); /// calling this function just with a name clears the xml tree and returns the root
///add a comment before the note starts
RootNode->AddComment("This is a XMLConfig file");
XMLread::Node* SomeNode = RootNode->addNode("Info");
SomeNode->AddComment("This is the info of the file");
///adding a attribute
SomeNode->AddAttribute("name", "Irrlicht 1.7.1");
SomeNode->Text = "The Irrlicht Engine is a 3D graphics engine without gameengine components";
///add a datanode
SomeNode = RootNode->addNode("Data");
SomeNode->AddComment("This a node with Data");
///this is a CDATA field
SomeNode->CData = "Some data whatever";
///add a node with children
SomeNode = RootNode->addNode("Childrens");
SomeNode->addNode("Children");
SomeNode->addNode("Children")->addNode("Blubb");
SomeNode->addNode("Children");
///save the xml tree to file
writer.save("myconfig.xml");
return 0;
}