none
How to save as xml (custom dtd) for text element RRS feed

  • Question

  • Hi, 

    I am building document content into custom xml that validtes against DTD defined. One place I stuck with accessing style of content for eg:

    if I have text like 

    This is example TestText 

    I would like to convert into as 

    <p> This <b><i> is </i></b> example <b><u> Test </u></b> Text </p>
    

    I am accessing Text from 

    var text = paragraph.Range.Text

    I did tried getting style information from paragraph.Range.WordOpenXml but it returns with all styles and package information and i have to go . through each and every text to transform this content. this definitely ruled out.

    Is there any recommended way to handle these styles on text? I am interested only on Bold, Underline and Itallic.


    Monday, July 2, 2012 4:12 PM

Answers

  • Hi Swithup

    It's been a while since I worked intensively with XSL transforms, but I seem to recall that you can set up the criteria in a transform to "filter out" everything except what you're interested in. So can't you set it up to return only the text and the elements you want, discarding all the other elements getting in your way? The right place to ask how to do that would be a forum specializing in XSL.

    There's nothing in the Word object model that can do that for you. The only other possible approach would be to "walk" each and every character in the document and check whether it's formatted bold or italic. If this is a long document, that could take quite a while...


    Cindy Meister, VSTO/Word MVP

    Wednesday, July 4, 2012 8:22 AM
    Moderator

All replies

  • Hi,

    Based on your issue, I am unclear of what you desired. Would you please explain more details about your question?  Also, there is a thread which give some ideas of converting word document into XML.http://social.msdn.microsoft.com/forums/en-us/csharplanguage/thread/1C43E4D9-5DBE-4E13-91D0-ABB3693EBF77

    Hope it helps.

    regards,

    leo

    Wednesday, July 4, 2012 5:34 AM
  • Hi Swithup

    It's been a while since I worked intensively with XSL transforms, but I seem to recall that you can set up the criteria in a transform to "filter out" everything except what you're interested in. So can't you set it up to return only the text and the elements you want, discarding all the other elements getting in your way? The right place to ask how to do that would be a forum specializing in XSL.

    There's nothing in the Word object model that can do that for you. The only other possible approach would be to "walk" each and every character in the document and check whether it's formatted bold or italic. If this is a long document, that could take quite a while...


    Cindy Meister, VSTO/Word MVP

    Wednesday, July 4, 2012 8:22 AM
    Moderator