Page 1 of 1

XML Writer/Reader

Posted: Tue Feb 23, 2010 3:27 pm
by sudi
I didn't like the way the Irrlicht XMLwriter/reader worked and actually the writer didn't work at all for me(linux64). so wrote a wrapper for irrxml and a xmlwriter i found on the net.

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

Posted: Fri Feb 26, 2010 1:46 pm
by zet.dp.ua
Thanks.
SAX approach is the fastest, but DOM is the simplest for use.

Posted: Tue Mar 02, 2010 2:21 pm
by onesixtyfourth
Have you ever tried tinyxml

Re: XML Writer/Reader

Posted: Sun Oct 21, 2018 7:30 am
by netpipe
can you reupload this please.