Class hides some XMLTag methods. More...
#include <loaders/xml.h>
Inherits nitro::XMLTag.

Public Member Functions | |
| XMLFile (void) | |
| XMLFile (const char *FilePath) | |
| XMLFile (const std::string &FilePath) | |
| XMLTag & | GetRoot (void) |
| void | LoadXML (const char *FilePath) |
| void | LoadXML (const std::string &FilePath) |
| void | LoadXMLFromANSIString (const char *str) |
| void | SaveXML (const char *FilePath=NULL) |
| virtual | ~XMLFile () |
Private Member Functions | |
| void | ParseHeader (std::vector< std::string > &Lexemmas, std::size_t &i) |
Private Attributes | |
| std::string | Version |
| std::string | Encoding |
| std::string | SerializedXML |
| std::string | OpenFilePath |
Class hides some XMLTag methods.
Definition at line 887 of file xml.h.
| nitro::XMLFile::XMLFile | ( | void | ) |
Default constructor.
| nitro::exception | An exception of that type is thrown if ahy error occured. |
Definition at line 117 of file xml.cpp.
References nitro::exception::code(), Encoding, OpenFilePath, Version, and nitro::exception::what().
{
try
{
Version = "";
Encoding = "";
OpenFilePath = "";
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "XMLFile::XMLFile( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "XMLFile::XMLFile( void )::An error occured" ) , 1 ) );
}
}

| nitro::XMLFile::XMLFile | ( | const char * | FilePath | ) |
Constructor that loads XML from file.
| FilePath | - Path to loading XML file. |
| nitro::exception | An exception of that type is thrown if ahy error occured. |
Definition at line 135 of file xml.cpp.
References nitro::exception::code(), Encoding, LoadXML(), OpenFilePath, Version, and nitro::exception::what().
{
try
{
Version = "";
Encoding = "";
OpenFilePath = FilePath;
LoadXML( FilePath );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "XMLFile::XMLFile( const char * FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "XMLFile::XMLFile( const char * FilePath )::An error occured" ) , 1 ) );
}
}

| nitro::XMLFile::XMLFile | ( | const std::string & | FilePath | ) |
Constructor that loads XML from file.
| FilePath | - Path to loading XML file |
| nitro::exception | An exception of that type is thrown if ahy error occured. |
Definition at line 156 of file xml.cpp.
References nitro::exception::code(), Encoding, LoadXML(), OpenFilePath, Version, and nitro::exception::what().
{
try
{
Version = "";
Encoding = "";
OpenFilePath = FilePath;
LoadXML( FilePath );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "XMLFile::XMLFile( const std::string & FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "XMLFile::XMLFile( const std::string & FilePath )::An error occured" ) , 1 ) );
}
}

| nitro::XMLFile::~XMLFile | ( | ) | [virtual] |
Destructor (virtual).
Definition at line 824 of file xml.cpp.
References nitro::XMLTag::Release().
{
try
{
this->Release();
}
catch( ... )
{
}
}

| XMLTag & nitro::XMLFile::GetRoot | ( | void | ) |
Function return the root element of the file.
| nitro::exception | An exception of that type is thrown if ahy error occured. |
Definition at line 604 of file xml.cpp.
References nitro::exception::code(), and nitro::exception::what().
Referenced by nitro::MVC::Create().
{
try
{
return( dynamic_cast< XMLTag & >( *this ) );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "XMLFile::GetRoot( void )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "XMLFile::GetRoot( void )::An error occured" ) , 1 ) );
}
}

| void nitro::XMLFile::LoadXML | ( | const char * | FilePath | ) |
Function loads XML file.
| FilePath | - Path to loading XML file |
| nitro::exception | An exception of that type is thrown if ahy error occured. |
Definition at line 620 of file xml.cpp.
References nitro::exception::code(), nitro::DispatchBuffer(), nitro::BinaryData::GetBuffer(), nitro::BinaryData::GetBufferLength(), nitro::File::LoadBinDataFromFile(), OpenFilePath, ParseHeader(), and nitro::exception::what().
Referenced by nitro::MVC::Create(), LoadXML(), LoadXMLFromANSIString(), and XMLFile().
{
try
{
OpenFilePath = FilePath;
std::vector< std::string > ProtoText;
std::vector< std::string > Lexemmas;
std::list< nitro::BinaryData > CDATA;
BinaryData BinaryData;
File::LoadBinDataFromFile( BinaryData , std::string( FilePath ) );
DispatchBuffer( BinaryData.GetBuffer() , Lexemmas , BinaryData.GetBufferLength() , CDATA );
std::size_t i( 0 );
std::list< nitro::BinaryData >::iterator j( CDATA.begin() );
ParseHeader( Lexemmas , i );
XMLTag::LoadXML( Lexemmas , i , CDATA , j );
ProtoText.clear();
Lexemmas.clear();
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "XMLFile::LoadXML( const char * FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "XMLFile::LoadXML( const char * FilePath )::An error occured" ) , 1 ) );
}
}

| void nitro::XMLFile::LoadXML | ( | const std::string & | FilePath | ) |
Function loads XML file.
| FilePath | - Path to loading XML file |
| nitro::exception | An exception of that type is thrown if ahy error occured. |
Definition at line 656 of file xml.cpp.
References nitro::exception::code(), LoadXML(), and nitro::exception::what().
{
try
{
LoadXML( FilePath.c_str() );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "XMLFile::LoadXML( const std::string & FilePath )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "XMLFile::LoadXML( const std::string & FilePath )::An error occured" ) , 1 ) );
}
}

