TinyXMLResource         Use TinyXML documents via Ogres resource system
Print

Author:' xadhoom?'

Discussion: Ogre Forum(external link)

The following class shows an example implementation for TinyXML(external link) documents via Ogres resource system (current version: 1.6.1 Shoggoth).

Its subclasses allow to open 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

 

 

The source code can be found here(external link).

 
Local copy here:
 TinyXMLResource.zip

 
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:

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

 
The class supports cloning:

TinyXMLPtr myXMLFile2 = myXMLFile->clone("myXMLFile2Name");

 
And the creation of manual XML resources.

// 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...

Contributors to this page: jacmoe133512 points  and Beauty10198 points  .
Page last modified on Friday 21 of May, 2010 00:44:58 UTC by jacmoe133512 points .


The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.