Update usage of TinyXML to use TinyXML2

This commit is contained in:
Lukas Aldershaab 2021-07-31 21:54:19 +02:00
parent cd170910b2
commit 9a795e89f3
23 changed files with 865 additions and 1447 deletions

View file

@ -20,8 +20,9 @@
#include <dae/daeURI.h> #include <dae/daeURI.h>
#include <dae/daeIOPluginCommon.h> #include <dae/daeIOPluginCommon.h>
class TiXmlDocument; #ifndef TINYXML2_INCLUDED
class TiXmlElement; #include <tinyxml2.h>
#endif
class daeTinyXMLPlugin : public daeIOPluginCommon class daeTinyXMLPlugin : public daeIOPluginCommon
{ {
@ -60,12 +61,12 @@ public:
virtual DLLSPEC daeString getOption( daeString option ); virtual DLLSPEC daeString getOption( daeString option );
private: private:
TiXmlDocument* m_doc; tinyxml2::XMLDocument* m_doc;
std::list<TiXmlElement*> m_elements; std::list<tinyxml2::XMLElement*> m_elements;
virtual daeElementRef readFromFile(const daeURI& uri); virtual daeElementRef readFromFile(const daeURI& uri);
virtual daeElementRef readFromMemory(daeString buffer, const daeURI& baseUri); virtual daeElementRef readFromMemory(daeString buffer, const daeURI& baseUri);
daeElementRef readElement(TiXmlElement* tinyXmlElement, daeElement* parentElement); daeElementRef readElement(tinyxml2::XMLElement* tinyXmlElement, daeElement* parentElement);
void writeElement( daeElement* element ); void writeElement( daeElement* element );
void writeAttribute( daeMetaAttribute* attr, daeElement* element ); void writeAttribute( daeMetaAttribute* attr, daeElement* element );

View file

@ -24,7 +24,7 @@
#endif #endif
#include <string> #include <string>
#include <tinyxml.h> #include <tinyxml2.h>
#include <dae.h> #include <dae.h>
#include <dom.h> #include <dom.h>
#include <dae/daeMetaElement.h> #include <dae/daeMetaElement.h>
@ -36,7 +36,7 @@
using namespace std; using namespace std;
namespace { namespace {
daeInt getCurrentLineNumber(TiXmlElement* element) { daeInt getCurrentLineNumber(tinyxml2::XMLElement* element) {
return -1; return -1;
} }
} }
@ -65,7 +65,7 @@ daeElementRef daeTinyXMLPlugin::readFromFile(const daeURI& uri) {
string file = cdom::uriToNativePath(uri.str()); string file = cdom::uriToNativePath(uri.str());
if (file.empty()) if (file.empty())
return NULL; return NULL;
TiXmlDocument doc; tinyxml2::XMLDocument doc;
doc.LoadFile(file.c_str()); doc.LoadFile(file.c_str());
if (!doc.RootElement()) { if (!doc.RootElement()) {
daeErrorHandler::get()->handleError((std::string("Failed to open ") + uri.str() + daeErrorHandler::get()->handleError((std::string("Failed to open ") + uri.str() +
@ -76,7 +76,7 @@ daeElementRef daeTinyXMLPlugin::readFromFile(const daeURI& uri) {
} }
daeElementRef daeTinyXMLPlugin::readFromMemory(daeString buffer, const daeURI& baseUri) { daeElementRef daeTinyXMLPlugin::readFromMemory(daeString buffer, const daeURI& baseUri) {
TiXmlDocument doc; tinyxml2::XMLDocument doc;
doc.Parse(buffer); doc.Parse(buffer);
if (!doc.RootElement()) { if (!doc.RootElement()) {
daeErrorHandler::get()->handleError("Failed to open XML document from memory buffer in " daeErrorHandler::get()->handleError("Failed to open XML document from memory buffer in "
@ -86,9 +86,9 @@ daeElementRef daeTinyXMLPlugin::readFromMemory(daeString buffer, const daeURI& b
return readElement(doc.RootElement(), NULL); return readElement(doc.RootElement(), NULL);
} }
daeElementRef daeTinyXMLPlugin::readElement(TiXmlElement* tinyXmlElement, daeElement* parentElement) { daeElementRef daeTinyXMLPlugin::readElement(tinyxml2::XMLElement* tinyXmlElement, daeElement* parentElement) {
std::vector<attrPair> attributes; std::vector<attrPair> attributes;
for (TiXmlAttribute* attrib = tinyXmlElement->FirstAttribute(); attrib != NULL; attrib = attrib->Next()) for (const tinyxml2::XMLAttribute* attrib = tinyXmlElement->FirstAttribute(); attrib != NULL; attrib = attrib->Next())
attributes.push_back(attrPair(attrib->Name(), attrib->Value())); attributes.push_back(attrPair(attrib->Name(), attrib->Value()));
daeElementRef element = beginReadElement(parentElement, tinyXmlElement->Value(), daeElementRef element = beginReadElement(parentElement, tinyXmlElement->Value(),
@ -102,7 +102,7 @@ daeElementRef daeTinyXMLPlugin::readElement(TiXmlElement* tinyXmlElement, daeEle
readElementText(element, tinyXmlElement->GetText(), getCurrentLineNumber(tinyXmlElement)); readElementText(element, tinyXmlElement->GetText(), getCurrentLineNumber(tinyXmlElement));
// Recurse children // Recurse children
for (TiXmlElement* child = tinyXmlElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement()) for (tinyxml2::XMLElement* child = tinyXmlElement->FirstChildElement(); child != NULL; child = child->NextSiblingElement())
element->placeElement(readElement(child, element)); element->placeElement(readElement(child, element));
return element; return element;
@ -136,13 +136,11 @@ daeInt daeTinyXMLPlugin::write(const daeURI& name, daeDocument *document, daeBoo
fclose(tempfd); fclose(tempfd);
} }
m_doc = new TiXmlDocument(name.getURI()); m_doc = new tinyxml2::XMLDocument();
if (m_doc) if (m_doc)
{ {
m_doc->SetTabSize(4); tinyxml2::XMLDeclaration* decl = m_doc->NewDeclaration("xml version=\"1.0\"");
m_doc->LinkEndChild( decl );
TiXmlDeclaration* decl = new TiXmlDeclaration( "1.0", "", "" );
m_doc->LinkEndChild( decl );
writeElement(document->getDomRoot()); writeElement(document->getDomRoot());
@ -158,12 +156,12 @@ void daeTinyXMLPlugin::writeElement( daeElement* element )
daeMetaElement* _meta = element->getMeta(); daeMetaElement* _meta = element->getMeta();
if (!_meta->getIsTransparent() ) if (!_meta->getIsTransparent() )
{ {
TiXmlElement* tiElm = new TiXmlElement( element->getElementName() ); tinyxml2::XMLElement* tiElm = m_doc->NewElement( element->getElementName() );
if (m_elements.empty() == true) { if (m_elements.empty() == true) {
m_doc->LinkEndChild(tiElm); m_doc->LinkEndChild(tiElm);
} else { } else {
TiXmlElement* first = m_elements.front(); tinyxml2::XMLElement* first = m_elements.front();
first->LinkEndChild(tiElm); first->LinkEndChild(tiElm);
} }
m_elements.push_front(tiElm); m_elements.push_front(tiElm);
@ -200,7 +198,7 @@ void daeTinyXMLPlugin::writeValue( daeElement* element )
attr->memoryToString(element, buffer); attr->memoryToString(element, buffer);
std::string s = buffer.str(); std::string s = buffer.str();
if (!s.empty()) if (!s.empty())
m_elements.front()->LinkEndChild( new TiXmlText(buffer.str().c_str()) ); m_elements.front()->LinkEndChild( m_doc->NewText(buffer.str().c_str()) );
} }
} }

View file

@ -34,7 +34,7 @@ namespace VPersistence
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <> template <>
bool write( TiXmlElement *pElement, VController *pObject ) bool write( tinyxml2::XMLElement *pElement, VController *pObject )
{ {
// Write Properties. // Write Properties.
if ( !writeProperties( pElement, pObject ) ) if ( !writeProperties( pElement, pObject ) )
@ -53,7 +53,7 @@ namespace VPersistence
} }
template <> template <>
bool read( TiXmlElement *pElement, VController *pObject ) bool read( tinyxml2::XMLElement *pElement, VController *pObject )
{ {
// Read Properties. // Read Properties.
if ( !readProperties( pElement, pObject ) ) if ( !readProperties( pElement, pObject ) )
@ -87,10 +87,10 @@ namespace VPersistence
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <> template <>
bool write( TiXmlElement *pElement, VObject *pObject ) bool write( tinyxml2::XMLElement *pElement, VObject *pObject )
{ {
// Create Element. // Create Element.
TiXmlElement *objectElement = new TiXmlElement( "VObject" ); tinyxml2::XMLElement *objectElement = pElement->GetDocument()->NewElement( "VObject" );
pElement->LinkEndChild( objectElement ); pElement->LinkEndChild( objectElement );
// Attributes. // Attributes.
@ -107,7 +107,7 @@ namespace VPersistence
} }
template <> template <>
bool read( TiXmlElement *pElement, VObject *pObject ) bool read( tinyxml2::XMLElement *pElement, VObject *pObject )
{ {
// Read Properties. // Read Properties.
if ( !readProperties( pElement, pObject ) ) if ( !readProperties( pElement, pObject ) )
@ -134,4 +134,4 @@ namespace VPersistence
// Valid Read. // Valid Read.
return true; return true;
} }
} }

View file

@ -24,7 +24,7 @@
#define _VT_VPERSISTENCE_H_ #define _VT_VPERSISTENCE_H_
#ifndef TINYXML_INCLUDED #ifndef TINYXML_INCLUDED
#include "tinyxml/tinyxml.h" #include "tinyxml/tinyxml2.h"
#endif #endif
#ifndef _SIMOBJECT_H_ #ifndef _SIMOBJECT_H_
@ -34,6 +34,7 @@
#ifndef _VT_VOBJECT_H_ #ifndef _VT_VOBJECT_H_
#include "Verve/Core/VObject.h" #include "Verve/Core/VObject.h"
#endif #endif
#include "persistence/taml/fsTinyXml.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -48,17 +49,17 @@ namespace VPersistence
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <class T> bool write( TiXmlElement *pElement, T *pObject ); template <class T> bool write( tinyxml2::XMLElement *pElement, T *pObject );
template <class T> bool writeFile( const char* pFileName, T *pObject ) template <class T> bool writeFile( const char* pFileName, T *pObject )
{ {
// Create Doc. // Create Doc.
TiXmlDocument xmlDocument; VfsXMLDocument xmlDocument;
TiXmlDeclaration *xmlDeclaration = new TiXmlDeclaration( "1.0", "", "" ); tinyxml2::XMLDeclaration *xmlDeclaration = xmlDocument.NewDeclaration();
xmlDocument.LinkEndChild( xmlDeclaration ); xmlDocument.LinkEndChild( xmlDeclaration );
// Create Root. // Create Root.
TiXmlElement *xmlRoot = new TiXmlElement( "VerveControllerSequence" ); tinyxml2::XMLElement *xmlRoot = xmlDocument.NewElement( "VerveControllerSequence" );
xmlDocument.LinkEndChild( xmlRoot ); xmlDocument.LinkEndChild( xmlRoot );
// Write Version. // Write Version.
@ -76,13 +77,13 @@ namespace VPersistence
}; };
template <class T> bool writeProperties( TiXmlElement *pElement, T *pObject ) template <class T> bool writeProperties( tinyxml2::XMLElement *pElement, T *pObject )
{ {
const AbstractClassRep::FieldList &fieldList = pObject->getFieldList(); const AbstractClassRep::FieldList &fieldList = pObject->getFieldList();
const AbstractClassRep::Field *field = NULL; const AbstractClassRep::Field *field = NULL;
// Create Property Root. // Create Property Root.
TiXmlElement *propertyRoot = new TiXmlElement( "Properties" ); tinyxml2::XMLElement *propertyRoot = pElement->GetDocument()->NewElement( "Properties" );
pElement->LinkEndChild( propertyRoot ); pElement->LinkEndChild( propertyRoot );
const S32 fieldCount = fieldList.size(); const S32 fieldCount = fieldList.size();
@ -111,10 +112,10 @@ namespace VPersistence
if ( fieldValue ) if ( fieldValue )
{ {
// Create Element. // Create Element.
TiXmlElement *propertyElement = new TiXmlElement( fieldName ); tinyxml2::XMLElement *propertyElement = pElement->GetDocument()->NewElement( fieldName );
// Apply Value. // Apply Value.
propertyElement->InsertEndChild( TiXmlText( fieldValue ) ); propertyElement->InsertNewText( fieldValue );
// Add. // Add.
propertyRoot->LinkEndChild( propertyElement ); propertyRoot->LinkEndChild( propertyElement );
@ -125,7 +126,7 @@ namespace VPersistence
return true; return true;
}; };
template <class T> bool writeObjects( TiXmlElement *pElement, T *pObject ) template <class T> bool writeObjects( tinyxml2::XMLElement *pElement, T *pObject )
{ {
for ( ITreeNode *node = pObject->mChildNode; node != NULL; node = node->mSiblingNextNode ) for ( ITreeNode *node = pObject->mChildNode; node != NULL; node = node->mSiblingNextNode )
{ {
@ -143,18 +144,18 @@ namespace VPersistence
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
template <class T> bool read( TiXmlElement *pElement, T *pObject ); template <class T> bool read( tinyxml2::XMLElement *pElement, T *pObject );
template <class T> bool readFile( const char* pFileName, T *pObject ) template <class T> bool readFile( const char* pFileName, T *pObject )
{ {
TiXmlDocument xmlDocument; VfsXMLDocument xmlDocument;
if ( !xmlDocument.LoadFile( pFileName ) ) if ( !xmlDocument.LoadFile( pFileName ) )
{ {
Con::errorf( "VPersistence::readFile() - Unable to load file '%s'.", pFileName ); Con::errorf( "VPersistence::readFile() - Unable to load file '%s'.", pFileName );
return false; return false;
} }
TiXmlElement *rootElement = xmlDocument.RootElement(); tinyxml2::XMLElement *rootElement = xmlDocument.RootElement();
if ( !rootElement ) if ( !rootElement )
{ {
Con::errorf( "VPersistence::readFile() - Invalid Document '%s'.", pFileName ); Con::errorf( "VPersistence::readFile() - Invalid Document '%s'.", pFileName );
@ -179,12 +180,12 @@ namespace VPersistence
return true; return true;
}; };
template <class T> bool readProperties( TiXmlElement *pElement, T *pObject ) template <class T> bool readProperties( tinyxml2::XMLElement *pElement, T *pObject )
{ {
TiXmlElement *propertyRoot = pElement->FirstChildElement( "Properties" ); tinyxml2::XMLElement *propertyRoot = pElement->FirstChildElement( "Properties" );
if ( propertyRoot ) if ( propertyRoot )
{ {
for ( TiXmlElement *child = propertyRoot->FirstChildElement(); child != NULL; child = child->NextSiblingElement() ) for ( tinyxml2::XMLElement *child = propertyRoot->FirstChildElement(); child != NULL; child = child->NextSiblingElement() )
{ {
// Get Field Data. // Get Field Data.
const char *fieldName = child->Value(); const char *fieldName = child->Value();
@ -211,9 +212,9 @@ namespace VPersistence
return true; return true;
}; };
template <class T> bool readObjects( TiXmlElement *pElement, T *pObject ) template <class T> bool readObjects( tinyxml2::XMLElement *pElement, T *pObject )
{ {
for ( TiXmlElement *child = pElement->FirstChildElement( "VObject" ); child != NULL; child = child->NextSiblingElement( "VObject" ) ) for ( tinyxml2::XMLElement *child = pElement->FirstChildElement( "VObject" ); child != NULL; child = child->NextSiblingElement( "VObject" ) )
{ {
// Get Object Type. // Get Object Type.
const char *type = child->Attribute( "Type" ); const char *type = child->Attribute( "Type" );

View file

@ -606,10 +606,10 @@ void VController::sort( void )
// Write the DataTable out to a TinyXML document. // Write the DataTable out to a TinyXML document.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool VController::writeDataTable( TiXmlElement *pElement ) bool VController::writeDataTable( tinyxml2::XMLElement *pElement )
{ {
// Create Data Table Root. // Create Data Table Root.
TiXmlElement *dataTableRoot = new TiXmlElement( "DataTable" ); tinyxml2::XMLElement *dataTableRoot = pElement->GetDocument()->NewElement( "DataTable" );
pElement->LinkEndChild( dataTableRoot ); pElement->LinkEndChild( dataTableRoot );
for ( VDataTable::VDataMap::Iterator itr = mDataTable.mDataMap.begin(); itr != mDataTable.mDataMap.end(); ++itr ) for ( VDataTable::VDataMap::Iterator itr = mDataTable.mDataMap.begin(); itr != mDataTable.mDataMap.end(); ++itr )
@ -618,11 +618,11 @@ bool VController::writeDataTable( TiXmlElement *pElement )
VDataTable::sDataItem *data = &itr->value; VDataTable::sDataItem *data = &itr->value;
// Create Element. // Create Element.
TiXmlElement *dataElement = new TiXmlElement( "DataItem" ); tinyxml2::XMLElement* dataElement = pElement->GetDocument()->NewElement( "DataItem" );
// Apply Attributes. // Apply Attributes.
dataElement->SetAttribute( "Type", VDataTable::getDataTypeDescription( data->Type ) ); dataElement->SetAttribute( "Type", VDataTable::getDataTypeDescription( data->Type ) );
dataElement->SetAttribute( "Name", data->FieldName ); dataElement->SetAttribute( "Name", data->FieldName.c_str() );
dataElement->SetAttribute( "Value", getDataField( StringTable->insert( data->FieldName.c_str() ), NULL ) ); dataElement->SetAttribute( "Value", getDataField( StringTable->insert( data->FieldName.c_str() ), NULL ) );
// Add. // Add.
@ -645,12 +645,12 @@ bool VController::writeDataTable( TiXmlElement *pElement )
// Read the DataTable from a TinyXML document. // Read the DataTable from a TinyXML document.
// //
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool VController::readDataTable( TiXmlElement *pElement ) bool VController::readDataTable( tinyxml2::XMLElement *pElement )
{ {
TiXmlElement *dataTableRoot = pElement->FirstChildElement( "DataTable" ); tinyxml2::XMLElement *dataTableRoot = pElement->FirstChildElement( "DataTable" );
if ( dataTableRoot ) if ( dataTableRoot )
{ {
for ( TiXmlElement *child = dataTableRoot->FirstChildElement(); child != NULL; child = child->NextSiblingElement() ) for ( tinyxml2::XMLElement *child = dataTableRoot->FirstChildElement(); child != NULL; child = child->NextSiblingElement() )
{ {
// Get Field Data. // Get Field Data.
const char *fieldType = child->Attribute( "Type" ); const char *fieldType = child->Attribute( "Type" );

View file

@ -198,11 +198,11 @@ public:
// Saving. // Saving.
bool writeDataTable( TiXmlElement *pElement ); bool writeDataTable( tinyxml2::XMLElement *pElement );
// Reading. // Reading.
bool readDataTable( TiXmlElement *pElement ); bool readDataTable( tinyxml2::XMLElement *pElement );
// Console Declaration. // Console Declaration.
@ -243,4 +243,4 @@ protected:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#endif // _VT_VCONTROLLER_H_ #endif // _VT_VCONTROLLER_H_

View file

@ -45,10 +45,6 @@
#include "Verve/Core/VTreeNode.h" #include "Verve/Core/VTreeNode.h"
#endif #endif
#ifndef TINYXML_INCLUDED
#include "tinyxml/tinyxml.h"
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class VController; class VController;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -123,4 +119,4 @@ public:
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#endif // _VT_VOBJECT_H_ #endif // _VT_VOBJECT_H_

View file

@ -20,7 +20,7 @@
// IN THE SOFTWARE. // IN THE SOFTWARE.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "tinyxml/tinyxml.h" #include "tinyxml/tinyxml2.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Console implementation of STL map. // Console implementation of STL map.
@ -176,7 +176,7 @@ bool SimXMLDocument::onAdd()
if(!m_qDocument) if(!m_qDocument)
{ {
m_qDocument = new fsTiXmlDocument(); m_qDocument = new VfsXMLDocument();
} }
return true; return true;
} }
@ -253,7 +253,7 @@ bool SimXMLDocument::saveFile(const char* rFileName)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
bool SimXMLDocument::saveToString(String& str) bool SimXMLDocument::saveToString(String& str)
{ {
TiXmlPrinter printer; tinyxml2::XMLPrinter printer;
bool ret = m_qDocument->Accept( &printer ); bool ret = m_qDocument->Accept( &printer );
if (ret) if (ret)
str = printer.CStr(); str = printer.CStr();
@ -313,7 +313,7 @@ const char* SimXMLDocument::getErrorDesc(void) const
{ {
return StringTable->insert("No document"); return StringTable->insert("No document");
} }
return m_qDocument->ErrorDesc(); return m_qDocument->ErrorStr();
} }
DefineEngineMethod( SimXMLDocument, getErrorDesc, const char*, (),, DefineEngineMethod( SimXMLDocument, getErrorDesc, const char*, (),,
@ -346,16 +346,16 @@ bool SimXMLDocument::pushFirstChildElement(const char* rName)
m_CurrentAttribute = 0; m_CurrentAttribute = 0;
// Push the first element found under the current element of the given name // Push the first element found under the current element of the given name
fsTiXmlElement* pElement; tinyxml2::XMLElement* pElement;
if(!m_paNode.empty()) if(!m_paNode.empty())
{ {
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iLastElement]; tinyxml2::XMLNode* pNode = m_paNode[iLastElement];
if(!pNode) if(!pNode)
{ {
return false; return false;
} }
pElement = (fsTiXmlElement*) pNode->FirstChildElement(rName); pElement = pNode->FirstChildElement(rName);
} }
else else
{ {
@ -363,7 +363,7 @@ bool SimXMLDocument::pushFirstChildElement(const char* rName)
{ {
return false; return false;
} }
pElement = (fsTiXmlElement*)m_qDocument->FirstChildElement(rName); pElement = m_qDocument->FirstChildElement(rName);
} }
if(!pElement) if(!pElement)
@ -410,22 +410,22 @@ bool SimXMLDocument::pushChildElement(S32 index)
m_CurrentAttribute = 0; m_CurrentAttribute = 0;
// Push the first element found under the current element of the given name // Push the first element found under the current element of the given name
fsTiXmlElement* pElement; tinyxml2::XMLElement* pElement;
if(!m_paNode.empty()) if(!m_paNode.empty())
{ {
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iLastElement]; tinyxml2::XMLNode* pNode = m_paNode[iLastElement];
if(!pNode) if(!pNode)
{ {
return false; return false;
} }
pElement = (fsTiXmlElement*) pNode->FirstChildElement(); pElement = pNode->FirstChildElement();
for( S32 i = 0; i < index; i++ ) for( S32 i = 0; i < index; i++ )
{ {
if( !pElement ) if( !pElement )
return false; return false;
pElement = (fsTiXmlElement*)pElement->NextSiblingElement(); pElement = pElement->NextSiblingElement();
} }
} }
else else
@ -434,13 +434,13 @@ bool SimXMLDocument::pushChildElement(S32 index)
{ {
return false; return false;
} }
pElement = (fsTiXmlElement*)m_qDocument->FirstChildElement(); pElement = m_qDocument->FirstChildElement();
for( S32 i = 0; i < index; i++ ) for( S32 i = 0; i < index; i++ )
{ {
if( !pElement ) if( !pElement )
return false; return false;
pElement = (fsTiXmlElement*)pElement->NextSiblingElement(); pElement = pElement->NextSiblingElement();
} }
} }
@ -474,13 +474,13 @@ bool SimXMLDocument::nextSiblingElement(const char* rName)
return false; return false;
} }
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement*& pElement = m_paNode[iLastElement]; tinyxml2::XMLNode*& pElement = m_paNode[iLastElement];
if(!pElement) if(!pElement)
{ {
return false; return false;
} }
pElement = (fsTiXmlElement*)pElement->NextSiblingElement(rName); pElement = pElement->NextSiblingElement(rName);
if(!pElement) if(!pElement)
{ {
return false; return false;
@ -508,7 +508,7 @@ const char* SimXMLDocument::elementValue()
return StringTable->EmptyString(); return StringTable->EmptyString();
} }
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iLastElement]; tinyxml2::XMLNode* pNode = m_paNode[iLastElement];
if(!pNode) if(!pNode)
{ {
return StringTable->EmptyString(); return StringTable->EmptyString();
@ -549,7 +549,7 @@ const char* SimXMLDocument::attribute(const char* rAttribute)
return StringTable->EmptyString(); return StringTable->EmptyString();
} }
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iLastElement]; tinyxml2::XMLElement* pNode = m_paNode[iLastElement]->ToElement();
if(!pNode) if(!pNode)
{ {
return StringTable->EmptyString(); return StringTable->EmptyString();
@ -600,7 +600,7 @@ bool SimXMLDocument::attributeExists(const char* rAttribute)
return false; return false;
} }
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iLastElement]; tinyxml2::XMLElement* pNode = m_paNode[iLastElement]->ToElement();
if(!pNode) if(!pNode)
{ {
return false; return false;
@ -633,14 +633,14 @@ const char* SimXMLDocument::firstAttribute()
return StringTable->EmptyString(); return StringTable->EmptyString();
} }
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iLastElement]; tinyxml2::XMLElement* pNode = m_paNode[iLastElement]->ToElement();
if(!pNode) if(!pNode)
{ {
return StringTable->EmptyString(); return StringTable->EmptyString();
} }
// Gets its first attribute, if any // Gets its first attribute, if any
m_CurrentAttribute = (fsTiXmlAttribute*)pNode->FirstAttribute(); m_CurrentAttribute = pNode->FirstAttribute();
if(!m_CurrentAttribute) if(!m_CurrentAttribute)
{ {
return StringTable->EmptyString(); return StringTable->EmptyString();
@ -670,14 +670,18 @@ const char* SimXMLDocument::lastAttribute()
return StringTable->EmptyString(); return StringTable->EmptyString();
} }
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iLastElement]; tinyxml2::XMLElement* pNode = m_paNode[iLastElement]->ToElement();
if(!pNode) if(!pNode)
{ {
return StringTable->EmptyString(); return StringTable->EmptyString();
} }
// Gets its last attribute, if any // Gets its last attribute, if any
m_CurrentAttribute = (fsTiXmlAttribute*)pNode->LastAttribute(); m_CurrentAttribute = pNode->FirstAttribute();
while (m_CurrentAttribute->Next() != NULL)
{
m_CurrentAttribute = m_CurrentAttribute->Next();
}
if(!m_CurrentAttribute) if(!m_CurrentAttribute)
{ {
return StringTable->EmptyString(); return StringTable->EmptyString();
@ -708,7 +712,7 @@ const char* SimXMLDocument::nextAttribute()
} }
// Gets its next attribute, if any // Gets its next attribute, if any
m_CurrentAttribute = (fsTiXmlAttribute*)m_CurrentAttribute->Next(); m_CurrentAttribute = m_CurrentAttribute->Next();
if(!m_CurrentAttribute) if(!m_CurrentAttribute)
{ {
return StringTable->EmptyString(); return StringTable->EmptyString();
@ -733,13 +737,29 @@ DefineEngineMethod( SimXMLDocument, nextAttribute, const char*, (),,
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
const char* SimXMLDocument::prevAttribute() const char* SimXMLDocument::prevAttribute()
{ {
// Get the current element
if (m_paNode.empty())
{
return StringTable->EmptyString();
}
const S32 iLastElement = m_paNode.size() - 1;
tinyxml2::XMLElement* pNode = m_paNode[iLastElement]->ToElement();
if (!pNode)
{
return StringTable->EmptyString();
}
if(!m_CurrentAttribute) if(!m_CurrentAttribute)
{ {
return StringTable->EmptyString(); return StringTable->EmptyString();
} }
// Gets its next attribute, if any // Gets its next attribute, if any
m_CurrentAttribute = (fsTiXmlAttribute*)m_CurrentAttribute->Previous(); while (m_CurrentAttribute != NULL && m_CurrentAttribute->Next() != m_CurrentAttribute)
{
m_CurrentAttribute = m_CurrentAttribute->Next();
}
if(!m_CurrentAttribute) if(!m_CurrentAttribute)
{ {
return StringTable->EmptyString(); return StringTable->EmptyString();
@ -769,7 +789,7 @@ void SimXMLDocument::setAttribute(const char* rAttribute, const char* rVal)
} }
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pElement = m_paNode[iLastElement]; tinyxml2::XMLElement* pElement = m_paNode[iLastElement]->ToElement();
if(!pElement) if(!pElement)
{ {
return; return;
@ -801,13 +821,13 @@ void SimXMLDocument::setObjectAttributes(const char* objectID)
return; return;
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pElement = m_paNode[iLastElement]; tinyxml2::XMLElement* pElement = m_paNode[iLastElement]->ToElement();
if(!pElement) if(!pElement)
return; return;
char textbuf[1024]; char textbuf[1024];
fsTiXmlElement field( "Field" ); tinyxml2::XMLElement* field = m_qDocument->NewElement("Field");
fsTiXmlElement group( "FieldGroup" ); tinyxml2::XMLElement* group = m_qDocument->NewElement("FieldGroup");
pElement->SetAttribute( "Name", pObject->getName() ); pElement->SetAttribute( "Name", pObject->getName() );
@ -847,13 +867,13 @@ void SimXMLDocument::setObjectAttributes(const char* objectID)
if( !pObject->writeField( itr->pFieldname, textbuf ) ) if( !pObject->writeField( itr->pFieldname, textbuf ) )
continue; continue;
field.SetValue( "Property" ); field->SetValue( "Property" );
field.SetAttribute( "name", itr->pFieldname ); field->SetAttribute( "name", itr->pFieldname );
if( cbt != NULL ) if( cbt != NULL )
field.SetAttribute( "type", cbt->getTypeName() ); field->SetAttribute( "type", cbt->getTypeName() );
else else
field.SetAttribute( "type", "TypeString" ); field->SetAttribute( "type", "TypeString" );
field.SetAttribute( "data", textbuf ); field->SetAttribute( "data", textbuf );
pElement->InsertEndChild( field ); pElement->InsertEndChild( field );
@ -918,23 +938,21 @@ DefineEngineMethod( SimXMLDocument, setObjectAttributes, void, ( const char* obj
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void SimXMLDocument::pushNewElement(const char* rName) void SimXMLDocument::pushNewElement(const char* rName)
{ {
fsTiXmlElement cElement( rName ); tinyxml2::XMLElement* cElement = m_qDocument->NewElement( rName );
fsTiXmlElement* pStackTop = 0; tinyxml2::XMLNode* pStackTop = 0;
if(m_paNode.empty()) if(m_paNode.empty())
{ {
pStackTop = dynamic_cast<fsTiXmlElement*> pStackTop = m_qDocument->InsertEndChild(cElement);
(m_qDocument->InsertEndChild( cElement ) );
} }
else else
{ {
const S32 iFinalElement = m_paNode.size() - 1; const S32 iFinalElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iFinalElement]; tinyxml2::XMLNode *pNode = m_paNode[iFinalElement];
if(!pNode) if(!pNode)
{ {
return; return;
} }
pStackTop = dynamic_cast<fsTiXmlElement*> pStackTop = pNode->InsertEndChild( cElement );
(pNode->InsertEndChild( cElement ));
} }
if(!pStackTop) if(!pStackTop)
{ {
@ -962,13 +980,12 @@ DefineEngineMethod( SimXMLDocument, pushNewElement, void, ( const char* name ),,
// New element is placed on top of element stack. // New element is placed on top of element stack.
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void SimXMLDocument::addNewElement(const char* rName) void SimXMLDocument::addNewElement(const char* rName)
{ {
fsTiXmlElement cElement( rName ); tinyxml2::XMLElement* cElement = m_qDocument->NewElement(rName);
fsTiXmlElement* pStackTop = 0; tinyxml2::XMLNode* pStackTop = 0;
if(m_paNode.empty()) if(m_paNode.empty())
{ {
pStackTop = dynamic_cast<fsTiXmlElement*> pStackTop = m_qDocument->InsertEndChild( cElement );
(m_qDocument->InsertEndChild( cElement ));
if(!pStackTop) if(!pStackTop)
{ {
return; return;
@ -980,8 +997,7 @@ void SimXMLDocument::addNewElement(const char* rName)
const S32 iParentElement = m_paNode.size() - 2; const S32 iParentElement = m_paNode.size() - 2;
if(iParentElement < 0) if(iParentElement < 0)
{ {
pStackTop = dynamic_cast<fsTiXmlElement*> pStackTop = m_qDocument->InsertEndChild( cElement );
(m_qDocument->InsertEndChild( cElement ));
if(!pStackTop) if(!pStackTop)
{ {
return; return;
@ -991,13 +1007,12 @@ void SimXMLDocument::addNewElement(const char* rName)
} }
else else
{ {
fsTiXmlElement* pNode = m_paNode[iParentElement]; tinyxml2::XMLNode* pNode = m_paNode[iParentElement];
if(!pNode) if(!pNode)
{ {
return; return;
} }
pStackTop = dynamic_cast<fsTiXmlElement*> pStackTop = pNode->InsertEndChild( cElement );
(pNode->InsertEndChild( cElement ));
if(!pStackTop) if(!pStackTop)
{ {
return; return;
@ -1030,7 +1045,7 @@ DefineEngineMethod( SimXMLDocument, addNewElement, void, ( const char* name ),,
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void SimXMLDocument::addHeader(void) void SimXMLDocument::addHeader(void)
{ {
fsTiXmlDeclaration cDeclaration("1.0", "utf-8", "yes"); tinyxml2::XMLDeclaration* cDeclaration = m_qDocument->NewDeclaration("xml version=\"1.0\" encoding=\"UTF-8\" standalone =\"yes\"");
m_qDocument->InsertEndChild(cDeclaration); m_qDocument->InsertEndChild(cDeclaration);
} }
@ -1058,8 +1073,8 @@ DefineEngineMethod( SimXMLDocument, addHeader, void, (),,
void SimXMLDocument::addComment(const char* comment) void SimXMLDocument::addComment(const char* comment)
{ {
fsTiXmlComment cComment; tinyxml2::XMLComment* cComment = m_qDocument->NewComment(comment);
cComment.SetValue(comment); cComment->SetValue(comment);
m_qDocument->InsertEndChild(cComment); m_qDocument->InsertEndChild(cComment);
} }
@ -1094,12 +1109,12 @@ const char* SimXMLDocument::readComment( S32 index )
if(!m_paNode.empty()) if(!m_paNode.empty())
{ {
const S32 iLastElement = m_paNode.size() - 1; const S32 iLastElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iLastElement]; tinyxml2::XMLNode* pNode = m_paNode[iLastElement];
if(!pNode) if(!pNode)
{ {
return ""; return "";
} }
TiXmlNode* node = pNode->FirstChild(); tinyxml2::XMLNode* node = pNode->FirstChild();
for( S32 i = 0; i < index; i++ ) for( S32 i = 0; i < index; i++ )
{ {
if( !node ) if( !node )
@ -1110,7 +1125,7 @@ const char* SimXMLDocument::readComment( S32 index )
if( node ) if( node )
{ {
TiXmlComment* comment = node->ToComment(); tinyxml2::XMLComment* comment = node->ToComment();
if( comment ) if( comment )
return comment->Value(); return comment->Value();
} }
@ -1121,7 +1136,7 @@ const char* SimXMLDocument::readComment( S32 index )
{ {
return ""; return "";
} }
TiXmlNode* node = m_qDocument->FirstChild(); tinyxml2::XMLNode* node = m_qDocument->FirstChild();
for( S32 i = 0; i < index; i++ ) for( S32 i = 0; i < index; i++ )
{ {
if( !node ) if( !node )
@ -1132,7 +1147,7 @@ const char* SimXMLDocument::readComment( S32 index )
if( node ) if( node )
{ {
TiXmlComment* comment = node->ToComment(); tinyxml2::XMLComment* comment = node->ToComment();
if( comment ) if( comment )
return comment->Value(); return comment->Value();
} }
@ -1162,11 +1177,11 @@ void SimXMLDocument::addText(const char* text)
return; return;
const S32 iFinalElement = m_paNode.size() - 1; const S32 iFinalElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iFinalElement]; tinyxml2::XMLNode* pNode = m_paNode[iFinalElement];
if(!pNode) if(!pNode)
return; return;
fsTiXmlText cText(text); tinyxml2::XMLText* cText = m_qDocument->NewText(text);
pNode->InsertEndChild( cText ); pNode->InsertEndChild( cText );
} }
@ -1207,14 +1222,14 @@ const char* SimXMLDocument::getText()
return ""; return "";
const S32 iFinalElement = m_paNode.size() - 1; const S32 iFinalElement = m_paNode.size() - 1;
TiXmlNode* pNode = m_paNode[iFinalElement]; tinyxml2::XMLNode* pNode = m_paNode[iFinalElement];
if(!pNode) if(!pNode)
return ""; return "";
if(!pNode->FirstChild()) if(!pNode->FirstChild())
return ""; return "";
fsTiXmlText* text = (fsTiXmlText*)pNode->FirstChild()->ToText(); tinyxml2::XMLText* text = pNode->FirstChild()->ToText();
if( !text ) if( !text )
return ""; return "";
@ -1267,18 +1282,18 @@ void SimXMLDocument::removeText()
return; return;
const S32 iFinalElement = m_paNode.size() - 1; const S32 iFinalElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iFinalElement]; tinyxml2::XMLNode* pNode = m_paNode[iFinalElement];
if(!pNode) if(!pNode)
return; return;
if( !pNode->FirstChild() ) if( !pNode->FirstChild() )
return; return;
fsTiXmlText* text = (fsTiXmlText*)pNode->FirstChild()->ToText(); tinyxml2::XMLText* text = pNode->FirstChild()->ToText();
if( !text ) if( !text )
return; return;
pNode->RemoveChild(text); pNode->DeleteChild(text);
} }
DefineEngineMethod( SimXMLDocument, removeText, void, (),, DefineEngineMethod( SimXMLDocument, removeText, void, (),,
@ -1303,11 +1318,11 @@ void SimXMLDocument::addData(const char* text)
return; return;
const S32 iFinalElement = m_paNode.size() - 1; const S32 iFinalElement = m_paNode.size() - 1;
fsTiXmlElement* pNode = m_paNode[iFinalElement]; tinyxml2::XMLNode* pNode = m_paNode[iFinalElement];
if(!pNode) if(!pNode)
return; return;
fsTiXmlText cText(text); tinyxml2::XMLText* cText = m_qDocument->NewText(text);
pNode->InsertEndChild( cText ); pNode->InsertEndChild( cText );
} }
@ -1349,14 +1364,14 @@ const char* SimXMLDocument::getData()
return ""; return "";
const S32 iFinalElement = m_paNode.size() - 1; const S32 iFinalElement = m_paNode.size() - 1;
TiXmlNode* pNode = m_paNode[iFinalElement]; tinyxml2::XMLNode* pNode = m_paNode[iFinalElement];
if(!pNode) if(!pNode)
return ""; return "";
if( !pNode->FirstChild() ) if( !pNode->FirstChild() )
return ""; return "";
TiXmlText* text = pNode->FirstChild()->ToText(); tinyxml2::XMLText* text = pNode->FirstChild()->ToText();
if( !text ) if( !text )
return ""; return "";

View file

@ -35,11 +35,10 @@
#include "core/util/tVector.h" #include "core/util/tVector.h"
#endif // _TVECTOR_H_ #endif // _TVECTOR_H_
#ifndef TINYXML2_INCLUDED
class fsTiXmlDocument; #include <tinyxml2.h>
class fsTiXmlElement; #endif // TINYXML2_INCLUDED
class fsTiXmlAttribute; #include "persistence/taml/fsTinyXml.h"
class SimXMLDocument: public SimObject class SimXMLDocument: public SimObject
{ {
@ -136,11 +135,11 @@ class SimXMLDocument: public SimObject
private: private:
// Document. // Document.
fsTiXmlDocument* m_qDocument; VfsXMLDocument* m_qDocument;
// Stack of nodes. // Stack of nodes.
Vector<fsTiXmlElement*> m_paNode; Vector<tinyxml2::XMLNode*> m_paNode;
// The current attribute // The current attribute
fsTiXmlAttribute* m_CurrentAttribute; const tinyxml2::XMLAttribute* m_CurrentAttribute;
public: public:
DECLARE_CONOBJECT(SimXMLDocument); DECLARE_CONOBJECT(SimXMLDocument);

View file

@ -52,7 +52,7 @@
#include "console/simObjectRef.h" #include "console/simObjectRef.h"
#endif #endif
#ifndef TINYXML_INCLUDED #ifndef TINYXML_INCLUDED
#include "tinyxml.h" #include "tinyxml2.h"
#endif #endif
/// @file /// @file
@ -208,7 +208,7 @@ public:
typedef ConsoleBaseType Parent; typedef ConsoleBaseType Parent;
/// Allows the writing of a custom TAML schema. /// Allows the writing of a custom TAML schema.
typedef void(*WriteCustomTamlSchema)(const AbstractClassRep* pClassRep, TiXmlElement* pParentElement); typedef void(*WriteCustomTamlSchema)(const AbstractClassRep* pClassRep, tinyxml2::XMLElement* pParentElement);
/// @name 'Tructors /// @name 'Tructors
/// @{ /// @{

View file

@ -21,13 +21,16 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "fsTinyXml.h" #include "fsTinyXml.h"
#include <cassert>
#include "console/console.h" #include "console/console.h"
bool fsTiXmlDocument::LoadFile( const char * pFilename, TiXmlEncoding encoding ) bool VfsXMLDocument::LoadFile(const char* pFilename)
{ {
// Expand the file-path. // Expand the file-path.
char filenameBuffer[1024]; char filenameBuffer[1024];
Con::expandScriptFilename( filenameBuffer, sizeof(filenameBuffer), pFilename ); Con::expandScriptFilename(filenameBuffer, sizeof(filenameBuffer), pFilename);
FileStream stream; FileStream stream;
@ -38,15 +41,15 @@ bool fsTiXmlDocument::LoadFile( const char * pFilename, TiXmlEncoding encoding )
#endif #endif
// File open for read? // File open for read?
if ( !stream.open( filenameBuffer, Torque::FS::File::Read ) ) if (!stream.open(filenameBuffer, Torque::FS::File::Read))
{ {
// No, so warn. // No, so warn.
Con::warnf("TamlXmlParser::parse() - Could not open filename '%s' for parse.", filenameBuffer ); Con::warnf("TamlXmlParser::parse() - Could not open filename '%s' for parse.", filenameBuffer);
return false; return false;
} }
// Load document from stream. // Load document from stream.
if ( !LoadFile( stream ) ) if (!LoadFile(stream))
{ {
// Warn! // Warn!
Con::warnf("TamlXmlParser: Could not load Taml XML file from stream."); Con::warnf("TamlXmlParser: Could not load Taml XML file from stream.");
@ -58,7 +61,7 @@ bool fsTiXmlDocument::LoadFile( const char * pFilename, TiXmlEncoding encoding )
return true; return true;
} }
bool fsTiXmlDocument::SaveFile( const char * pFilename ) const bool VfsXMLDocument::SaveFile(const char* pFilename)
{ {
// Expand the file-name into the file-path buffer. // Expand the file-name into the file-path buffer.
char filenameBuffer[1024]; char filenameBuffer[1024];
@ -67,10 +70,10 @@ bool fsTiXmlDocument::SaveFile( const char * pFilename ) const
FileStream stream; FileStream stream;
// File opened? // File opened?
if ( !stream.open( filenameBuffer, Torque::FS::File::Write ) ) if (!stream.open(filenameBuffer, Torque::FS::File::Write))
{ {
// No, so warn. // No, so warn.
Con::warnf("Taml::writeFile() - Could not open filename '%s' for write.", filenameBuffer ); Con::warnf("Taml::writeFile() - Could not open filename '%s' for write.", filenameBuffer);
return false; return false;
} }
@ -80,10 +83,80 @@ bool fsTiXmlDocument::SaveFile( const char * pFilename ) const
return ret; return ret;
} }
bool fsTiXmlDocument::LoadFile( FileStream &stream, TiXmlEncoding encoding ) void VfsXMLDocument::ClearError()
{
_errorID = tinyxml2::XML_SUCCESS;
_errorLineNum = 0;
_errorStr.Reset();
tinyxml2::XMLDocument::ClearError();
}
void VfsXMLDocument::SetError(tinyxml2::XMLError error, int lineNum, const char* format, ...)
{
TIXMLASSERT(error >= 0 && error < tinyxml2::XML_ERROR_COUNT);
_errorID = error;
_errorLineNum = lineNum;
_errorStr.Reset();
const size_t BUFFER_SIZE = 1000;
char* buffer = new char[BUFFER_SIZE];
TIXMLASSERT(sizeof(error) <= sizeof(int));
dSprintf(buffer, BUFFER_SIZE, "Error=%s ErrorID=%d (0x%x) Line number=%d", ErrorIDToName(error), int(error), int(error), lineNum);
if (format) {
size_t len = strlen(buffer);
dSprintf(buffer + len, BUFFER_SIZE - len, ": ");
len = strlen(buffer);
va_list va;
va_start(va, format);
dSprintf(buffer + len, BUFFER_SIZE - len, format, va);
va_end(va);
}
_errorStr.SetStr(buffer);
delete[] buffer;
}
VfsXMLPrinter::VfsXMLPrinter(FileStream& stream, bool compact, int depth)
: XMLPrinter(NULL, compact, depth),
m_Stream(stream)
{
}
VfsXMLPrinter::~VfsXMLPrinter()
{
m_Stream.flush();
m_Stream.close();
}
void VfsXMLPrinter::Print(const char* format, ...)
{
va_list va;
va_start(va, format);
m_Stream.writeFormattedBuffer(format, va);
va_end(va);
}
void VfsXMLPrinter::Write(const char* data, size_t size)
{
m_Stream.write(size, data);
}
void VfsXMLPrinter::Putc(char ch)
{
m_Stream.write(static_cast<U8>(ch));
}
bool VfsXMLDocument::LoadFile(FileStream& stream)
{ {
// Delete the existing data: // Delete the existing data:
Clear(); Clear();
// Clear shadowed error
ClearError();
//TODO: Can't clear location, investigate if this gives issues. //TODO: Can't clear location, investigate if this gives issues.
//doc.location.Clear(); //doc.location.Clear();
@ -91,9 +164,9 @@ bool fsTiXmlDocument::LoadFile( FileStream &stream, TiXmlEncoding encoding )
long length = stream.getStreamSize(); long length = stream.getStreamSize();
// Strange case, but good to handle up front. // Strange case, but good to handle up front.
if ( length <= 0 ) if (length <= 0)
{ {
SetError( TiXmlDocument::TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN ); SetError(tinyxml2::XML_ERROR_EMPTY_DOCUMENT, 0, 0);
return false; return false;
} }
@ -118,12 +191,13 @@ bool fsTiXmlDocument::LoadFile( FileStream &stream, TiXmlEncoding encoding )
} }
*/ */
char* buf = new char[ length+1 ]; char* buf = new char[length + 1];
buf[0] = 0; buf[0] = 0;
if ( !stream.read( length, buf ) ) { if (!stream.read(length, buf))
{
delete [] buf; delete [] buf;
SetError( TiXmlDocument::TIXML_ERROR_OPENING_FILE, 0, 0, TIXML_ENCODING_UNKNOWN ); SetError(tinyxml2::XML_ERROR_FILE_COULD_NOT_BE_OPENED, 0, 0);
return false; return false;
} }
@ -138,610 +212,48 @@ bool fsTiXmlDocument::LoadFile( FileStream &stream, TiXmlEncoding encoding )
// * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS // * CR+LF: DEC RT-11 and most other early non-Unix, non-IBM OSes, CP/M, MP/M, DOS, OS/2, Microsoft Windows, Symbian OS
// * CR: Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9 // * CR: Commodore 8-bit machines, Apple II family, Mac OS up to version 9 and OS-9
const char* p = buf; // the read head const char* p = buf; // the read head
char* q = buf; // the write head char* q = buf; // the write head
const char CR = 0x0d; const char CR = 0x0d;
const char LF = 0x0a; const char LF = 0x0a;
buf[length] = 0; buf[length] = 0;
while( *p ) { while (*p)
assert( p < (buf+length) ); {
assert( q <= (buf+length) ); assert(p < (buf+length));
assert( q <= p ); assert(q <= (buf+length));
assert(q <= p);
if ( *p == CR ) { if (*p == CR)
{
*q++ = LF; *q++ = LF;
p++; p++;
if ( *p == LF ) { // check for CR+LF (and skip LF) if (*p == LF)
{
// check for CR+LF (and skip LF)
p++; p++;
} }
} }
else { else
{
*q++ = *p++; *q++ = *p++;
} }
} }
assert( q <= (buf+length) ); assert(q <= (buf+length));
*q = 0; *q = 0;
Parse( buf, 0, encoding ); Parse(buf, length);
delete [] buf; delete [] buf;
return !Error(); return !Error();
} }
bool fsTiXmlDocument::SaveFile( FileStream &stream ) const bool VfsXMLDocument::SaveFile(FileStream& stream)
{ {
if ( useMicrosoftBOM ) // Clear any error from the last save, otherwise it will get reported
{ // for *this* call.
const unsigned char TIXML_UTF_LEAD_0 = 0xefU; ClearError();
const unsigned char TIXML_UTF_LEAD_1 = 0xbbU; VfsXMLPrinter printer(stream, false, 0);
const unsigned char TIXML_UTF_LEAD_2 = 0xbfU; Print(&printer);
return !Error();
stream.write( TIXML_UTF_LEAD_0 );
stream.write( TIXML_UTF_LEAD_1 );
stream.write( TIXML_UTF_LEAD_2 );
}
Print( stream, 0 );
return true;
} }
void fsTiXmlDocument::Print( FileStream& stream, int depth ) const
{
for ( const TiXmlNode* node=FirstChild(); node; node=node->NextSibling() )
{
//AttemptPrintTiNode(const_cast<TiXmlNode*>(node), stream, depth);
dynamic_cast<const fsTiXmlNode*>(node)->Print( stream, depth );
stream.writeText( "\n" );
}
}
void fsTiXmlAttribute::Print( FileStream& stream, int depth, TIXML_STRING* str ) const
{
TIXML_STRING n, v;
TiXmlString val = TiXmlString(Value());
EncodeString( NameTStr(), &n );
EncodeString( val, &v );
for ( int i=0; i< depth; i++ ) {
stream.writeText( " " );
}
if (val.find ('\"') == TIXML_STRING::npos) {
const char* pValue = v.c_str();
char buffer[4096];
const S32 length = dSprintf(buffer, sizeof(buffer), "%s=\"%s\"", n.c_str(), pValue);
stream.write(length, buffer);
if ( str ) {
(*str) += n; (*str) += "=\""; (*str) += v; (*str) += "\"";
}
}
else {
char buffer[4096];
const S32 length = dSprintf(buffer, sizeof(buffer), "%s='%s'", n.c_str(), v.c_str());
stream.write(length, buffer);
if ( str ) {
(*str) += n; (*str) += "='"; (*str) += v; (*str) += "'";
}
}
}
void fsTiXmlDeclaration::Print(FileStream& stream, int depth, TiXmlString* str) const
{
stream.writeStringBuffer( "<?xml " );
if ( str ) (*str) += "<?xml ";
if ( !version.empty() ) {
stream.writeFormattedBuffer( "version=\"%s\" ", version.c_str ());
if ( str ) { (*str) += "version=\""; (*str) += version; (*str) += "\" "; }
}
if ( !encoding.empty() ) {
stream.writeFormattedBuffer( "encoding=\"%s\" ", encoding.c_str ());
if ( str ) { (*str) += "encoding=\""; (*str) += encoding; (*str) += "\" "; }
}
if ( !standalone.empty() ) {
stream.writeFormattedBuffer( "standalone=\"%s\" ", standalone.c_str ());
if ( str ) { (*str) += "standalone=\""; (*str) += standalone; (*str) += "\" "; }
}
stream.writeStringBuffer( "?>" );
if ( str ) (*str) += "?>";
}
void fsTiXmlElement::Print(FileStream& stream, int depth) const
{
int i;
for ( i=0; i<depth; i++ ) {
stream.writeStringBuffer( " " );
}
stream.writeFormattedBuffer( "<%s", value.c_str() );
const TiXmlAttribute* attrib;
for ( attrib = attributeSet.First(); attrib; attrib = attrib->Next() )
{
stream.writeStringBuffer( "\n" );
dynamic_cast<const fsTiXmlAttribute*>(attrib)->Print( stream, depth+1 );
}
// There are 3 different formatting approaches:
// 1) An element without children is printed as a <foo /> node
// 2) An element with only a text child is printed as <foo> text </foo>
// 3) An element with children is printed on multiple lines.
TiXmlNode* node;
if ( !firstChild )
{
stream.writeStringBuffer( " />" );
}
else if ( firstChild == lastChild && firstChild->ToText() )
{
stream.writeStringBuffer( ">" );
dynamic_cast<const fsTiXmlNode*>(firstChild)->Print( stream, depth + 1 );
stream.writeFormattedBuffer( "</%s>", value.c_str() );
}
else
{
stream.writeStringBuffer( ">" );
for ( node = firstChild; node; node=node->NextSibling() )
{
if ( !node->ToText() )
{
stream.writeStringBuffer( "\n" );
}
dynamic_cast<const fsTiXmlNode*>(node)->Print( stream, depth+1 );
}
stream.writeStringBuffer( "\n" );
for( i=0; i<depth; ++i ) {
stream.writeStringBuffer( " " );
}
stream.writeFormattedBuffer( "</%s>", value.c_str() );
}
}
void fsTiXmlComment::Print(FileStream& stream, int depth) const
{
for ( int i=0; i<depth; i++ )
{
stream.writeStringBuffer( " " );
}
stream.writeFormattedBuffer( "<!--%s-->", value.c_str() );
}
void fsTiXmlText::Print(FileStream& stream, int depth) const
{
if ( cdata )
{
int i;
stream.writeStringBuffer( "\n" );
for ( i=0; i<depth; i++ ) {
stream.writeStringBuffer( " " );
}
stream.writeFormattedBuffer( "<![CDATA[%s]]>\n", value.c_str() ); // unformatted output
}
else
{
TIXML_STRING buffer;
EncodeString( value, &buffer );
stream.writeFormattedBuffer( "%s", buffer.c_str() );
}
}
void fsTiXmlUnknown::Print(FileStream& stream, int depth) const
{
for ( int i=0; i<depth; i++ )
stream.writeStringBuffer( " " );
stream.writeFormattedBuffer( "<%s>", value.c_str() );
}
static TiXmlNode* TiNodeIdentify( TiXmlNode* parent, const char* p, TiXmlEncoding encoding )
{
TiXmlNode* returnNode = 0;
p = TiXmlNode::SkipWhiteSpace( p, encoding );
if( !p || !*p || *p != '<' )
{
return 0;
}
p = TiXmlNode::SkipWhiteSpace( p, encoding );
if ( !p || !*p )
{
return 0;
}
// What is this thing?
// - Elements start with a letter or underscore, but xml is reserved.
// - Comments: <!--
// - Decleration: <?xml
// - Everthing else is unknown to tinyxml.
//
const char* xmlHeader = { "<?xml" };
const char* commentHeader = { "<!--" };
const char* dtdHeader = { "<!" };
const char* cdataHeader = { "<![CDATA[" };
if ( TiXmlNode::StringEqual( p, xmlHeader, true, encoding ) )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Declaration\n" );
#endif
returnNode = new fsTiXmlDeclaration();
}
else if ( TiXmlNode::StringEqual( p, commentHeader, false, encoding ) )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Comment\n" );
#endif
returnNode = new fsTiXmlComment();
}
else if ( TiXmlNode::StringEqual( p, cdataHeader, false, encoding ) )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing CDATA\n" );
#endif
TiXmlText* text = new fsTiXmlText( "" );
text->SetCDATA( true );
returnNode = text;
}
else if ( TiXmlNode::StringEqual( p, dtdHeader, false, encoding ) )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Unknown(1)\n" );
#endif
returnNode = new fsTiXmlUnknown();
}
else if ( TiXmlNode::IsAlpha( *(p+1), encoding )
|| *(p+1) == '_' )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Element\n" );
#endif
returnNode = new fsTiXmlElement( "" );
}
else
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Unknown(2)\n" );
#endif
returnNode = new fsTiXmlUnknown();
}
if ( returnNode )
{
// Set the parent, so it can report errors
returnNode->parent = parent;
}
return returnNode;
}
TiXmlNode* fsTiXmlDocument::Identify( const char* p, TiXmlEncoding encoding )
{
return TiNodeIdentify(this, p, encoding);
}
TiXmlNode* fsTiXmlElement::Identify( const char* p, TiXmlEncoding encoding )
{
return TiNodeIdentify(this, p, encoding);
}
const char* fsTiXmlElement::Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding )
{
p = SkipWhiteSpace( p, encoding );
TiXmlDocument* document = GetDocument();
if ( !p || !*p )
{
if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, 0, 0, encoding );
return 0;
}
if ( data )
{
data->Stamp( p, encoding );
location = data->Cursor();
}
if ( *p != '<' )
{
if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, p, data, encoding );
return 0;
}
p = SkipWhiteSpace( p+1, encoding );
// Read the name.
const char* pErr = p;
p = ReadName( p, &value, encoding );
if ( !p || !*p )
{
if ( document ) document->SetError( TIXML_ERROR_FAILED_TO_READ_ELEMENT_NAME, pErr, data, encoding );
return 0;
}
TIXML_STRING endTag ("</");
endTag += value;
// Check for and read attributes. Also look for an empty
// tag or an end tag.
while ( p && *p )
{
pErr = p;
p = SkipWhiteSpace( p, encoding );
if ( !p || !*p )
{
if ( document ) document->SetError( TIXML_ERROR_READING_ATTRIBUTES, pErr, data, encoding );
return 0;
}
if ( *p == '/' )
{
++p;
// Empty tag.
if ( *p != '>' )
{
if ( document ) document->SetError( TIXML_ERROR_PARSING_EMPTY, p, data, encoding );
return 0;
}
return (p+1);
}
else if ( *p == '>' )
{
// Done with attributes (if there were any.)
// Read the value -- which can include other
// elements -- read the end tag, and return.
++p;
p = ReadValue( p, data, encoding ); // Note this is an Element method, and will set the error if one happens.
if ( !p || !*p ) {
// We were looking for the end tag, but found nothing.
// Fix for [ 1663758 ] Failure to report error on bad XML
if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
return 0;
}
// We should find the end tag now
// note that:
// </foo > and
// </foo>
// are both valid end tags.
if ( StringEqual( p, endTag.c_str(), false, encoding ) )
{
p += endTag.length();
p = SkipWhiteSpace( p, encoding );
if ( p && *p && *p == '>' ) {
++p;
return p;
}
if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
return 0;
}
else
{
if ( document ) document->SetError( TIXML_ERROR_READING_END_TAG, p, data, encoding );
return 0;
}
}
else
{
// Try to read an attribute:
TiXmlAttribute* attrib = new fsTiXmlAttribute();
if ( !attrib )
{
return 0;
}
attrib->SetDocument( document );
pErr = p;
p = attrib->Parse( p, data, encoding );
if ( !p || !*p )
{
if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
delete attrib;
return 0;
}
// Handle the strange case of double attributes:
#ifdef TIXML_USE_STL
TiXmlAttribute* node = attributeSet.Find( attrib->NameTStr() );
#else
TiXmlAttribute* node = attributeSet.Find( attrib->Name() );
#endif
if ( node )
{
if ( document ) document->SetError( TIXML_ERROR_PARSING_ELEMENT, pErr, data, encoding );
delete attrib;
return 0;
}
attributeSet.Add( attrib );
}
}
return p;
}
/*
TiXmlNode* fsTiXmlNode::Identify(char const* p, TiXmlEncoding encoding)
{
TiXmlNode* returnNode = 0;
p = TiXmlBase::SkipWhiteSpace( p, encoding );
if( !p || !*p || *p != '<' )
{
return 0;
}
p = TiXmlBase::SkipWhiteSpace( p, encoding );
if ( !p || !*p )
{
return 0;
}
// What is this thing?
// - Elements start with a letter or underscore, but xml is reserved.
// - Comments: <!--
// - Decleration: <?xml
// - Everthing else is unknown to tinyxml.
//
const char* xmlHeader = { "<?xml" };
const char* commentHeader = { "<!--" };
const char* dtdHeader = { "<!" };
const char* cdataHeader = { "<![CDATA[" };
if ( TiXmlBase::StringEqual( p, xmlHeader, true, encoding ) )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Declaration\n" );
#endif
returnNode = new fsTiXmlDeclaration();
}
else if ( TiXmlBase::StringEqual( p, commentHeader, false, encoding ) )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Comment\n" );
#endif
returnNode = new fsTiXmlComment();
}
else if ( TiXmlBase::StringEqual( p, cdataHeader, false, encoding ) )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing CDATA\n" );
#endif
fsTiXmlText* text = new fsTiXmlText( "" );
text->SetCDATA( true );
returnNode = text;
}
else if ( TiXmlBase::StringEqual( p, dtdHeader, false, encoding ) )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Unknown(1)\n" );
#endif
returnNode = new fsTiXmlUnknown();
}
else if ( TiXmlBase::IsAlpha( *(p+1), encoding )
|| *(p+1) == '_' )
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Element\n" );
#endif
returnNode = new fsTiXmlElement( "" );
}
else
{
#ifdef DEBUG_PARSER
TIXML_LOG( "XML parsing Unknown(2)\n" );
#endif
returnNode = new fsTiXmlUnknown();
}
if ( returnNode )
{
// Set the parent, so it can report errors
returnNode->parent = this;
}
return returnNode;
}
const unsigned char TIXML_UTF_LEAD_0 = 0xefU;
const unsigned char TIXML_UTF_LEAD_1 = 0xbbU;
const unsigned char TIXML_UTF_LEAD_2 = 0xbfU;
char const* fsTiXmlDocument::Parse(char const* p, TiXmlParsingData* prevData, TiXmlEncoding encoding)
{
ClearError();
// Parse away, at the document level. Since a document
// contains nothing but other tags, most of what happens
// here is skipping white space.
if ( !p || !*p )
{
SetError( TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
// Note that, for a document, this needs to come
// before the while space skip, so that parsing
// starts from the pointer we are given.
location.Clear();
if ( prevData )
{
location.row = prevData->Cursor().row;
location.col = prevData->Cursor().col;
}
else
{
location.row = 0;
location.col = 0;
}
TiXmlParsingData data( p, TabSize(), location.row, location.col );
location = data.Cursor();
if ( encoding == TIXML_ENCODING_UNKNOWN )
{
// Check for the Microsoft UTF-8 lead bytes.
const unsigned char* pU = (const unsigned char*)p;
if ( *(pU+0) && *(pU+0) == TIXML_UTF_LEAD_0
&& *(pU+1) && *(pU+1) == TIXML_UTF_LEAD_1
&& *(pU+2) && *(pU+2) == TIXML_UTF_LEAD_2 )
{
encoding = TIXML_ENCODING_UTF8;
useMicrosoftBOM = true;
}
}
p = TiXmlBase::SkipWhiteSpace( p, encoding );
if ( !p )
{
SetError( TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, TIXML_ENCODING_UNKNOWN );
return 0;
}
while ( p && *p )
{
TiXmlNode* node = fsTiXmlNode::Identify( p, encoding );
if ( node )
{
p = node->Parse( p, &data, encoding );
LinkEndChild( node );
}
else
{
break;
}
// Did we get encoding info?
if ( encoding == TIXML_ENCODING_UNKNOWN
&& node->ToDeclaration() )
{
TiXmlDeclaration* dec = node->ToDeclaration();
const char* enc = dec->Encoding();
assert( enc );
if ( *enc == 0 )
encoding = TIXML_ENCODING_UTF8;
else if ( TiXmlBase::StringEqual( enc, "UTF-8", true, TIXML_ENCODING_UNKNOWN ) )
encoding = TIXML_ENCODING_UTF8;
else if ( TiXmlBase::StringEqual( enc, "UTF8", true, TIXML_ENCODING_UNKNOWN ) )
encoding = TIXML_ENCODING_UTF8; // incorrect, but be nice
else
encoding = TIXML_ENCODING_LEGACY;
}
p = TiXmlBase::SkipWhiteSpace( p, encoding );
}
// Was this empty?
if ( !firstChild ) {
SetError( TiXmlBase::TIXML_ERROR_DOCUMENT_EMPTY, 0, 0, encoding );
return 0;
}
// All is well.
return p;
}
*/

View file

@ -25,7 +25,7 @@
#ifndef TINYXML_INCLUDED #ifndef TINYXML_INCLUDED
#include "tinyxml/tinyxml.h" #include "tinyxml/tinyxml2.h"
#endif #endif
#include "platform/platform.h" #include "platform/platform.h"
@ -34,215 +34,97 @@
#include "core/stream/fileStream.h" #include "core/stream/fileStream.h"
#endif #endif
class fsTiXmlNode class VfsXMLPrinter : public tinyxml2::XMLPrinter
{ {
public: public:
virtual void Print( FileStream& stream, int depth ) const = 0; VfsXMLPrinter(FileStream& stream, bool compact = false, int depth = 0);
~VfsXMLPrinter() override;
void Print(const char* format, ...) override;
void Write(const char* data, size_t size) override;
void Putc(char ch) override;
FileStream& m_Stream;
}; };
class fsTiXmlDocument : public TiXmlDocument, public fsTiXmlNode class VfsXMLDocument : public tinyxml2::XMLDocument
{ {
public: public:
bool LoadFile( FileStream &stream, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); bool LoadFile(FileStream& stream);
bool SaveFile( FileStream &stream ) const; bool SaveFile(FileStream& stream);
/// Load a file using the given filename. Returns true if successful. /// Load a file using the given filename. Returns true if successful.
bool LoadFile( const char * filename, TiXmlEncoding encoding = TIXML_DEFAULT_ENCODING ); bool LoadFile(const char* filename);
/// Save a file using the given filename. Returns true if successful. /// Save a file using the given filename. Returns true if successful.
bool SaveFile( const char * filename ) const; bool SaveFile(const char* filename);
virtual void Print( FileStream& stream, int depth ) const;
virtual TiXmlNode* Clone() const /// Clears the error flags.
void ClearError();
tinyxml2::XMLError _errorID;
mutable tinyxml2::StrPair _errorStr;
int _errorLineNum;
// Create a parallel SetError implementation since it is private in tinyxml2
void SetError(tinyxml2::XMLError error, int lineNum, const char* format, ...);
/// Return true if there was an error parsing the document.
bool Error() const
{ {
TiXmlDocument* clone = new fsTiXmlDocument(); return _errorID != tinyxml2::XML_SUCCESS || XMLDocument::Error();
if ( !clone )
return 0;
CopyTo( clone );
return clone;
}
TiXmlNode* Identify( const char* p, TiXmlEncoding encoding );
};
class fsTiXmlAttribute : public TiXmlAttribute, public fsTiXmlNode
{
public:
virtual void Print( FileStream& stream, int depth, TIXML_STRING* str ) const;
virtual void Print( FileStream& stream, int depth) const
{
Print(stream, depth, 0);
}
};
class fsTiXmlDeclaration : public TiXmlDeclaration, public fsTiXmlNode
{
public:
fsTiXmlDeclaration(){};
fsTiXmlDeclaration( const char* _version,
const char* _encoding,
const char* _standalone ) : TiXmlDeclaration(_version, _encoding, _standalone) { }
virtual void Print( FileStream& stream, int depth, TIXML_STRING* str ) const;
virtual void Print( FileStream& stream, int depth) const
{
Print(stream, depth, 0);
} }
virtual TiXmlNode* Clone() const /// Return the errorID.
tinyxml2::XMLError ErrorID() const
{ {
fsTiXmlDeclaration* clone = new fsTiXmlDeclaration(); if (XMLDocument::Error())
if ( !clone )
return 0;
CopyTo( clone );
return clone;
}
};
class fsTiXmlElement : public TiXmlElement, public fsTiXmlNode
{
public:
fsTiXmlElement(const char* in_value) : TiXmlElement(in_value) { }
virtual void Print( FileStream& stream, int depth ) const;
virtual TiXmlNode* Clone() const
{
TiXmlElement* clone = new fsTiXmlElement( Value() );
if ( !clone )
return 0;
CopyTo( clone );
return clone;
}
void SetAttribute( const char* name, const char * _value )
{
TiXmlAttribute* attrib = attributeSet.Find( name );
if(!attrib)
{ {
attrib = new fsTiXmlAttribute(); return XMLDocument::ErrorID();
attributeSet.Add( attrib );
attrib->SetName( name );
} }
if ( attrib ) { else
attrib->SetValue( _value );
}
}
void SetAttribute( const char * name, int _value)
{
TiXmlAttribute* attrib = attributeSet.Find( name );
if(!attrib)
{ {
attrib = new fsTiXmlAttribute(); return _errorID;
attributeSet.Add( attrib );
attrib->SetName( name );
} }
if ( attrib ) {
attrib->SetIntValue(_value);
}
} }
TiXmlNode* Identify( const char* p, TiXmlEncoding encoding );
virtual const char* Parse( const char* p, TiXmlParsingData* data, TiXmlEncoding encoding );
};
class fsTiXmlComment : public TiXmlComment, public fsTiXmlNode const char* ErrorName() const
{
public:
virtual void Print( FileStream& stream, int depth ) const;
virtual TiXmlNode* Clone() const
{ {
TiXmlComment* clone = new fsTiXmlComment(); if (XMLDocument::Error())
{
return XMLDocument::ErrorName();
}
else
{
return ErrorIDToName(_errorID);
}
}
if ( !clone ) /** Returns a "long form" error description. A hopefully helpful
return 0; diagnostic with location, line number, and/or additional info.
*/
const char* ErrorStr() const
{
if (XMLDocument::Error())
{
return XMLDocument::ErrorStr();
}
else
{
return _errorStr.Empty() ? "" : _errorStr.GetStr();
}
}
CopyTo( clone ); /// Return the line where the error occurred, or zero if unknown.
return clone; int ErrorLineNum() const
{
if (XMLDocument::Error())
{
return XMLDocument::ErrorLineNum();
}
else
{
return _errorLineNum;
}
} }
}; };
class fsTiXmlText : public TiXmlText, public fsTiXmlNode
{
public:
fsTiXmlText (const char * initValue ) : TiXmlText(initValue) { }
virtual void Print( FileStream& stream, int depth ) const;
virtual TiXmlNode* Clone() const
{
TiXmlText* clone = 0;
clone = new fsTiXmlText( "" );
if ( !clone )
return 0;
CopyTo( clone );
return clone;
}
};
class fsTiXmlUnknown : public TiXmlUnknown, public fsTiXmlNode
{
public:
virtual void Print( FileStream& stream, int depth ) const;
virtual TiXmlNode* Clone() const
{
TiXmlUnknown* clone = new fsTiXmlUnknown();
if ( !clone )
return 0;
CopyTo( clone );
return clone;
}
};
static bool AttemptPrintTiNode(class fsTiXmlDocument* node, FileStream& stream, int depth)
{
fsTiXmlDocument* fsDoc = dynamic_cast<fsTiXmlDocument*>(node);
if(fsDoc != NULL)
{
fsDoc->Print(stream, depth);
return true;
}
fsTiXmlUnknown* fsUnk = dynamic_cast<fsTiXmlUnknown*>(node);
if(fsUnk != NULL)
{
fsUnk->Print(stream, depth);
return true;
}
fsTiXmlText* fsTxt = dynamic_cast<fsTiXmlText*>(node);
if(fsTxt != NULL)
{
fsTxt->Print(stream, depth);
return true;
}
fsTiXmlComment* fsCom = dynamic_cast<fsTiXmlComment*>(node);
if(fsCom != NULL)
{
fsCom->Print(stream, depth);
return true;
}
fsTiXmlElement* fsElm = dynamic_cast<fsTiXmlElement*>(node);
if(fsElm != NULL)
{
fsElm->Print(stream, depth);
return true;
}
fsTiXmlDeclaration* fsDec = dynamic_cast<fsTiXmlDeclaration*>(node);
if(fsDec != NULL)
{
fsDec->Print(stream, depth);
return true;
}
fsTiXmlAttribute* fsAtt = dynamic_cast<fsTiXmlAttribute*>(node);
if(fsAtt != NULL)
{
fsAtt->Print(stream, depth);
return true;
}
return false;
}
#endif //_FSTINYXML_H_ #endif //_FSTINYXML_H_

View file

@ -1056,14 +1056,14 @@ ImplementEnumType(_TamlFormatMode,
}*/ }*/
// Create document. // Create document.
TiXmlDocument schemaDocument; tinyxml2::XMLDocument schemaDocument;
// Add declaration. // Add declaration.
TiXmlDeclaration schemaDeclaration("1.0", "iso-8859-1", "no"); tinyxml2::XMLDeclaration* schemaDeclaration = schemaDocument.NewDeclaration("xml version=\"1.0\" encoding=\"iso-8859-1\" standalone =\"no\"");
schemaDocument.InsertEndChild(schemaDeclaration); schemaDocument.InsertEndChild(schemaDeclaration);
// Add schema element. // Add schema element.
TiXmlElement* pSchemaElement = new TiXmlElement("xs:schema"); tinyxml2::XMLElement* pSchemaElement = schemaDocument.NewElement("xs:schema");
pSchemaElement->SetAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema"); pSchemaElement->SetAttribute("xmlns:xs", "http://www.w3.org/2001/XMLSchema");
schemaDocument.LinkEndChild(pSchemaElement); schemaDocument.LinkEndChild(pSchemaElement);
@ -1084,156 +1084,156 @@ ImplementEnumType(_TamlFormatMode,
// ************************************************************* // *************************************************************
// Vector2. // Vector2.
TiXmlComment* pVector2Comment = new TiXmlComment("Vector2 Console Type"); tinyxml2::XMLComment* pVector2Comment = schemaDocument.NewComment("Vector2 Console Type");
pSchemaElement->LinkEndChild(pVector2Comment); pSchemaElement->LinkEndChild(pVector2Comment);
TiXmlElement* pVector2TypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pVector2TypeElement = schemaDocument.NewElement("xs:simpleType");
pVector2TypeElement->SetAttribute("name", "Vector2_ConsoleType"); pVector2TypeElement->SetAttribute("name", "Vector2_ConsoleType");
pSchemaElement->LinkEndChild(pVector2TypeElement); pSchemaElement->LinkEndChild(pVector2TypeElement);
TiXmlElement* pVector2ElementA = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pVector2ElementA = schemaDocument.NewElement("xs:restriction");
pVector2ElementA->SetAttribute("base", "xs:string"); pVector2ElementA->SetAttribute("base", "xs:string");
pVector2TypeElement->LinkEndChild(pVector2ElementA); pVector2TypeElement->LinkEndChild(pVector2ElementA);
TiXmlElement* pVector2ElementB = new TiXmlElement("xs:pattern"); tinyxml2::XMLElement* pVector2ElementB = schemaDocument.NewElement("xs:pattern");
pVector2ElementB->SetAttribute("value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b"); pVector2ElementB->SetAttribute("value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b");
pVector2ElementA->LinkEndChild(pVector2ElementB); pVector2ElementA->LinkEndChild(pVector2ElementB);
// Point2F. // Point2F.
TiXmlComment* pPoint2FComment = new TiXmlComment("Point2F Console Type"); tinyxml2::XMLComment* pPoint2FComment = schemaDocument.NewComment("Point2F Console Type");
pSchemaElement->LinkEndChild(pPoint2FComment); pSchemaElement->LinkEndChild(pPoint2FComment);
TiXmlElement* pPoint2FTypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pPoint2FTypeElement = schemaDocument.NewElement("xs:simpleType");
pPoint2FTypeElement->SetAttribute("name", "Point2F_ConsoleType"); pPoint2FTypeElement->SetAttribute("name", "Point2F_ConsoleType");
pSchemaElement->LinkEndChild(pPoint2FTypeElement); pSchemaElement->LinkEndChild(pPoint2FTypeElement);
TiXmlElement* pPoint2FElementA = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pPoint2FElementA = schemaDocument.NewElement("xs:restriction");
pPoint2FElementA->SetAttribute("base", "xs:string"); pPoint2FElementA->SetAttribute("base", "xs:string");
pPoint2FTypeElement->LinkEndChild(pPoint2FElementA); pPoint2FTypeElement->LinkEndChild(pPoint2FElementA);
TiXmlElement* pPoint2FElementB = new TiXmlElement("xs:pattern"); tinyxml2::XMLElement* pPoint2FElementB = schemaDocument.NewElement("xs:pattern");
pPoint2FElementB->SetAttribute("value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b"); pPoint2FElementB->SetAttribute("value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b");
pPoint2FElementA->LinkEndChild(pPoint2FElementB); pPoint2FElementA->LinkEndChild(pPoint2FElementB);
// Point2I. // Point2I.
TiXmlComment* pPoint2IComment = new TiXmlComment("Point2I Console Type"); tinyxml2::XMLComment* pPoint2IComment = schemaDocument.NewComment("Point2I Console Type");
pSchemaElement->LinkEndChild(pPoint2IComment); pSchemaElement->LinkEndChild(pPoint2IComment);
TiXmlElement* pPoint2ITypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pPoint2ITypeElement = schemaDocument.NewElement("xs:simpleType");
pPoint2ITypeElement->SetAttribute("name", "Point2I_ConsoleType"); pPoint2ITypeElement->SetAttribute("name", "Point2I_ConsoleType");
pSchemaElement->LinkEndChild(pPoint2ITypeElement); pSchemaElement->LinkEndChild(pPoint2ITypeElement);
TiXmlElement* pPoint2IElementA = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pPoint2IElementA = schemaDocument.NewElement("xs:restriction");
pPoint2IElementA->SetAttribute("base", "xs:string"); pPoint2IElementA->SetAttribute("base", "xs:string");
pPoint2ITypeElement->LinkEndChild(pPoint2IElementA); pPoint2ITypeElement->LinkEndChild(pPoint2IElementA);
TiXmlElement* pPoint2IElementB = new TiXmlElement("xs:pattern"); tinyxml2::XMLElement* pPoint2IElementB = schemaDocument.NewElement("xs:pattern");
pPoint2IElementB->SetAttribute("value", "[-]?[0-9]* [-]?[0-9]*"); pPoint2IElementB->SetAttribute("value", "[-]?[0-9]* [-]?[0-9]*");
pPoint2IElementA->LinkEndChild(pPoint2IElementB); pPoint2IElementA->LinkEndChild(pPoint2IElementB);
// b2AABB. // b2AABB.
TiXmlComment* pb2AABBComment = new TiXmlComment("b2AABB Console Type"); tinyxml2::XMLComment* pb2AABBComment = schemaDocument.NewComment("b2AABB Console Type");
pSchemaElement->LinkEndChild(pb2AABBComment); pSchemaElement->LinkEndChild(pb2AABBComment);
TiXmlElement* pb2AABBTypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pb2AABBTypeElement = schemaDocument.NewElement("xs:simpleType");
pb2AABBTypeElement->SetAttribute("name", "b2AABB_ConsoleType"); pb2AABBTypeElement->SetAttribute("name", "b2AABB_ConsoleType");
pSchemaElement->LinkEndChild(pb2AABBTypeElement); pSchemaElement->LinkEndChild(pb2AABBTypeElement);
TiXmlElement* pb2AABBElementA = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pb2AABBElementA = schemaDocument.NewElement("xs:restriction");
pb2AABBElementA->SetAttribute("base", "xs:string"); pb2AABBElementA->SetAttribute("base", "xs:string");
pb2AABBTypeElement->LinkEndChild(pb2AABBElementA); pb2AABBTypeElement->LinkEndChild(pb2AABBElementA);
TiXmlElement* pb2AABBElementB = new TiXmlElement("xs:pattern"); tinyxml2::XMLElement* pb2AABBElementB = schemaDocument.NewElement("xs:pattern");
pb2AABBElementB->SetAttribute("value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b"); pb2AABBElementB->SetAttribute("value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b");
pb2AABBElementA->LinkEndChild(pb2AABBElementB); pb2AABBElementA->LinkEndChild(pb2AABBElementB);
// RectI. // RectI.
TiXmlComment* pRectIComment = new TiXmlComment("RectI Console Type"); tinyxml2::XMLComment* pRectIComment = schemaDocument.NewComment("RectI Console Type");
pSchemaElement->LinkEndChild(pRectIComment); pSchemaElement->LinkEndChild(pRectIComment);
TiXmlElement* pRectITypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pRectITypeElement = schemaDocument.NewElement("xs:simpleType");
pRectITypeElement->SetAttribute("name", "RectI_ConsoleType"); pRectITypeElement->SetAttribute("name", "RectI_ConsoleType");
pSchemaElement->LinkEndChild(pRectITypeElement); pSchemaElement->LinkEndChild(pRectITypeElement);
TiXmlElement* pRectIElementA = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pRectIElementA = schemaDocument.NewElement("xs:restriction");
pRectIElementA->SetAttribute("base", "xs:string"); pRectIElementA->SetAttribute("base", "xs:string");
pRectITypeElement->LinkEndChild(pRectIElementA); pRectITypeElement->LinkEndChild(pRectIElementA);
TiXmlElement* pRectIElementB = new TiXmlElement("xs:pattern"); tinyxml2::XMLElement* pRectIElementB = schemaDocument.NewElement("xs:pattern");
pRectIElementB->SetAttribute("value", "[-]?[0-9]* [-]?[0-9]* [-]?[0-9]* [-]?[0-9]*"); pRectIElementB->SetAttribute("value", "[-]?[0-9]* [-]?[0-9]* [-]?[0-9]* [-]?[0-9]*");
pRectIElementA->LinkEndChild(pRectIElementB); pRectIElementA->LinkEndChild(pRectIElementB);
// RectF. // RectF.
TiXmlComment* pRectFComment = new TiXmlComment("RectF Console Type"); tinyxml2::XMLComment* pRectFComment = schemaDocument.NewComment("RectF Console Type");
pSchemaElement->LinkEndChild(pRectFComment); pSchemaElement->LinkEndChild(pRectFComment);
TiXmlElement* pRectFTypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pRectFTypeElement = schemaDocument.NewElement("xs:simpleType");
pRectFTypeElement->SetAttribute("name", "RectF_ConsoleType"); pRectFTypeElement->SetAttribute("name", "RectF_ConsoleType");
pSchemaElement->LinkEndChild(pRectFTypeElement); pSchemaElement->LinkEndChild(pRectFTypeElement);
TiXmlElement* pRectFElementA = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pRectFElementA = schemaDocument.NewElement("xs:restriction");
pRectFElementA->SetAttribute("base", "xs:string"); pRectFElementA->SetAttribute("base", "xs:string");
pRectFTypeElement->LinkEndChild(pRectFElementA); pRectFTypeElement->LinkEndChild(pRectFElementA);
TiXmlElement* pRectFElementB = new TiXmlElement("xs:pattern"); tinyxml2::XMLElement* pRectFElementB = schemaDocument.NewElement("xs:pattern");
pRectFElementB->SetAttribute("value", "(\\b[-]?(b[0-9]+)?\\.)?[0-9]+\\b"); pRectFElementB->SetAttribute("value", "(\\b[-]?(b[0-9]+)?\\.)?[0-9]+\\b");
pRectFElementA->LinkEndChild(pRectFElementB); pRectFElementA->LinkEndChild(pRectFElementB);
// AssetId. // AssetId.
TiXmlComment* pAssetIdComment = new TiXmlComment("AssetId Console Type"); tinyxml2::XMLComment* pAssetIdComment = schemaDocument.NewComment("AssetId Console Type");
pSchemaElement->LinkEndChild(pAssetIdComment); pSchemaElement->LinkEndChild(pAssetIdComment);
TiXmlElement* pAssetIdTypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pAssetIdTypeElement = schemaDocument.NewElement("xs:simpleType");
pAssetIdTypeElement->SetAttribute("name", "AssetId_ConsoleType"); pAssetIdTypeElement->SetAttribute("name", "AssetId_ConsoleType");
pSchemaElement->LinkEndChild(pAssetIdTypeElement); pSchemaElement->LinkEndChild(pAssetIdTypeElement);
TiXmlElement* pAssetIdElementA = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pAssetIdElementA = schemaDocument.NewElement("xs:restriction");
pAssetIdElementA->SetAttribute("base", "xs:string"); pAssetIdElementA->SetAttribute("base", "xs:string");
pAssetIdTypeElement->LinkEndChild(pAssetIdElementA); pAssetIdTypeElement->LinkEndChild(pAssetIdElementA);
TiXmlElement* pAssetIdElementB = new TiXmlElement("xs:pattern"); tinyxml2::XMLElement* pAssetIdElementB = schemaDocument.NewElement("xs:pattern");
dSprintf(buffer, sizeof(buffer), "(%s)?\\b[a-zA-Z0-9]+\\b%s\\b[a-zA-Z0-9]+\\b", ASSET_ID_FIELD_PREFIX, ASSET_SCOPE_TOKEN); dSprintf(buffer, sizeof(buffer), "(%s)?\\b[a-zA-Z0-9]+\\b%s\\b[a-zA-Z0-9]+\\b", ASSET_ID_FIELD_PREFIX, ASSET_SCOPE_TOKEN);
pAssetIdElementB->SetAttribute("value", buffer); pAssetIdElementB->SetAttribute("value", buffer);
pAssetIdElementA->LinkEndChild(pAssetIdElementB); pAssetIdElementA->LinkEndChild(pAssetIdElementB);
// Color Enums. // Color Enums.
TiXmlComment* pColorEnumsComment = new TiXmlComment("Color Enums"); tinyxml2::XMLComment* pColorEnumsComment = schemaDocument.NewComment("Color Enums");
pSchemaElement->LinkEndChild(pColorEnumsComment); pSchemaElement->LinkEndChild(pColorEnumsComment);
TiXmlElement* pColorEnumsTypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pColorEnumsTypeElement = schemaDocument.NewElement("xs:simpleType");
pColorEnumsTypeElement->SetAttribute("name", "Color_Enums"); pColorEnumsTypeElement->SetAttribute("name", "Color_Enums");
pSchemaElement->LinkEndChild(pColorEnumsTypeElement); pSchemaElement->LinkEndChild(pColorEnumsTypeElement);
TiXmlElement* pColorEnumsRestrictionElement = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pColorEnumsRestrictionElement = schemaDocument.NewElement("xs:restriction");
pColorEnumsRestrictionElement->SetAttribute("base", "xs:string"); pColorEnumsRestrictionElement->SetAttribute("base", "xs:string");
pColorEnumsTypeElement->LinkEndChild(pColorEnumsRestrictionElement); pColorEnumsTypeElement->LinkEndChild(pColorEnumsRestrictionElement);
const S32 ColorEnumsCount = StockColor::getCount(); const S32 ColorEnumsCount = StockColor::getCount();
for (S32 index = 0; index < ColorEnumsCount; ++index) for (S32 index = 0; index < ColorEnumsCount; ++index)
{ {
// Add enumeration element. // Add enumeration element.
TiXmlElement* pColorEnumsAttributeEnumerationElement = new TiXmlElement("xs:enumeration"); tinyxml2::XMLElement* pColorEnumsAttributeEnumerationElement = schemaDocument.NewElement("xs:enumeration");
pColorEnumsAttributeEnumerationElement->SetAttribute("value", StockColor::getColorItem(index)->getColorName()); pColorEnumsAttributeEnumerationElement->SetAttribute("value", StockColor::getColorItem(index)->getColorName());
pColorEnumsRestrictionElement->LinkEndChild(pColorEnumsAttributeEnumerationElement); pColorEnumsRestrictionElement->LinkEndChild(pColorEnumsAttributeEnumerationElement);
} }
// LinearColorF. // LinearColorF.
TiXmlComment* pColorFValuesComment = new TiXmlComment("LinearColorF Values"); tinyxml2::XMLComment* pColorFValuesComment = schemaDocument.NewComment("LinearColorF Values");
pSchemaElement->LinkEndChild(pColorFValuesComment); pSchemaElement->LinkEndChild(pColorFValuesComment);
TiXmlElement* pColorFValuesTypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pColorFValuesTypeElement = schemaDocument.NewElement("xs:simpleType");
pColorFValuesTypeElement->SetAttribute("name", "ColorF_Values"); pColorFValuesTypeElement->SetAttribute("name", "ColorF_Values");
pSchemaElement->LinkEndChild(pColorFValuesTypeElement); pSchemaElement->LinkEndChild(pColorFValuesTypeElement);
TiXmlElement* pColorFValuesElementA = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pColorFValuesElementA = schemaDocument.NewElement("xs:restriction");
pColorFValuesElementA->SetAttribute("base", "xs:string"); pColorFValuesElementA->SetAttribute("base", "xs:string");
pColorFValuesTypeElement->LinkEndChild(pColorFValuesElementA); pColorFValuesTypeElement->LinkEndChild(pColorFValuesElementA);
TiXmlElement* pColorFValuesElementB = new TiXmlElement("xs:pattern"); tinyxml2::XMLElement* pColorFValuesElementB = schemaDocument.NewElement("xs:pattern");
pColorFValuesElementB->SetAttribute("value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b"); pColorFValuesElementB->SetAttribute("value", "([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b ([-]?(\\b[0-9]+)?\\.)?[0-9]+\\b");
pColorFValuesElementA->LinkEndChild(pColorFValuesElementB); pColorFValuesElementA->LinkEndChild(pColorFValuesElementB);
TiXmlComment* pColorFComment = new TiXmlComment("LinearColorF Console Type"); tinyxml2::XMLComment* pColorFComment = schemaDocument.NewComment("LinearColorF Console Type");
pSchemaElement->LinkEndChild(pColorFComment); pSchemaElement->LinkEndChild(pColorFComment);
TiXmlElement* pColorFTypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pColorFTypeElement = schemaDocument.NewElement("xs:simpleType");
pColorFTypeElement->SetAttribute("name", "ColorF_ConsoleType"); pColorFTypeElement->SetAttribute("name", "ColorF_ConsoleType");
pSchemaElement->LinkEndChild(pColorFTypeElement); pSchemaElement->LinkEndChild(pColorFTypeElement);
TiXmlElement* pColorFUnionElement = new TiXmlElement("xs:union"); tinyxml2::XMLElement* pColorFUnionElement = schemaDocument.NewElement("xs:union");
pColorFUnionElement->SetAttribute("memberTypes", "ColorF_Values Color_Enums"); pColorFUnionElement->SetAttribute("memberTypes", "ColorF_Values Color_Enums");
pColorFTypeElement->LinkEndChild(pColorFUnionElement); pColorFTypeElement->LinkEndChild(pColorFUnionElement);
// ColorI. // ColorI.
TiXmlComment* pColorIValuesComment = new TiXmlComment("ColorI Values"); tinyxml2::XMLComment* pColorIValuesComment = schemaDocument.NewComment("ColorI Values");
pSchemaElement->LinkEndChild(pColorIValuesComment); pSchemaElement->LinkEndChild(pColorIValuesComment);
TiXmlElement* pColorIValuesTypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pColorIValuesTypeElement = schemaDocument.NewElement("xs:simpleType");
pColorIValuesTypeElement->SetAttribute("name", "ColorI_Values"); pColorIValuesTypeElement->SetAttribute("name", "ColorI_Values");
pSchemaElement->LinkEndChild(pColorIValuesTypeElement); pSchemaElement->LinkEndChild(pColorIValuesTypeElement);
TiXmlElement* pColorIValuesElementA = new TiXmlElement("xs:restriction"); tinyxml2::XMLElement* pColorIValuesElementA = schemaDocument.NewElement("xs:restriction");
pColorIValuesElementA->SetAttribute("base", "xs:string"); pColorIValuesElementA->SetAttribute("base", "xs:string");
pColorIValuesTypeElement->LinkEndChild(pColorIValuesElementA); pColorIValuesTypeElement->LinkEndChild(pColorIValuesElementA);
TiXmlElement* pColorIValuesElementB = new TiXmlElement("xs:pattern"); tinyxml2::XMLElement* pColorIValuesElementB = schemaDocument.NewElement("xs:pattern");
pColorIValuesElementB->SetAttribute("value", "[-]?[0-9]* [-]?[0-9]* [-]?[0-9]* [-]?[0-9]*"); pColorIValuesElementB->SetAttribute("value", "[-]?[0-9]* [-]?[0-9]* [-]?[0-9]* [-]?[0-9]*");
pColorIValuesElementA->LinkEndChild(pColorIValuesElementB); pColorIValuesElementA->LinkEndChild(pColorIValuesElementB);
TiXmlComment* pColorIComment = new TiXmlComment("ColorI Console Type"); tinyxml2::XMLComment* pColorIComment = schemaDocument.NewComment("ColorI Console Type");
pSchemaElement->LinkEndChild(pColorIComment); pSchemaElement->LinkEndChild(pColorIComment);
TiXmlElement* pColorITypeElement = new TiXmlElement("xs:simpleType"); tinyxml2::XMLElement* pColorITypeElement = schemaDocument.NewElement("xs:simpleType");
pColorITypeElement->SetAttribute("name", "ColorI_ConsoleType"); pColorITypeElement->SetAttribute("name", "ColorI_ConsoleType");
pSchemaElement->LinkEndChild(pColorITypeElement); pSchemaElement->LinkEndChild(pColorITypeElement);
TiXmlElement* pColorIUnionElement = new TiXmlElement("xs:union"); tinyxml2::XMLElement* pColorIUnionElement = schemaDocument.NewElement("xs:union");
pColorIUnionElement->SetAttribute("memberTypes", "ColorI_Values Color_Enums"); pColorIUnionElement->SetAttribute("memberTypes", "ColorI_Values Color_Enums");
pColorITypeElement->LinkEndChild(pColorIUnionElement); pColorITypeElement->LinkEndChild(pColorIUnionElement);
@ -1242,12 +1242,12 @@ ImplementEnumType(_TamlFormatMode,
// ************************************************************* // *************************************************************
// Generate the engine type elements. // Generate the engine type elements.
TiXmlComment* tComment = new TiXmlComment("Type Elements"); tinyxml2::XMLComment* tComment = schemaDocument.NewComment("Type Elements");
pSchemaElement->LinkEndChild(tComment); pSchemaElement->LinkEndChild(tComment);
for (AbstractClassRep* pType = pRootType; pType != NULL; pType = pType->getNextClass()) for (AbstractClassRep* pType = pRootType; pType != NULL; pType = pType->getNextClass())
{ {
// Add type. // Add type.
TiXmlElement* pTypeElement = new TiXmlElement("xs:element"); tinyxml2::XMLElement* pTypeElement = schemaDocument.NewElement("xs:element");
pTypeElement->SetAttribute("name", pType->getClassName()); pTypeElement->SetAttribute("name", pType->getClassName());
dSprintf(buffer, sizeof(buffer), "%s_Type", pType->getClassName()); dSprintf(buffer, sizeof(buffer), "%s_Type", pType->getClassName());
pTypeElement->SetAttribute("type", buffer); pTypeElement->SetAttribute("type", buffer);
@ -1261,17 +1261,17 @@ ImplementEnumType(_TamlFormatMode,
{ {
// Add complex type comment. // Add complex type comment.
dSprintf(buffer, sizeof(buffer), " %s Type ", pType->getClassName()); dSprintf(buffer, sizeof(buffer), " %s Type ", pType->getClassName());
TiXmlComment* ctComment = new TiXmlComment(buffer); tinyxml2::XMLComment* ctComment = schemaDocument.NewComment(buffer);
pSchemaElement->LinkEndChild(ctComment); pSchemaElement->LinkEndChild(ctComment);
// Add complex type. // Add complex type.
TiXmlElement* pComplexTypeElement = new TiXmlElement("xs:complexType"); tinyxml2::XMLElement* pComplexTypeElement = schemaDocument.NewElement("xs:complexType");
dSprintf(buffer, sizeof(buffer), "%s_Type", pType->getClassName()); dSprintf(buffer, sizeof(buffer), "%s_Type", pType->getClassName());
pComplexTypeElement->SetAttribute("name", buffer); pComplexTypeElement->SetAttribute("name", buffer);
pSchemaElement->LinkEndChild(pComplexTypeElement); pSchemaElement->LinkEndChild(pComplexTypeElement);
// Add sequence. // Add sequence.
TiXmlElement* pSequenceElement = new TiXmlElement("xs:sequence"); tinyxml2::XMLElement* pSequenceElement = schemaDocument.NewElement("xs:sequence");
pComplexTypeElement->LinkEndChild(pSequenceElement); pComplexTypeElement->LinkEndChild(pSequenceElement);
// Fetch container child class. // Fetch container child class.
@ -1281,7 +1281,7 @@ ImplementEnumType(_TamlFormatMode,
if (pContainerChildClass != NULL) if (pContainerChildClass != NULL)
{ {
// Yes, so add choice element. // Yes, so add choice element.
TiXmlElement* pChoiceElement = new TiXmlElement("xs:choice"); tinyxml2::XMLElement* pChoiceElement = schemaDocument.NewElement("xs:choice");
pChoiceElement->SetAttribute("minOccurs", 0); pChoiceElement->SetAttribute("minOccurs", 0);
pChoiceElement->SetAttribute("maxOccurs", "unbounded"); pChoiceElement->SetAttribute("maxOccurs", "unbounded");
pSequenceElement->LinkEndChild(pChoiceElement); pSequenceElement->LinkEndChild(pChoiceElement);
@ -1299,12 +1299,12 @@ ImplementEnumType(_TamlFormatMode,
childGroupItr = childGroups.insertUnique(pContainerChildClass, StringTable->insert(buffer)); childGroupItr = childGroups.insertUnique(pContainerChildClass, StringTable->insert(buffer));
// Add the group. // Add the group.
TiXmlElement* pChildrenGroupElement = new TiXmlElement("xs:group"); tinyxml2::XMLElement* pChildrenGroupElement = schemaDocument.NewElement("xs:group");
pChildrenGroupElement->SetAttribute("name", buffer); pChildrenGroupElement->SetAttribute("name", buffer);
pSchemaElement->LinkEndChild(pChildrenGroupElement); pSchemaElement->LinkEndChild(pChildrenGroupElement);
// Add choice element. // Add choice element.
TiXmlElement* pChildreGroupChoiceElement = new TiXmlElement("xs:choice"); tinyxml2::XMLElement* pChildreGroupChoiceElement = schemaDocument.NewElement("xs:choice");
pChildrenGroupElement->LinkEndChild(pChildreGroupChoiceElement); pChildrenGroupElement->LinkEndChild(pChildreGroupChoiceElement);
// Add choice members. // Add choice members.
@ -1315,7 +1315,7 @@ ImplementEnumType(_TamlFormatMode,
continue; continue;
// Add choice member. // Add choice member.
TiXmlElement* pChildrenMemberElement = new TiXmlElement("xs:element"); tinyxml2::XMLElement* pChildrenMemberElement = schemaDocument.NewElement("xs:element");
pChildrenMemberElement->SetAttribute("name", pChoiceType->getClassName()); pChildrenMemberElement->SetAttribute("name", pChoiceType->getClassName());
dSprintf(buffer, sizeof(buffer), "%s_Type", pChoiceType->getClassName()); dSprintf(buffer, sizeof(buffer), "%s_Type", pChoiceType->getClassName());
pChildrenMemberElement->SetAttribute("type", buffer); pChildrenMemberElement->SetAttribute("type", buffer);
@ -1325,7 +1325,7 @@ ImplementEnumType(_TamlFormatMode,
} }
// Reference the child group. // Reference the child group.
TiXmlElement* pChoiceGroupReferenceElement = new TiXmlElement("xs:group"); tinyxml2::XMLElement* pChoiceGroupReferenceElement = schemaDocument.NewElement("xs:group");
pChoiceGroupReferenceElement->SetAttribute("ref", childGroupItr->value); pChoiceGroupReferenceElement->SetAttribute("ref", childGroupItr->value);
pChoiceGroupReferenceElement->SetAttribute("minOccurs", 0); pChoiceGroupReferenceElement->SetAttribute("minOccurs", 0);
pChoiceElement->LinkEndChild(pChoiceGroupReferenceElement); pChoiceElement->LinkEndChild(pChoiceGroupReferenceElement);
@ -1346,7 +1346,7 @@ ImplementEnumType(_TamlFormatMode,
} }
// Generate field attribute group. // Generate field attribute group.
TiXmlElement* pFieldAttributeGroupElement = new TiXmlElement("xs:attributeGroup"); tinyxml2::XMLElement* pFieldAttributeGroupElement = schemaDocument.NewElement("xs:attributeGroup");
dSprintf(buffer, sizeof(buffer), "%s_Fields", pType->getClassName()); dSprintf(buffer, sizeof(buffer), "%s_Fields", pType->getClassName());
pFieldAttributeGroupElement->SetAttribute("name", buffer); pFieldAttributeGroupElement->SetAttribute("name", buffer);
pSchemaElement->LinkEndChild(pFieldAttributeGroupElement); pSchemaElement->LinkEndChild(pFieldAttributeGroupElement);
@ -1374,7 +1374,7 @@ ImplementEnumType(_TamlFormatMode,
continue; continue;
// Add attribute element. // Add attribute element.
TiXmlElement* pAttributeElement = new TiXmlElement("xs:attribute"); tinyxml2::XMLElement* pAttributeElement = schemaDocument.NewElement("xs:attribute");
pAttributeElement->SetAttribute("name", field.pFieldname); pAttributeElement->SetAttribute("name", field.pFieldname);
// Handle the console type appropriately. // Handle the console type appropriately.
@ -1385,11 +1385,11 @@ ImplementEnumType(_TamlFormatMode,
if ( fieldType == TypeEnum ) if ( fieldType == TypeEnum )
{ {
// Yes, so add attribute type. // Yes, so add attribute type.
TiXmlElement* pAttributeSimpleTypeElement = new TiXmlElement( "xs:simpleType" ); tinyxml2::XMLElement* pAttributeSimpleTypeElement = schemaDocument.NewElement( "xs:simpleType" );
pAttributeElement->LinkEndChild( pAttributeSimpleTypeElement ); pAttributeElement->LinkEndChild( pAttributeSimpleTypeElement );
// Add restriction element. // Add restriction element.
TiXmlElement* pAttributeRestrictionElement = new TiXmlElement( "xs:restriction" ); tinyxml2::XMLElement* pAttributeRestrictionElement = schemaDocument.NewElement( "xs:restriction" );
pAttributeRestrictionElement->SetAttribute( "base", "xs:string" ); pAttributeRestrictionElement->SetAttribute( "base", "xs:string" );
pAttributeSimpleTypeElement->LinkEndChild( pAttributeRestrictionElement ); pAttributeSimpleTypeElement->LinkEndChild( pAttributeRestrictionElement );
@ -1400,7 +1400,7 @@ ImplementEnumType(_TamlFormatMode,
for( S32 index = 0; index < enumCount; ++index ) for( S32 index = 0; index < enumCount; ++index )
{ {
// Add enumeration element. // Add enumeration element.
TiXmlElement* pAttributeEnumerationElement = new TiXmlElement( "xs:enumeration" ); tinyxml2::XMLElement* pAttributeEnumerationElement = schemaDocument.NewElement( "xs:enumeration" );
pAttributeEnumerationElement->SetAttribute( "value", field.table->table[index].label ); pAttributeEnumerationElement->SetAttribute( "value", field.table->table[index].label );
pAttributeRestrictionElement->LinkEndChild( pAttributeEnumerationElement ); pAttributeRestrictionElement->LinkEndChild( pAttributeEnumerationElement );
} }
@ -1469,19 +1469,19 @@ ImplementEnumType(_TamlFormatMode,
// Yes, so add reserved Taml field attributes here... // Yes, so add reserved Taml field attributes here...
// Add Taml "Name" attribute element. // Add Taml "Name" attribute element.
TiXmlElement* pNameAttributeElement = new TiXmlElement("xs:attribute"); tinyxml2::XMLElement* pNameAttributeElement = schemaDocument.NewElement("xs:attribute");
pNameAttributeElement->SetAttribute("name", tamlNamedObjectName); pNameAttributeElement->SetAttribute("name", tamlNamedObjectName);
pNameAttributeElement->SetAttribute("type", "xs:normalizedString"); pNameAttributeElement->SetAttribute("type", "xs:normalizedString");
pFieldAttributeGroupElement->LinkEndChild(pNameAttributeElement); pFieldAttributeGroupElement->LinkEndChild(pNameAttributeElement);
// Add Taml "TamlId" attribute element. // Add Taml "TamlId" attribute element.
TiXmlElement* pTamlIdAttributeElement = new TiXmlElement("xs:attribute"); tinyxml2::XMLElement* pTamlIdAttributeElement = schemaDocument.NewElement("xs:attribute");
pTamlIdAttributeElement->SetAttribute("name", tamlRefIdName); pTamlIdAttributeElement->SetAttribute("name", tamlRefIdName);
pTamlIdAttributeElement->SetAttribute("type", "xs:nonNegativeInteger"); pTamlIdAttributeElement->SetAttribute("type", "xs:nonNegativeInteger");
pFieldAttributeGroupElement->LinkEndChild(pTamlIdAttributeElement); pFieldAttributeGroupElement->LinkEndChild(pTamlIdAttributeElement);
// Add Taml "TamlRefId" attribute element. // Add Taml "TamlRefId" attribute element.
TiXmlElement* pTamlRefIdAttributeElement = new TiXmlElement("xs:attribute"); tinyxml2::XMLElement* pTamlRefIdAttributeElement = schemaDocument.NewElement("xs:attribute");
pTamlRefIdAttributeElement->SetAttribute("name", tamlRefToIdName); pTamlRefIdAttributeElement->SetAttribute("name", tamlRefToIdName);
pTamlRefIdAttributeElement->SetAttribute("type", "xs:nonNegativeInteger"); pTamlRefIdAttributeElement->SetAttribute("type", "xs:nonNegativeInteger");
pFieldAttributeGroupElement->LinkEndChild(pTamlRefIdAttributeElement); pFieldAttributeGroupElement->LinkEndChild(pTamlRefIdAttributeElement);
@ -1490,14 +1490,14 @@ ImplementEnumType(_TamlFormatMode,
// Add attribute group types. // Add attribute group types.
for (AbstractClassRep* pAttributeGroupsType = pType; pAttributeGroupsType != NULL; pAttributeGroupsType = pAttributeGroupsType->getParentClass()) for (AbstractClassRep* pAttributeGroupsType = pType; pAttributeGroupsType != NULL; pAttributeGroupsType = pAttributeGroupsType->getParentClass())
{ {
TiXmlElement* pFieldAttributeGroupRefElement = new TiXmlElement("xs:attributeGroup"); tinyxml2::XMLElement* pFieldAttributeGroupRefElement = schemaDocument.NewElement("xs:attributeGroup");
dSprintf(buffer, sizeof(buffer), "%s_Fields", pAttributeGroupsType->getClassName()); dSprintf(buffer, sizeof(buffer), "%s_Fields", pAttributeGroupsType->getClassName());
pFieldAttributeGroupRefElement->SetAttribute("ref", buffer); pFieldAttributeGroupRefElement->SetAttribute("ref", buffer);
pComplexTypeElement->LinkEndChild(pFieldAttributeGroupRefElement); pComplexTypeElement->LinkEndChild(pFieldAttributeGroupRefElement);
} }
// Add "any" attribute element (dynamic fields). // Add "any" attribute element (dynamic fields).
TiXmlElement* pAnyAttributeElement = new TiXmlElement("xs:anyAttribute"); tinyxml2::XMLElement* pAnyAttributeElement = schemaDocument.NewElement("xs:anyAttribute");
pAnyAttributeElement->SetAttribute("processContents", "skip"); pAnyAttributeElement->SetAttribute("processContents", "skip");
pComplexTypeElement->LinkEndChild(pAnyAttributeElement); pComplexTypeElement->LinkEndChild(pAnyAttributeElement);
} }
@ -1513,17 +1513,19 @@ ImplementEnumType(_TamlFormatMode,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Taml::WriteUnrestrictedCustomTamlSchema(const char* pCustomNodeName, const AbstractClassRep* pClassRep, TiXmlElement* pParentElement) void Taml::WriteUnrestrictedCustomTamlSchema(const char* pCustomNodeName, const AbstractClassRep* pClassRep, tinyxml2::XMLElement* pParentElement)
{ {
// Sanity! // Sanity!
AssertFatal(pCustomNodeName != NULL, "Taml::WriteDefaultCustomTamlSchema() - Node name cannot be NULL."); AssertFatal(pCustomNodeName != NULL, "Taml::WriteDefaultCustomTamlSchema() - Node name cannot be NULL.");
AssertFatal(pClassRep != NULL, "Taml::WriteDefaultCustomTamlSchema() - ClassRep cannot be NULL."); AssertFatal(pClassRep != NULL, "Taml::WriteDefaultCustomTamlSchema() - ClassRep cannot be NULL.");
AssertFatal(pParentElement != NULL, "Taml::WriteDefaultCustomTamlSchema() - Parent Element cannot be NULL."); AssertFatal(pParentElement != NULL, "Taml::WriteDefaultCustomTamlSchema() - Parent Element cannot be NULL.");
tinyxml2::XMLDocument* doc = pParentElement->GetDocument();
char buffer[1024]; char buffer[1024];
// Add custom type element. // Add custom type element.
TiXmlElement* pCustomElement = new TiXmlElement("xs:element"); tinyxml2::XMLElement* pCustomElement = doc->NewElement("xs:element");
dSprintf(buffer, sizeof(buffer), "%s.%s", pClassRep->getClassName(), pCustomNodeName); dSprintf(buffer, sizeof(buffer), "%s.%s", pClassRep->getClassName(), pCustomNodeName);
pCustomElement->SetAttribute("name", buffer); pCustomElement->SetAttribute("name", buffer);
pCustomElement->SetAttribute("minOccurs", 0); pCustomElement->SetAttribute("minOccurs", 0);
@ -1531,21 +1533,21 @@ ImplementEnumType(_TamlFormatMode,
pParentElement->LinkEndChild(pCustomElement); pParentElement->LinkEndChild(pCustomElement);
// Add complex type element. // Add complex type element.
TiXmlElement* pComplexTypeElement = new TiXmlElement("xs:complexType"); tinyxml2::XMLElement* pComplexTypeElement = doc->NewElement("xs:complexType");
pCustomElement->LinkEndChild(pComplexTypeElement); pCustomElement->LinkEndChild(pComplexTypeElement);
// Add choice element. // Add choice element.
TiXmlElement* pChoiceElement = new TiXmlElement("xs:choice"); tinyxml2::XMLElement* pChoiceElement = doc->NewElement("xs:choice");
pChoiceElement->SetAttribute("minOccurs", 0); pChoiceElement->SetAttribute("minOccurs", 0);
pChoiceElement->SetAttribute("maxOccurs", "unbounded"); pChoiceElement->SetAttribute("maxOccurs", "unbounded");
pComplexTypeElement->LinkEndChild(pChoiceElement); pComplexTypeElement->LinkEndChild(pChoiceElement);
// Add sequence element. // Add sequence element.
TiXmlElement* pSequenceElement = new TiXmlElement("xs:sequence"); tinyxml2::XMLElement* pSequenceElement = doc->NewElement("xs:sequence");
pChoiceElement->LinkEndChild(pSequenceElement); pChoiceElement->LinkEndChild(pSequenceElement);
// Add "any" element. // Add "any" element.
TiXmlElement* pAnyElement = new TiXmlElement("xs:any"); tinyxml2::XMLElement* pAnyElement = doc->NewElement("xs:any");
pAnyElement->SetAttribute("processContents", "skip"); pAnyElement->SetAttribute("processContents", "skip");
pSequenceElement->LinkEndChild(pAnyElement); pSequenceElement->LinkEndChild(pAnyElement);
} }

View file

@ -67,8 +67,6 @@ extern StringTableEntry tamlNamedObjectName;
#define TAML_SCHEMA_VARIABLE "$pref::T2D::TAMLSchema" #define TAML_SCHEMA_VARIABLE "$pref::T2D::TAMLSchema"
#define TAML_JSON_STRICT_VARIBLE "$pref::T2D::JSONStrict" #define TAML_JSON_STRICT_VARIBLE "$pref::T2D::JSONStrict"
class TiXmlElement;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// @ingroup tamlGroup /// @ingroup tamlGroup
@ -196,7 +194,7 @@ public:
static bool generateTamlSchema(); static bool generateTamlSchema();
/// Write a unrestricted custom Taml schema. /// Write a unrestricted custom Taml schema.
static void WriteUnrestrictedCustomTamlSchema( const char* pCustomNodeName, const AbstractClassRep* pClassRep, TiXmlElement* pParentElement ); static void WriteUnrestrictedCustomTamlSchema( const char* pCustomNodeName, const AbstractClassRep* pClassRep, tinyxml2::XMLElement* pParentElement );
/// Get format mode info. /// Get format mode info.
static TamlFormatMode getFormatModeEnum( const char* label ); static TamlFormatMode getFormatModeEnum( const char* label );
@ -215,4 +213,4 @@ public:
DECLARE_CONOBJECT( Taml ); DECLARE_CONOBJECT( Taml );
}; };
#endif // _TAML_H_ #endif // _TAML_H_

View file

@ -21,17 +21,21 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
#include "persistence/taml/xml/tamlXmlParser.h" #include "persistence/taml/xml/tamlXmlParser.h"
#include "persistence/taml/fsTinyXml.h"
#include "persistence/taml/tamlVisitor.h" #include "persistence/taml/tamlVisitor.h"
#include "console/console.h" #include "console/console.h"
// Debug Profiling. // Debug Profiling.
#include "persistence/taml/fsTinyXml.h"
#include "platform/profiler.h" #include "platform/profiler.h"
#ifndef _FILESTREAM_H_ #ifndef _FILESTREAM_H_
#include "core/stream/fileStream.h" #include "core/stream/fileStream.h"
#endif #endif
#ifndef TINYXML2_INCLUDED
#include <tinyxml2.h>
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor ) bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor )
@ -68,7 +72,7 @@ bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor )
*/ */
fsTiXmlDocument xmlDocument; VfsXMLDocument xmlDocument;
// Load document from stream. // Load document from stream.
if ( !xmlDocument.LoadFile( filenameBuffer ) ) if ( !xmlDocument.LoadFile( filenameBuffer ) )
@ -88,7 +92,7 @@ bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor )
mDocumentDirty = false; mDocumentDirty = false;
// Parse root element. // Parse root element.
parseElement( (fsTiXmlElement*)xmlDocument.RootElement(), visitor ); parseElement( xmlDocument.RootElement(), visitor );
// Reset parsing filename. // Reset parsing filename.
setParsingFilename( StringTable->EmptyString() ); setParsingFilename( StringTable->EmptyString() );
@ -121,7 +125,7 @@ bool TamlXmlParser::accept( const char* pFilename, TamlVisitor& visitor )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline bool TamlXmlParser::parseElement( fsTiXmlElement* pXmlElement, TamlVisitor& visitor ) inline bool TamlXmlParser::parseElement( tinyxml2::XMLElement* pXmlElement, TamlVisitor& visitor )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlParser_ParseElement); PROFILE_SCOPE(TamlXmlParser_ParseElement);
@ -135,13 +139,13 @@ inline bool TamlXmlParser::parseElement( fsTiXmlElement* pXmlElement, TamlVisito
return false; return false;
// Fetch any children. // Fetch any children.
TiXmlNode* pChildXmlNode = pXmlElement->FirstChild(); tinyxml2::XMLNode* pChildXmlNode = pXmlElement->FirstChild();
// Do we have any element children? // Do we have any element children?
if ( pChildXmlNode != NULL && pChildXmlNode->Type() == TiXmlNode::TINYXML_ELEMENT ) if ( pChildXmlNode != NULL && pChildXmlNode->ToElement() != NULL )
{ {
// Iterate children. // Iterate children.
for ( fsTiXmlElement* pChildXmlElement = dynamic_cast<fsTiXmlElement*>( pChildXmlNode ); pChildXmlElement; pChildXmlElement = (fsTiXmlElement*)pChildXmlElement->NextSiblingElement() ) for ( tinyxml2::XMLElement* pChildXmlElement = pChildXmlNode->ToElement(); pChildXmlElement; pChildXmlElement = pChildXmlElement->NextSiblingElement() )
{ {
// Parse element (stop processing if instructed). // Parse element (stop processing if instructed).
if ( !parseElement( pChildXmlElement, visitor ) ) if ( !parseElement( pChildXmlElement, visitor ) )
@ -154,7 +158,7 @@ inline bool TamlXmlParser::parseElement( fsTiXmlElement* pXmlElement, TamlVisito
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
inline bool TamlXmlParser::parseAttributes( fsTiXmlElement* pXmlElement, TamlVisitor& visitor ) inline bool TamlXmlParser::parseAttributes( tinyxml2::XMLElement* pXmlElement, TamlVisitor& visitor )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlParser_ParseAttribute); PROFILE_SCOPE(TamlXmlParser_ParseAttribute);
@ -167,7 +171,7 @@ inline bool TamlXmlParser::parseAttributes( fsTiXmlElement* pXmlElement, TamlVis
propertyState.setObjectName( pXmlElement->Value(), isRoot ); propertyState.setObjectName( pXmlElement->Value(), isRoot );
// Iterate attributes. // Iterate attributes.
for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() ) for ( const tinyxml2::XMLAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
{ {
// Configure property state. // Configure property state.
propertyState.setProperty( pAttribute->Name(), pAttribute->Value() ); propertyState.setProperty( pAttribute->Name(), pAttribute->Value() );
@ -179,7 +183,7 @@ inline bool TamlXmlParser::parseAttributes( fsTiXmlElement* pXmlElement, TamlVis
if ( propertyState.getPropertyValueDirty() ) if ( propertyState.getPropertyValueDirty() )
{ {
// Yes, so update the attribute. // Yes, so update the attribute.
pAttribute->SetValue( propertyState.getPropertyValue() ); const_cast<tinyxml2::XMLAttribute*>(pAttribute)->SetAttribute( propertyState.getPropertyValue() );
// Flag the document as dirty. // Flag the document as dirty.
mDocumentDirty = true; mDocumentDirty = true;

View file

@ -27,6 +27,10 @@
#include "persistence/taml/tamlParser.h" #include "persistence/taml/tamlParser.h"
#endif #endif
#ifndef TINYXML2_INCLUDED
#include <tinyxml2.h>
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class fsTiXmlElement; class fsTiXmlElement;
@ -45,8 +49,8 @@ public:
virtual bool accept( const char* pFilename, TamlVisitor& visitor ); virtual bool accept( const char* pFilename, TamlVisitor& visitor );
private: private:
inline bool parseElement( fsTiXmlElement* pXmlElement, TamlVisitor& visitor ); inline bool parseElement( tinyxml2::XMLElement* pXmlElement, TamlVisitor& visitor );
inline bool parseAttributes( fsTiXmlElement* pXmlElement, TamlVisitor& visitor ); inline bool parseAttributes( tinyxml2::XMLElement* pXmlElement, TamlVisitor& visitor );
bool mDocumentDirty; bool mDocumentDirty;
}; };

View file

@ -24,6 +24,8 @@
// Debug Profiling. // Debug Profiling.
#include "platform/profiler.h" #include "platform/profiler.h"
#include <tinyxml2.h>
#include "persistence/taml/fsTinyXml.h" #include "persistence/taml/fsTinyXml.h"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -34,10 +36,10 @@ SimObject* TamlXmlReader::read( FileStream& stream )
PROFILE_SCOPE(TamlXmlReader_Read); PROFILE_SCOPE(TamlXmlReader_Read);
// Create document. // Create document.
fsTiXmlDocument xmlDocument; VfsXMLDocument xmlDocument;
// Load document from stream. // Load document from stream.
if ( !xmlDocument.LoadFile( stream ) ) if ( !xmlDocument.LoadFile(stream) )
{ {
// Warn! // Warn!
Con::warnf("Taml: Could not load Taml XML file from stream."); Con::warnf("Taml: Could not load Taml XML file from stream.");
@ -66,7 +68,7 @@ void TamlXmlReader::resetParse( void )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
SimObject* TamlXmlReader::parseElement( TiXmlElement* pXmlElement ) SimObject* TamlXmlReader::parseElement( tinyxml2::XMLElement* pXmlElement )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlReader_ParseElement); PROFILE_SCOPE(TamlXmlReader_ParseElement);
@ -103,7 +105,7 @@ SimObject* TamlXmlReader::parseElement( TiXmlElement* pXmlElement )
#ifdef TORQUE_DEBUG #ifdef TORQUE_DEBUG
// Format the type location. // Format the type location.
char typeLocationBuffer[64]; char typeLocationBuffer[64];
dSprintf( typeLocationBuffer, sizeof(typeLocationBuffer), "Taml [format='xml' row=%d column=%d]", pXmlElement->Row(), pXmlElement->Column() ); dSprintf( typeLocationBuffer, sizeof(typeLocationBuffer), "Taml [format='xml' line=%d]", pXmlElement->GetLineNum() );
// Create type. // Create type.
pSimObject = Taml::createType( typeName, mpTaml, typeLocationBuffer ); pSimObject = Taml::createType( typeName, mpTaml, typeLocationBuffer );
@ -165,7 +167,7 @@ SimObject* TamlXmlReader::parseElement( TiXmlElement* pXmlElement )
} }
// Fetch any children. // Fetch any children.
TiXmlNode* pChildXmlNode = pXmlElement->FirstChild(); tinyxml2::XMLNode* pChildXmlNode = pXmlElement->FirstChild();
TamlCustomNodes customProperties; TamlCustomNodes customProperties;
@ -182,7 +184,7 @@ SimObject* TamlXmlReader::parseElement( TiXmlElement* pXmlElement )
do do
{ {
// Fetch element. // Fetch element.
TiXmlElement* pChildXmlElement = dynamic_cast<TiXmlElement*>( pChildXmlNode ); tinyxml2::XMLElement* pChildXmlElement = pChildXmlNode->ToElement();
// Move to next sibling. // Move to next sibling.
pChildXmlNode = pChildXmlNode->NextSibling(); pChildXmlNode = pChildXmlNode->NextSibling();
@ -271,7 +273,7 @@ SimObject* TamlXmlReader::parseElement( TiXmlElement* pXmlElement )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void TamlXmlReader::parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimObject ) void TamlXmlReader::parseAttributes( tinyxml2::XMLElement* pXmlElement, SimObject* pSimObject )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlReader_ParseAttributes); PROFILE_SCOPE(TamlXmlReader_ParseAttributes);
@ -280,7 +282,7 @@ void TamlXmlReader::parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimO
AssertFatal( pSimObject != NULL, "Taml: Cannot parse attributes on a NULL object." ); AssertFatal( pSimObject != NULL, "Taml: Cannot parse attributes on a NULL object." );
// Iterate attributes. // Iterate attributes.
for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() ) for ( const tinyxml2::XMLAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
{ {
// Insert attribute name. // Insert attribute name.
StringTableEntry attributeName = StringTable->insert( pAttribute->Name() ); StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
@ -298,7 +300,7 @@ void TamlXmlReader::parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimO
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void TamlXmlReader::parseCustomElement( TiXmlElement* pXmlElement, TamlCustomNodes& customNodes ) void TamlXmlReader::parseCustomElement( tinyxml2::XMLElement* pXmlElement, TamlCustomNodes& customNodes )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlReader_ParseCustomElement); PROFILE_SCOPE(TamlXmlReader_ParseCustomElement);
@ -310,7 +312,7 @@ void TamlXmlReader::parseCustomElement( TiXmlElement* pXmlElement, TamlCustomNod
AssertFatal( pPeriod != NULL, "Parsing extended element but no period character found." ); AssertFatal( pPeriod != NULL, "Parsing extended element but no period character found." );
// Fetch any custom XML node. // Fetch any custom XML node.
TiXmlNode* pCustomXmlNode = pXmlElement->FirstChild(); tinyxml2::XMLNode* pCustomXmlNode = pXmlElement->FirstChild();
// Finish is no XML node exists. // Finish is no XML node exists.
if ( pCustomXmlNode == NULL ) if ( pCustomXmlNode == NULL )
@ -322,7 +324,7 @@ void TamlXmlReader::parseCustomElement( TiXmlElement* pXmlElement, TamlCustomNod
do do
{ {
// Fetch element. // Fetch element.
TiXmlElement* pCustomXmlElement = dynamic_cast<TiXmlElement*>( pCustomXmlNode ); tinyxml2::XMLElement* pCustomXmlElement = pCustomXmlNode->ToElement();
// Move to next sibling. // Move to next sibling.
pCustomXmlNode = pCustomXmlNode->NextSibling(); pCustomXmlNode = pCustomXmlNode->NextSibling();
@ -339,7 +341,7 @@ void TamlXmlReader::parseCustomElement( TiXmlElement* pXmlElement, TamlCustomNod
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void TamlXmlReader::parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode* pCustomNode ) void TamlXmlReader::parseCustomNode( tinyxml2::XMLElement* pXmlElement, TamlCustomNode* pCustomNode )
{ {
// Is the node a proxy object? // Is the node a proxy object?
if ( getTamlRefId( pXmlElement ) != 0 || getTamlRefToId( pXmlElement ) != 0 ) if ( getTamlRefId( pXmlElement ) != 0 || getTamlRefToId( pXmlElement ) != 0 )
@ -357,7 +359,7 @@ void TamlXmlReader::parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode*
TamlCustomNode* pChildNode = pCustomNode->addNode( pXmlElement->Value() ); TamlCustomNode* pChildNode = pCustomNode->addNode( pXmlElement->Value() );
// Iterate attributes. // Iterate attributes.
for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() ) for ( const tinyxml2::XMLAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
{ {
// Insert attribute name. // Insert attribute name.
StringTableEntry attributeName = StringTable->insert( pAttribute->Name() ); StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
@ -381,7 +383,7 @@ void TamlXmlReader::parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode*
} }
// Fetch any children. // Fetch any children.
TiXmlNode* pChildXmlNode = pXmlElement->FirstChild(); tinyxml2::XMLNode* pChildXmlNode = pXmlElement->FirstChild();
// Do we have any element children? // Do we have any element children?
if ( pChildXmlNode != NULL ) if ( pChildXmlNode != NULL )
@ -389,7 +391,7 @@ void TamlXmlReader::parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode*
do do
{ {
// Yes, so fetch child element. // Yes, so fetch child element.
TiXmlElement* pChildXmlElement = dynamic_cast<TiXmlElement*>( pChildXmlNode ); tinyxml2::XMLElement* pChildXmlElement = pChildXmlNode->ToElement();
// Move to next sibling. // Move to next sibling.
pChildXmlNode = pChildXmlNode->NextSibling(); pChildXmlNode = pChildXmlNode->NextSibling();
@ -407,13 +409,13 @@ void TamlXmlReader::parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode*
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
U32 TamlXmlReader::getTamlRefId( TiXmlElement* pXmlElement ) U32 TamlXmlReader::getTamlRefId( tinyxml2::XMLElement* pXmlElement )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlReader_GetTamlRefId); PROFILE_SCOPE(TamlXmlReader_GetTamlRefId);
// Iterate attributes. // Iterate attributes.
for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() ) for ( const tinyxml2::XMLAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
{ {
// Insert attribute name. // Insert attribute name.
StringTableEntry attributeName = StringTable->insert( pAttribute->Name() ); StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
@ -432,13 +434,13 @@ U32 TamlXmlReader::getTamlRefId( TiXmlElement* pXmlElement )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
U32 TamlXmlReader::getTamlRefToId( TiXmlElement* pXmlElement ) U32 TamlXmlReader::getTamlRefToId( tinyxml2::XMLElement* pXmlElement )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlReader_GetTamlRefToId); PROFILE_SCOPE(TamlXmlReader_GetTamlRefToId);
// Iterate attributes. // Iterate attributes.
for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() ) for ( const tinyxml2::XMLAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
{ {
// Insert attribute name. // Insert attribute name.
StringTableEntry attributeName = StringTable->insert( pAttribute->Name() ); StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );
@ -457,13 +459,13 @@ U32 TamlXmlReader::getTamlRefToId( TiXmlElement* pXmlElement )
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
const char* TamlXmlReader::getTamlObjectName( TiXmlElement* pXmlElement ) const char* TamlXmlReader::getTamlObjectName( tinyxml2::XMLElement* pXmlElement )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlReader_GetTamlObjectName); PROFILE_SCOPE(TamlXmlReader_GetTamlObjectName);
// Iterate attributes. // Iterate attributes.
for ( TiXmlAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() ) for ( const tinyxml2::XMLAttribute* pAttribute = pXmlElement->FirstAttribute(); pAttribute; pAttribute = pAttribute->Next() )
{ {
// Insert attribute name. // Insert attribute name.
StringTableEntry attributeName = StringTable->insert( pAttribute->Name() ); StringTableEntry attributeName = StringTable->insert( pAttribute->Name() );

View file

@ -31,10 +31,6 @@
#include "persistence/taml/taml.h" #include "persistence/taml/taml.h"
#endif #endif
#ifndef TINYXML_INCLUDED
#include "tinyXML/tinyxml.h"
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// @ingroup tamlGroup /// @ingroup tamlGroup
@ -60,14 +56,14 @@ private:
private: private:
void resetParse( void ); void resetParse( void );
SimObject* parseElement( TiXmlElement* pXmlElement ); SimObject* parseElement( tinyxml2::XMLElement* pXmlElement );
void parseAttributes( TiXmlElement* pXmlElement, SimObject* pSimObject ); void parseAttributes( tinyxml2::XMLElement* pXmlElement, SimObject* pSimObject );
void parseCustomElement( TiXmlElement* pXmlElement, TamlCustomNodes& pCustomNode ); void parseCustomElement( tinyxml2::XMLElement* pXmlElement, TamlCustomNodes& pCustomNode );
void parseCustomNode( TiXmlElement* pXmlElement, TamlCustomNode* pCustomNode ); void parseCustomNode( tinyxml2::XMLElement* pXmlElement, TamlCustomNode* pCustomNode );
U32 getTamlRefId( TiXmlElement* pXmlElement ); U32 getTamlRefId( tinyxml2::XMLElement* pXmlElement );
U32 getTamlRefToId( TiXmlElement* pXmlElement ); U32 getTamlRefToId( tinyxml2::XMLElement* pXmlElement );
const char* getTamlObjectName( TiXmlElement* pXmlElement ); const char* getTamlObjectName( tinyxml2::XMLElement* pXmlElement );
}; };
#endif // _TAML_XMLREADER_H_ #endif // _TAML_XMLREADER_H_

View file

@ -34,10 +34,10 @@ bool TamlXmlWriter::write( FileStream& stream, const TamlWriteNode* pTamlWriteNo
PROFILE_SCOPE(TamlXmlWriter_Write); PROFILE_SCOPE(TamlXmlWriter_Write);
// Create document. // Create document.
fsTiXmlDocument xmlDocument; VfsXMLDocument xmlDocument;
// Compile the root element. // Compile the root element.
TiXmlElement* pRootElement = compileElement( pTamlWriteNode ); tinyxml2::XMLElement* pRootElement = compileElement( &xmlDocument, pTamlWriteNode );
// Fetch any TAML Schema file reference. // Fetch any TAML Schema file reference.
const char* pTamlSchemaFile = Con::getVariable( TAML_SCHEMA_VARIABLE ); const char* pTamlSchemaFile = Con::getVariable( TAML_SCHEMA_VARIABLE );
@ -77,7 +77,7 @@ bool TamlXmlWriter::write( FileStream& stream, const TamlWriteNode* pTamlWriteNo
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
TiXmlElement* TamlXmlWriter::compileElement( const TamlWriteNode* pTamlWriteNode ) tinyxml2::XMLElement* TamlXmlWriter::compileElement( tinyxml2::XMLDocument* doc, const TamlWriteNode* pTamlWriteNode )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlWriter_CompileElement); PROFILE_SCOPE(TamlXmlWriter_CompileElement);
@ -89,7 +89,7 @@ TiXmlElement* TamlXmlWriter::compileElement( const TamlWriteNode* pTamlWriteNode
const char* pElementName = pSimObject->getClassName(); const char* pElementName = pSimObject->getClassName();
// Create element. // Create element.
TiXmlElement* pElement = new fsTiXmlElement( pElementName ); tinyxml2::XMLElement* pElement = doc->NewElement( pElementName );
// Fetch reference Id. // Fetch reference Id.
const U32 referenceId = pTamlWriteNode->mRefId; const U32 referenceId = pTamlWriteNode->mRefId;
@ -140,7 +140,7 @@ TiXmlElement* TamlXmlWriter::compileElement( const TamlWriteNode* pTamlWriteNode
for( Vector<TamlWriteNode*>::iterator itr = pChildren->begin(); itr != pChildren->end(); ++itr ) for( Vector<TamlWriteNode*>::iterator itr = pChildren->begin(); itr != pChildren->end(); ++itr )
{ {
// Write child element. // Write child element.
pElement->LinkEndChild( compileElement( (*itr) ) ); pElement->LinkEndChild( compileElement( doc, (*itr) ) );
} }
} }
@ -152,7 +152,7 @@ TiXmlElement* TamlXmlWriter::compileElement( const TamlWriteNode* pTamlWriteNode
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void TamlXmlWriter::compileAttributes( TiXmlElement* pXmlElement, const TamlWriteNode* pTamlWriteNode ) void TamlXmlWriter::compileAttributes( tinyxml2::XMLElement* pXmlElement, const TamlWriteNode* pTamlWriteNode )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlWriter_CompileAttributes); PROFILE_SCOPE(TamlXmlWriter_CompileAttributes);
@ -177,7 +177,7 @@ void TamlXmlWriter::compileAttributes( TiXmlElement* pXmlElement, const TamlWrit
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void TamlXmlWriter::compileCustomElements( TiXmlElement* pXmlElement, const TamlWriteNode* pTamlWriteNode ) void TamlXmlWriter::compileCustomElements( tinyxml2::XMLElement* pXmlElement, const TamlWriteNode* pTamlWriteNode )
{ {
// Debug Profiling. // Debug Profiling.
PROFILE_SCOPE(TamlXmlWriter_CompileCustomElements); PROFILE_SCOPE(TamlXmlWriter_CompileCustomElements);
@ -189,7 +189,7 @@ void TamlXmlWriter::compileCustomElements( TiXmlElement* pXmlElement, const Taml
const TamlCustomNodeVector& nodes = customNodes.getNodes(); const TamlCustomNodeVector& nodes = customNodes.getNodes();
// Finish if no custom nodes to process. // Finish if no custom nodes to process.
if ( nodes.size() == 0 ) if (nodes.empty())
return; return;
// Iterate custom nodes. // Iterate custom nodes.
@ -204,7 +204,7 @@ void TamlXmlWriter::compileCustomElements( TiXmlElement* pXmlElement, const Taml
StringTableEntry extendedElementName = StringTable->insert( extendedElementNameBuffer ); StringTableEntry extendedElementName = StringTable->insert( extendedElementNameBuffer );
// Create element. // Create element.
TiXmlElement* pExtendedPropertyElement = new fsTiXmlElement( extendedElementName ); tinyxml2::XMLElement* pExtendedPropertyElement = pXmlElement->GetDocument()->NewElement( extendedElementName );
// Fetch node children. // Fetch node children.
const TamlCustomNodeVector& nodeChildren = pCustomNode->getChildren(); const TamlCustomNodeVector& nodeChildren = pCustomNode->getChildren();
@ -223,7 +223,7 @@ void TamlXmlWriter::compileCustomElements( TiXmlElement* pXmlElement, const Taml
if ( pCustomNode->getIgnoreEmpty() && pExtendedPropertyElement->NoChildren() ) if ( pCustomNode->getIgnoreEmpty() && pExtendedPropertyElement->NoChildren() )
{ {
// Yes, so delete the extended element. // Yes, so delete the extended element.
delete pExtendedPropertyElement; pXmlElement->GetDocument()->DeleteNode(pExtendedPropertyElement);
pExtendedPropertyElement = NULL; pExtendedPropertyElement = NULL;
} }
else else
@ -236,7 +236,7 @@ void TamlXmlWriter::compileCustomElements( TiXmlElement* pXmlElement, const Taml
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void TamlXmlWriter::compileCustomNode( TiXmlElement* pXmlElement, const TamlCustomNode* pCustomNode ) void TamlXmlWriter::compileCustomNode(tinyxml2::XMLElement* pXmlElement, const TamlCustomNode* pCustomNode )
{ {
// Finish if the node is set to ignore if empty and it is empty. // Finish if the node is set to ignore if empty and it is empty.
if ( pCustomNode->getIgnoreEmpty() && pCustomNode->isEmpty() ) if ( pCustomNode->getIgnoreEmpty() && pCustomNode->isEmpty() )
@ -246,18 +246,18 @@ void TamlXmlWriter::compileCustomNode( TiXmlElement* pXmlElement, const TamlCust
if ( pCustomNode->isProxyObject() ) if ( pCustomNode->isProxyObject() )
{ {
// Yes, so write the proxy object. // Yes, so write the proxy object.
pXmlElement->LinkEndChild( compileElement( pCustomNode->getProxyWriteNode() ) ); pXmlElement->LinkEndChild( compileElement( pXmlElement->GetDocument(), pCustomNode->getProxyWriteNode() ) );
return; return;
} }
// Create element. // Create element.
TiXmlElement* pNodeElement = new fsTiXmlElement( pCustomNode->getNodeName() ); tinyxml2::XMLElement* pNodeElement = pXmlElement->GetDocument()->NewElement( pCustomNode->getNodeName() );
// Is there any node text? // Is there any node text?
if ( !pCustomNode->getNodeTextField().isValueEmpty() ) if ( !pCustomNode->getNodeTextField().isValueEmpty() )
{ {
// Yes, so add a text node. // Yes, so add a text node.
pNodeElement->LinkEndChild( new TiXmlText( pCustomNode->getNodeTextField().getFieldValue() ) ); pNodeElement->LinkEndChild( pXmlElement->GetDocument()->NewText( pCustomNode->getNodeTextField().getFieldValue() ) );
} }
// Fetch fields. // Fetch fields.
@ -287,10 +287,10 @@ void TamlXmlWriter::compileCustomNode( TiXmlElement* pXmlElement, const TamlCust
} }
// Finish if the node is set to ignore if empty and it is empty (including fields). // Finish if the node is set to ignore if empty and it is empty (including fields).
if ( pCustomNode->getIgnoreEmpty() && fields.size() == 0 && pNodeElement->NoChildren() ) if ( pCustomNode->getIgnoreEmpty() && fields.empty() && pNodeElement->NoChildren() )
{ {
// Yes, so delete the extended element. // Yes, so delete the extended element.
delete pNodeElement; pXmlElement->GetDocument()->DeleteNode(pNodeElement);
pNodeElement = NULL; pNodeElement = NULL;
} }
else else

View file

@ -27,10 +27,6 @@
#include "persistence/taml/taml.h" #include "persistence/taml/taml.h"
#endif #endif
#ifndef TINYXML_INCLUDED
#include "tinyXML/tinyxml.h"
#endif
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
/// @ingroup tamlGroup /// @ingroup tamlGroup
@ -50,10 +46,10 @@ private:
Taml* mpTaml; Taml* mpTaml;
private: private:
TiXmlElement* compileElement( const TamlWriteNode* pTamlWriteNode ); tinyxml2::XMLElement* compileElement( tinyxml2::XMLDocument* doc, const TamlWriteNode* pTamlWriteNode );
void compileAttributes( TiXmlElement* pXmlElement, const TamlWriteNode* pTamlWriteNode ); void compileAttributes( tinyxml2::XMLElement* pXmlElement, const TamlWriteNode* pTamlWriteNode );
void compileCustomElements( TiXmlElement* pXmlElement, const TamlWriteNode* pTamlWriteNode ); void compileCustomElements( tinyxml2::XMLElement* pXmlElement, const TamlWriteNode* pTamlWriteNode );
void compileCustomNode( TiXmlElement* pXmlElement, const TamlCustomNode* pCustomNode ); void compileCustomNode( tinyxml2::XMLElement* pXmlElement, const TamlCustomNode* pCustomNode );
}; };
#endif // _TAML_XMLWRITER_H_ #endif // _TAML_XMLWRITER_H_

File diff suppressed because it is too large Load diff

View file

@ -43,8 +43,8 @@
#ifndef _OPTIMIZEDPOLYLIST_H_ #ifndef _OPTIMIZEDPOLYLIST_H_
#include "collision/optimizedPolyList.h" #include "collision/optimizedPolyList.h"
#endif #endif
#ifndef TINYXML_INCLUDED #ifndef TINYXML2_INCLUDED
#include "tinyxml.h" #include "tinyxml2.h"
#endif #endif
#ifndef _CONSOLE_H_ #ifndef _CONSOLE_H_
#include "console/console.h" #include "console/console.h"
@ -299,17 +299,17 @@ namespace ColladaUtils
// Collada export helper functions // Collada export helper functions
Torque::Path findTexture(const Torque::Path& diffuseMap); Torque::Path findTexture(const Torque::Path& diffuseMap);
void exportColladaHeader(TiXmlElement* rootNode); void exportColladaHeader(tinyxml2::XMLElement* rootNode);
void exportColladaMaterials(TiXmlElement* rootNode, const OptimizedPolyList& mesh, Vector<String>& matNames, const Torque::Path& colladaFile); void exportColladaMaterials(tinyxml2::XMLElement* rootNode, const OptimizedPolyList& mesh, Vector<String>& matNames, const Torque::Path& colladaFile);
void exportColladaTriangles(TiXmlElement* meshNode, const OptimizedPolyList& mesh, const String& meshName, const Vector<String>& matNames); void exportColladaTriangles(tinyxml2::XMLElement* meshNode, const OptimizedPolyList& mesh, const String& meshName, const Vector<String>& matNames);
void exportColladaMesh(TiXmlElement* rootNode, const OptimizedPolyList& mesh, const String& meshName, const Vector<String>& matNames); void exportColladaMesh(tinyxml2::XMLElement* rootNode, const OptimizedPolyList& mesh, const String& meshName, const Vector<String>& matNames);
void exportColladaScene(TiXmlElement* rootNode, const String& meshName, const Vector<String>& matNames); void exportColladaScene(tinyxml2::XMLElement* rootNode, const String& meshName, const Vector<String>& matNames);
void exportColladaMaterials(TiXmlElement* rootNode, const ExportData& exportData, const Torque::Path& colladaFile); void exportColladaMaterials(tinyxml2::XMLElement* rootNode, const ExportData& exportData, const Torque::Path& colladaFile);
void exportColladaMesh(TiXmlElement* rootNode, const ExportData& exportData, const String& meshName); void exportColladaMesh(tinyxml2::XMLElement* rootNode, const ExportData& exportData, const String& meshName);
void exportColladaCollisionTriangles(TiXmlElement* meshNode, const ExportData& exportData, const U32 collisionIdx); void exportColladaCollisionTriangles(tinyxml2::XMLElement* meshNode, const ExportData& exportData, const U32 collisionIdx);
void exportColladaTriangles(TiXmlElement* meshNode, const ExportData& exportData, const U32 detailLevel, const String& meshName); void exportColladaTriangles(tinyxml2::XMLElement* meshNode, const ExportData& exportData, const U32 detailLevel, const String& meshName);
void exportColladaScene(TiXmlElement* rootNode, const ExportData& exportData, const String& meshName); void exportColladaScene(tinyxml2::XMLElement* rootNode, const ExportData& exportData, const String& meshName);
// Export an OptimizedPolyList to a simple Collada file // Export an OptimizedPolyList to a simple Collada file
void exportToCollada(const Torque::Path& colladaFile, const OptimizedPolyList& mesh, const String& meshName = String::EmptyString); void exportToCollada(const Torque::Path& colladaFile, const OptimizedPolyList& mesh, const String& meshName = String::EmptyString);

View file

@ -2294,14 +2294,6 @@ void TSShapeConstructor::ChangeSet::write(TSShape* shape, Stream& stream, const
} }
} }
TiXmlElement *createNodeWithText( const char* name, const char* text )
{
TiXmlElement* node = new TiXmlElement( name );
node->LinkEndChild( new TiXmlText( text ) );
return node;
}
void TSShapeConstructor::ChangeSet::add( TSShapeConstructor::ChangeSet::Command& cmd ) void TSShapeConstructor::ChangeSet::add( TSShapeConstructor::ChangeSet::Command& cmd )
{ {
// Lookup the command type // Lookup the command type