//! Parse xml from memory buffer with specific size XmlNodeRef XmlParser::parseBuffer(char* buffer, int size, const char* rootNodeName) { m_errorString = ""; XmlParserImp xml; XmlNodeRef ref = xml.parse(buffer, size, rootNodeName, m_errorString, true); if (!m_errorString.empty()) { BEHAVIAC_LOGWARNING("Error while parsing XML file : \n\n%s", m_errorString.c_str()); } return ref; }
//! Parse xml file. XmlNodeRef XmlParser::parse( const String& fileName ) { m_errorString = ""; XmlParserImp xml; //std::vector<char> buf; //String buf; char *buf; FILE *file; #if _MSC_VER<=1200 file = fopen( fileName.c_str(),"rb" ); if (file) { #else if (!fopen_s(&file, fileName.c_str(),"rb" )) { #endif fseek( file,0,SEEK_END ); int fileSize = ftell(file); fseek( file,0,SEEK_SET ); int buffersize = fileSize; buf=new char[buffersize ]; fread( buf,fileSize,1,file ); // buf.resize( fileSize ); // fread( buf.begin(),fileSize,1,file ); fclose(file); XmlNodeRef nodeR =xml.parse( buf,buffersize ,m_errorString ); delete buf; return nodeR; } else { return XmlNodeRef(); } } //! Parse xml from memory buffer. XmlNodeRef XmlParser::parse( const std::vector<char, hb::allocator<char> > &buffer ) { m_errorString = ""; XmlParserImp xml; //return xml.parse( buffer,m_errorString ); assert(0); XmlNodeRef nodeR; return nodeR; };
XmlNodeRef XmlParser::parse(behaviac::IFile* file, const char* rootNodeName, const char* suffix, bool handleError) { BEHAVIAC_UNUSED_VAR(suffix); BEHAVIAC_UNUSED_VAR(handleError); m_errorString.clear(); XmlParserImp xml; if (file) { int iSize = (int)file->GetSize() - (int)file->Seek(0, behaviac::CFileSystem::ESeekMoveMode_Cur); if (iSize != 0) { static const int32_t ReadBlockSize = 64 * 1024; char* buf = (char*)BEHAVIAC_MALLOC_WITHTAG(ReadBlockSize, "XML"); XmlNodeRef ref; for (int32_t i = 0; i <= iSize / (ReadBlockSize); ++i) { int32_t bufSize = file->Read(buf, ReadBlockSize); { buf[bufSize] = '\0'; ref = xml.parse(buf, bufSize, rootNodeName, m_errorString, i == iSize / (ReadBlockSize)); } } BEHAVIAC_FREE(buf); if (handleError && !m_errorString.empty()) { BEHAVIAC_LOGWARNING("Error while parsing file\n\n%s", m_errorString.c_str()); } return ref; } else { return XmlNodeRef(); } } else { BEHAVIAC_ASSERT(0, "XmlParse(behaviac::IFile*) - Invalid file\n"); return XmlNodeRef(); } }