| void nitro::XMLFile::LoadXMLFromANSIString | ( | const char * | str | ) |
Function loads XML from const string.
| str | - String with XML. |
| nitro::exception | An exception of that type is thrown if ahy error occured. |
Definition at line 576 of file xml.cpp.
References nitro::DispatchBuffer(), LoadXML(), OpenFilePath, ParseHeader(), and nitro::exception::what().
{
try
{
OpenFilePath = "";
std::vector< std::string > Lexemmas;
std::list< nitro::BinaryData > CDATA;
DispatchBuffer( str , Lexemmas , strlen( str ) , CDATA );
std::size_t i( 0 );
std::list< nitro::BinaryData >::iterator j( CDATA.begin() );
ParseHeader( Lexemmas , i );
XMLTag::LoadXML( Lexemmas , i , CDATA , j );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "XMLFile::LoadXMLFromANSIString( const char * str )::" ) + e.what() , 1 ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "XMLFile::LoadXMLFromANSIString( const char * str )::An error occured" ) , 1 ) );
}
}

| void nitro::XMLFile::ParseHeader | ( | std::vector< std::string > & | Lexemmas, | |
| std::size_t & | i | |||
| ) | [private] |
This function parse xml header <?xml version=....?>
| Lexemmas | - XML file splitted into tag names, tag parameters and special simbols. | |
| i | - Cursor for array Lexemmas. |
Definition at line 1016 of file xml.cpp.
References nitro::exception::code(), Encoding, nitro::IsTagName(), Version, and nitro::exception::what().
Referenced by LoadXML(), and LoadXMLFromANSIString().
{
try
{
if( Lexemmas.size() < 6 )
{
throw( nitro::exception( "Bad XML structure" , 1 ) );
}
if( Lexemmas[ 0 ] != "<" || Lexemmas[ 1 ] != "?" || Lexemmas[ 2 ] != "xml" )
{
return;
}
i = 3;
for( std::size_t k( 3 ) ; k < Lexemmas.size() ; k += 5 , i += 5 )
{
if( IsTagName( Lexemmas[ k ] ) && Lexemmas[ k + 1 ] == "=" && Lexemmas[ k + 2 ] == "\"" )
{
if( Lexemmas[ k ] == "version" )
{
Version = Lexemmas[ k + 3 ];
goto next_iter;
}
if( Lexemmas[ k ] == "encoding" )
{
Encoding = Lexemmas[ k + 3 ];
goto next_iter;
}
}
else
{
if( Lexemmas[ k ] == "?" && Lexemmas[ k + 1 ] == ">" )
{
i += 2;
return;
}
else
{
throw( nitro::exception( "Bad XML structure" , 1 ) );
}
}
next_iter:;
}
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "XMLFile::ParseHeader( std::vector< std::string > & Lexemmas , std::size_t & i )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "XMLFile::ParseHeader( std::vector< std::string > & Lexemmas , std::size_t & i )::An error occured" ) , 1 ) );
}
}

| void nitro::XMLFile::SaveXML | ( | const char * | FilePath = NULL |
) |
Function saves XML faile into file.
| FilePath | - Path to the destination file. |
| nitro::exception | An exception of that type is thrown if ahy error occured. |
Definition at line 770 of file xml.cpp.
References nitro::exception::code(), Encoding, nitro::FA_FILE_BINARY, nitro::FA_FILE_TRUNCATE, nitro::FA_FILE_WRITE, nitro::FileAbstraction::Open(), OpenFilePath, Version, nitro::exception::what(), and nitro::FileAbstraction::Write().
{
try
{
nitro::FileAbstraction File;
if( FilePath )
{
OpenFilePath = FilePath;
File.Open( FilePath , nitro::FA_FILE_WRITE | nitro::FA_FILE_BINARY | nitro::FA_FILE_TRUNCATE );
}
else
{
File.Open( OpenFilePath.c_str() , nitro::FA_FILE_WRITE | nitro::FA_FILE_BINARY | nitro::FA_FILE_TRUNCATE );
}
if( Version != "" || Encoding != "" )
{
std::string str;
str = "<?xml ";
File.Write( str.c_str() , str.length() );
if( Version != "" )
{
str = "version=\"";
str += Version;
str += "\" ";
File.Write( str.c_str() , str.length() );
}
if( Encoding != "" )
{
str = "encoding=\"";
str += Encoding;
str += "\" ";
File.Write( str.c_str() , str.length() );
}
str = "?>\n";
File.Write( str.c_str() , str.length() );
}
XMLTag::SaveXML( File , "" );
}
catch( nitro::exception e )
{
throw( nitro::exception( std::string( "XMLFile::SaveXML( const char * FilePath /* = NULL */ )::" ) + e.what() , e.code() ) );
}
catch( ... )
{
throw( nitro::exception( std::string( "XMLFile::SaveXML( const char * FilePath /* = NULL */ )::An error occured" ) , 1 ) );
}
}

std::string nitro::XMLFile::Encoding [private] |
std::string nitro::XMLFile::OpenFilePath [private] |
std::string nitro::XMLFile::SerializedXML [private] |
std::string nitro::XMLFile::Version [private] |
Version of the XML format.
Definition at line 1070 of file xml.h.
Referenced by ParseHeader(), SaveXML(), and XMLFile().
1.6.1