|  | 
| MFC. Extract text from markup | 
| Post Reply   | 
| Author | |
| zaksoft   Senior Member     Joined: 05 June 2003 Location: Italy Status: Offline Points: 163 |  Post Options  Thanks(0)  Quote  Reply  Topic: MFC. Extract text from markup Posted: 20 May 2008 at 4:09am | 
| 
   I have the need to get text from a makup control. This control is a preview of some information and it's very fancy to present to user information in a rich way, but I also need to store these information on request... At this point I can of course rebuild all information without markup.. but the better way (for me of course) is to have a command that remove <bold>, <grid> and so on from the full string.
 Any hint ? TIA | |
| 
     VS2022 - MFC MBCS Statically linked XTP 23.1 Static Link --------------------------------------------------------- Davide Zaccanti - ZakSoft - www.zaksoft.com | |
|  | |
| Oleg   Senior Member   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |  Post Options  Thanks(0)  Quote  Reply  Posted: 20 May 2008 at 1:45pm | 
| 
   Hi,
 Here some start: if (pUIElement) { for (int i = 0; i < pUIElement->GetVisualChildrenCount(); i++) { CXTPMarkupVisual* pVisual = pUIElement->GetVisualChild(i);    if (pVisual->IsKindOf(MARKUP_TYPE(CXTPMarkupRun))) { CXTPMarkupRun* p = (CXTPMarkupRun*)pVisual; CString str = p->GetText(); ... }   [ CallRec(pVisual);]  }  } so you need call it recursively and find all Runs. | |
| 
     Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS | |
|  | |
| zaksoft   Senior Member     Joined: 05 June 2003 Location: Italy Status: Offline Points: 163 |  Post Options  Thanks(0)  Quote  Reply  Posted: 28 May 2008 at 3:00am | 
| 
   to your markupstatic.cpp code in markup sample I've added this function:
 void CMarkupStatic::GetInnerText( CString& sContent, CXTPMarkupVisual* pParent){ ASSERT( pParent); for (int i = 0; i < pParent->GetVisualChildrenCount(); i++) { CXTPMarkupVisual* pVisual = pParent->GetVisualChild( i); ASSERT( pVisual); if ( pVisual->IsKindOf(MARKUP_TYPE(CXTPMarkupRun))) { CXTPMarkupRun* p = (CXTPMarkupRun*)pVisual; sContent += p->GetText(); } GetInnerText( sContent, pVisual); } } Called as GetInnerText( sContent, m_pUIElement); but the resulting string is empty... what's wrong ? can you please help me ? TIA | |
| 
     VS2022 - MFC MBCS Statically linked XTP 23.1 Static Link --------------------------------------------------------- Davide Zaccanti - ZakSoft - www.zaksoft.com | |
|  | |
| zaksoft   Senior Member     Joined: 05 June 2003 Location: Italy Status: Offline Points: 163 |  Post Options  Thanks(0)  Quote  Reply  Posted: 03 June 2008 at 1:45pm | 
| 
   Anyone can help me in make the previous code working ?
 TIA | |
| 
     VS2022 - MFC MBCS Statically linked XTP 23.1 Static Link --------------------------------------------------------- Davide Zaccanti - ZakSoft - www.zaksoft.com | |
|  | |
| Oleg   Senior Member   Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |  Post Options  Thanks(0)  Quote  Reply  Posted: 03 June 2008 at 2:16pm | 
| 
   Hi,
 Here working version. Sorry need Logical Childs: voidCMarkupStatic::GetInnerText( CString& sContent, CXTPMarkupObject* pParent) {ASSERT( pParent); for (int i = 0; i < pParent->GetLogicalChildrenCount(); i++) {CXTPMarkupObject* pVisual = pParent->GetLogicalChild(i); ASSERT( pVisual); if ( pVisual->IsKindOf(MARKUP_TYPE(CXTPMarkupRun))) {CXTPMarkupRun* p = (CXTPMarkupRun*)pVisual; sContent += p->GetText(); } GetInnerText( sContent, pVisual); } } | |
| 
     Oleg, Support Team CODEJOCK SOFTWARE SOLUTIONS | |
|  | |
| zaksoft   Senior Member     Joined: 05 June 2003 Location: Italy Status: Offline Points: 163 |  Post Options  Thanks(0)  Quote  Reply  Posted: 03 June 2008 at 4:08pm | 
| 
   thank you, this code works and with some small enhancements I've added the auto-recognition of TaskPanel end to add a CR+LF to break block of text (and also spaces betwwen block).
 What I'm not able to do is insert line feed after a row of a grid, infact using border as marker a line feed is added after each column. two questions: 1) Any suggestion to detect end of row ? 2) Do you plan o add a more generic and well done function to extract text in future release ? Thank you agin for your support. | |
| 
     VS2022 - MFC MBCS Statically linked XTP 23.1 Static Link --------------------------------------------------------- Davide Zaccanti - ZakSoft - www.zaksoft.com | |
|  | |
| Post Reply   | |
| Tweet | 
| Forum Jump | Forum Permissions  You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |