Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

wxWidgets and TinyXML

Name: Anonymous 2007-12-21 22:47

I'm having a bit of trouble saving formatted text from a wxRichTextBox control. I don't normally go to forums for help, but I'm depressed and cloudy-headed today and I feel like being called a faggot. Here's how I'm doing it now:


// Create the XML document and ready it to be appended.
   TiXmlDocument xmlDocument;
   TiXmlDeclaration* p_decDeclaration = new TiXmlDeclaration( "1.0", "", "" );
   xmlDocument.LinkEndChild( p_decDeclaration );

   // Create the story and body sections.
   TiXmlElement* p_xleStory = new TiXmlElement( "story" );
   xmlDocument.LinkEndChild( p_xleStory );
   TiXmlElement* p_xleStoryBody = new TiXmlElement( "body" );
   p_xleStory->LinkEndChild( p_xleStoryBody );

   // Parse the text box character by character, build strings of like-
   // formatted characters, and link them to the story's body text as
   // children nodes.
   //TiXmlText* p_xltBody = new TiXmlText( (char*)p_txtMain->GetValue().char_str() );
   //p_xleStoryBody->LinkEndChild( p_xltBodyLine );
   TiXmlText* p_xltBodyLine = NULL;
   wxString strChildBuffer;
   //TiXmlNode* p_xleBodyTextParentNew = NULL;
   TiXmlNode* p_xleBodyTextParent = p_xleStoryBody;
   for( unsigned long intCountPos = 1 ; intCountPos < p_txtMain->GetValue().Len() ; intCountPos++ ) {


      wxRichTextAttr atrCurrent;
      wxRichTextAttr atrPrevious;
      p_txtMain->GetStyle( intCountPos, atrCurrent );
      p_txtMain->GetStyle( intCountPos - 1, atrPrevious );

      // Using this arrangement, bold will always be "outermost".

      if( atrCurrent.HasFontWeight() == true && atrPrevious.HasFontWeight() == false ) {
         // Finish up the current child.
         p_xltBodyLine = new TiXmlText( (char*)strChildBuffer.char_str() );
         p_xleBodyTextParent->LinkEndChild( p_xltBodyLine );

         // Bold has just been turned on.
         TiXmlElement* p_xleBodyTextParentNew = new TiXmlElement( "strong" );
         p_xleBodyTextParent->LinkEndChild( p_xleBodyTextParentNew );
         p_xleBodyTextParent = p_xleBodyTextParentNew;

         // Clean up.
         strChildBuffer = _( "" );
         p_xltBodyLine = NULL;
      }

      if( atrCurrent.HasFontItalic() == true && atrPrevious.HasFontItalic() == false ) {
         // Finish up the current child.
         p_xltBodyLine = new TiXmlText( (char*)strChildBuffer.char_str() );
         p_xleBodyTextParent->LinkEndChild( p_xltBodyLine );

         // Italic text has just been turned on.
         TiXmlElement* p_xleBodyTextParentNew = new TiXmlElement( "em" );
         p_xleBodyTextParent->LinkEndChild( p_xleBodyTextParentNew );
         p_xleBodyTextParent = p_xleBodyTextParentNew;

         // Clean up.
         strChildBuffer = _( "" );
         p_xltBodyLine = NULL;
      }

      if( atrCurrent.HasFontItalic() == false && atrPrevious.HasFontItalic() == true ) {
         // Finish up the current child.
         p_xltBodyLine = new TiXmlText( (char*)strChildBuffer.char_str() );
         p_xleBodyTextParent->LinkEndChild( p_xltBodyLine );

         // Italic text has just been turned off.
         p_xleBodyTextParent = p_xleBodyTextParent->Parent();

         // Clean up.
         strChildBuffer = _( "" );
         p_xltBodyLine = NULL;
      }

      if( atrCurrent.HasFontWeight() == false && atrPrevious.HasFontWeight() == true ) {
         // Finish up the current child.
         p_xltBodyLine = new TiXmlText( (char*)strChildBuffer.char_str() );
         p_xleBodyTextParent->LinkEndChild( p_xltBodyLine );

         // Bold text has just been turned off.
         p_xleBodyTextParent = p_xleBodyTextParent->Parent();

         // Clean up.
         strChildBuffer = _( "" );
         p_xltBodyLine = NULL;
      }

      // Now that we've dealt with the last of that buffer, start building
      // anew.
      strChildBuffer.Append( p_txtMain->GetValue().Mid( intCountPos, intCountPos + 1 ) );
   }

   xmlDocument.SaveFile( (char*)strFilePathIn.char_str() );


Needless to say, it doesn't work. I don't think I understand the RichText control well enough, despite the documentation. Or my algorithm's just stupid. How would you do this, /prog/?

Name: Anonymous 2007-12-22 12:09

TiXmlDocument xmldocument; TiXmlDeclaration, p xltbodyline TiXmlElement,
story p decdeclaration new TiXmlDeclaration p xlebodytextparent Parent,
strchildbuffer p xlebodytextparent p xlebodytextparentnew new
TiXmlElement new TiXmlText, TiXmlElement, story p decdeclaration new
TiXmlElement, story p xlebodytextparent p char str, p xlestory
TiXmlElement p txtmain GetStyle, GetValue, Len, intcountpos atrprevious
p xltbodyline NULL.  TiXmlDocument xmldocument: TiXmlDeclaration, p
xlebodytextparent p decdeclaration new TiXmlElement body p txtmain
GetValue (Len, intcountpos intcountpos intcountpos p txtmain GetStyle
intcountpos intcountpos wxrichtextattr atrcurrent p xltbodyline NULL:
xlebodytextparent p xltbodyline p txtmain GetStyle intcountpos
atrprevious).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List