#include #include #include #include std::string create_xml( std::vector & ,std::vector & ) ; int main( ) { std::vector names , remarks ; names.push_back( "April" ) ; names.push_back( "Tam O'Shantor" ) ; names.push_back ( "Emily" ) ; remarks.push_back( "Bubbly, I'm > Tam and <= Emily" ) ; remarks.push_back( "Burns: \"When chapman billies leave the street ...\"" ) ; remarks.push_back( "Short & shrift" ) ; std::cout << "This is in XML:\n" ; std::cout << create_xml( names , remarks ) << std::endl ; return 0 ; } std::string create_xml( std::vector & names , std::vector & remarks ) { std::vector > entities ; entities.push_back( std::make_pair( "&" , "&" ) ) ; entities.push_back( std::make_pair( "<" , "<" ) ) ; entities.push_back( std::make_pair( ">" , ">" ) ) ; std::string xmlstring ( "\n" ) ; std::vector::iterator vsi = names.begin( ) ; typedef std::vector >::iterator Vpss ; for ( ; vsi != names.end( ) ; vsi++ ) { for ( Vpss vs = entities.begin( ) ; vs != entities.end( ) ; vs++ ) { boost::replace_all ( *vsi , vs->first , vs->second ) ; } } for ( vsi = remarks.begin( ) ; vsi != remarks.end( ) ; vsi++ ) { for ( Vpss vs = entities.begin( ) ; vs != entities.end( ) ; vs++ ) { boost::replace_all ( *vsi , vs->first , vs->second ) ; } } for ( int i = 0 ; i < names.size( ) ; i++ ) { xmlstring.append( "\t") .append( remarks[ i ] ).append( "\n" ) ; } xmlstring.append( "" ) ; return xmlstring ; }