00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "CEGUITinyXMLParser.h"
00025 #include "CEGUIResourceProvider.h"
00026 #include "CEGUISystem.h"
00027 #include "CEGUIXMLHandler.h"
00028 #include "CEGUIXMLAttributes.h"
00029 #include "CEGUILogger.h"
00030 #include "tinyxml/tinyxml.h"
00031
00032
00033 namespace CEGUI
00034 {
00035 class TinyXMLDocument : public TiXmlDocument
00036 {
00037 public:
00038 TinyXMLDocument(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup);
00039 ~TinyXMLDocument()
00040 {}
00041 protected:
00042 void processElement(const TiXmlElement* element);
00043
00044 private:
00045 XMLHandler* d_handler;
00046 };
00047
00048 TinyXMLDocument::TinyXMLDocument(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup)
00049 {
00050 d_handler = &handler;
00051
00052
00053
00054 RawDataContainer rawXMLData;
00055 System::getSingleton().getResourceProvider()->loadRawDataContainer(filename, rawXMLData, resourceGroup);
00056
00057 TiXmlDocument doc;
00058 doc.Parse((const char*)rawXMLData.getDataPtr());
00059
00060 const TiXmlElement* currElement = doc.RootElement();
00061
00062 if (currElement)
00063 {
00064
00065 processElement(currElement);
00066 }
00067
00068 System::getSingleton().getResourceProvider()->unloadRawDataContainer(rawXMLData);
00069 }
00070
00071 void TinyXMLDocument::processElement(const TiXmlElement* element)
00072 {
00073
00074 XMLAttributes attrs;
00075 const TiXmlAttribute *currAttr = element->FirstAttribute();
00076
00077 while (currAttr)
00078 {
00079 attrs.add((utf8*)currAttr->Name(), (utf8*)currAttr->Value());
00080 currAttr = currAttr->Next();
00081 }
00082
00083
00084 d_handler->elementStart((utf8*)element->Value(), attrs);
00085
00086
00087 const TiXmlElement* childElement = element->FirstChildElement();
00088
00089 while (childElement)
00090 {
00091 processElement(childElement);
00092 childElement = childElement->NextSiblingElement();
00093 }
00094
00095
00096 d_handler->elementEnd(element->Value());
00097 }
00098
00099
00100 TinyXMLParser::TinyXMLParser(void)
00101 {
00102
00103 d_identifierString = "CEGUI::TinyXMLParser - Official tinyXML based parser module for CEGUI";
00104 }
00105
00106 TinyXMLParser::~TinyXMLParser(void)
00107 {}
00108
00109 void TinyXMLParser::parseXMLFile(XMLHandler& handler, const String& filename, const String& schemaName, const String& resourceGroup)
00110 {
00111 TinyXMLDocument doc(handler, filename, schemaName, resourceGroup);
00112 }
00113
00114
00115 bool TinyXMLParser::initialiseImpl(void)
00116 {
00117 return true;
00118 }
00119
00120 void TinyXMLParser::cleanupImpl(void)
00121 {}
00122
00123 }