3 // *****************************************************************************
4 // *****************************************************************************
8 // *****************************************************************************
9 // *****************************************************************************
11 TXML::TXML ( int f , int t , string &s , bool fix_comments )
15 name = s.substr ( from + 1 , to - (from+1) ) ;
16 name = trim ( name ) ;
17 name = before_first ( ' ' , name ) ;
18 closing = selfclosing = false ;
19 if ( left ( name , 1 ) == "/" )
22 name = name.substr ( 1 , name.length()-1 ) ;
24 if ( right ( name , 1 ) == "/" )
27 name = name.substr ( 0 , name.length()-1 ) ;
29 name = trim ( name ) ;
31 // This will replace < and > within a comment with the appropriate HTML entities
32 if ( fix_comments && left ( name , 1 ) == "!" )
35 for ( a = from+1 ; a < to ; a++ )
37 if ( s[a] != '>' && s[a] != '<' ) continue ;
39 if ( s[a] == '>' ) s.insert ( a , ">" ) ;
40 if ( s[a] == '<' ) s.insert ( a , "<" ) ;
46 void TXML::remove_at ( int pos )
48 if ( pos < from ) from-- ;
49 if ( pos < to ) to-- ;
52 void TXML::insert_at ( int pos )
54 if ( pos < from ) from++ ;
55 if ( pos < to ) to++ ;
58 void TXML::add_key_value ( string k , string v )
60 key.push_back ( trim ( k ) ) ;
61 value.push_back ( trim ( v ) ) ;
64 string TXML::get_string ()
68 for ( size_t a = 0 ; a < key.size() ; a++ )
70 for ( size_t b = 0 ; b < key[a].length() ; b++ )
72 if ( key[a][b] == ' ' ) key[a][b] = '_' ;
75 if ( value[a] != "" ) ret += "=\"" + unquote ( SINGLE_QUOTE , value[a] ) + "\"" ;
77 if ( text == "" ) ret += "/>" ;
78 else ret += ">" + text + "</" + name + ">" ;