Nanji Mange

Nanji Mange

  • NA
  • 37
  • 5.1k

How to convert text(with html tag) to XML -WordprocessingML?

Aug 31 2016 5:06 AM
I have a string variable. I want to convert it in WordprocessingML(kind of XML). I can convert if I have only string variable(static string) but everytime value of string variable is different. I have tried by didn't get any logical idea.
Example:
  1. Dim strData As String  
  2. strData = "This is <b>Bold</b> Text. This is <i>Italic</i> Text"  
WordprocessingML (kind of XML) conversation:
  1. <?xml version="1.0"?>  
  2. <?mso-application progid="Word.Document"?>  
  3. <w:wordDocument  
  4. xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"  
  5. xml:space="preserve">  
  6. <w:body>  
  7.    <w:p>  
  8.       <w:r>  
  9.          <w:t>This is </w:t>  
  10.       </w:r>  
  11.       <w:r>  
  12.          <w:rPr>  
  13.             <w:b/>  
  14.          </w:rPr>  
  15.          <w:t>Bold</w:t>  
  16.       </w:r>  
  17.       <w:r>  
  18.          <w:t>Text. This is </w:t>  
  19.       </w:r>  
  20.       <w:r>  
  21.          <w:rPr>  
  22.             <w:i w:val="on"/>  
  23.          </w:rPr>  
  24.          <w:t>Italic</w:t>  
  25.       </w:r>  
  26.       <w:r>  
  27.          <w:t>Text</w:t>  
  28.       </w:r>  
  29. </w:p>  
  30. </w:body>  
  31. </w:wordDocument>  
In my case, `strData` can be any string which can have HTML tags for formatting.
Ex:
  1. strData = "This <b>is Bold</b> Text. This is <i>Italic</i> Text"  
  2. strData = "<b><i>This is Bold Text. This is Italic</b></i> Text"  
  3. strData = "<b>This is Bold</b> Text."  
  4. strData = "<b>This is Bold.</b>"  
I have tried to use Replace function but it doesn't work in all cases.
Can anybody suggest me how to convert any string in this kind of format?

Answers (1)