Skip to main content

History: TinyXMLResource

Source of version: 14 (current)

Copy to clipboard
            __Author__:' ((User:xadhoom|xadhoom))'

__Discussion__: [http://www.ogre3d.org/forums/viewtopic.php?f=10&t=48867|Ogre Forum]

The following class shows an example implementation for [http://en.wikipedia.org/wiki/TinyXML|TinyXML] documents via Ogres resource system (current version: 1.6.1 ((Shoggoth))).

Its subclasses allow to open ((-XML|XML)) files (with TinyXML) like you would do with ''.mesh'' files. You only have to call create and load as described and you will get a resource which contains the actual XML data of the file. This is useful for everything where you describe things in XML ...

* __TinyXMLResourceManager__ - The Ogre ResourceManager which creates new TinyXML resources
* __TinyXMLResource__ - The actual TinyXML document resource which supplies access to the TinyXMLDocument node

{toc}

{DIV(class="Layout_box13")}The source code can be found [http://www.mediafire.com/file/m2nzu11woh1/TinyXMLResource.zip|here].
{DIV}

To use the code you have to add the additional TinyXML dependencies. If you encounter problems you may have to 
adapt the Header files. You can then use it like this:
{CODE(wrap="1", colors="c++")}// create our ResourceManager
OGRE_NEW TinyXMLResourceManager();

// create a new resource for our xml file 'MyFile.xml'
TinyXMLPtr myXMLFile = TinyXMLResourceManager::getSingleton().create("MyFile.xml", "MyResourceGroup");

// actually load our xml file
myXMLFile->load();

// if there was no loading error we can now retrieve the TiniYML node below
if(xml->getError())
{
   LogManager::getSingletonPtr()->logMessage("An error occured in file " + xml->getName() + 
                                             " : " + String(xml->getErrorDesc()));
}
else
{
   TiXmlNode* node = xml->getXMLData();
   
   // perform operations on the xml structure
}{CODE}

The class supports cloning:
{CODE(wrap="1", colors="c++")}TinyXMLPtr myXMLFile2 = myXMLFile->clone("myXMLFile2Name");{CODE}

And the creation of manual XML resources.
{CODE(wrap="1", colors="c++")}// create a manual xml resource (normally you should add a ManualResourceLoader in case of a reload)   
TinyXMLPtr myXMLFile3 = 
   TinyXMLResourceManager::getSingleton().createManual("myXMLFile3Name", "MyGroup");

// retrieve the xml root node
TiXmlNode* node = xml->getXMLData();

// add attributes and elements to node as you like...{CODE}