Embedding Special Character in Element Value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jsweeney
    New Member
    • Aug 2008
    • 2

    Embedding Special Character in Element Value

    Beth Massi has an excellent article on merging data with docx using Visual Basic - click here for the article

    In the article, she cuts and pastes the document.xml file to create an XDocument, then manually replaces the Word field delimiters (« ») with ASP field delimiters (<%= %>).

    I have developed a method that takes the path/file name of the docx merge file and programmaticall y extracts the document.xml, then recursively loops through the elements and does a replace on the delimiters for the element values.

    My problem is that the < and > characters are being escaped. Beth's example works like a charm with the manual replacement, but the Replace method in VB is not providing the same result. Here is the function I wrote:

    Code:
        Private Function FixDelimeter(ByRef xElems As IEnumerable(Of XElement)) As Boolean
            Dim pXElem As XElement
    
            Try
    
                For Each pXElem In xElems
                    pXElem.Value = pXElem.Value.Replace("«", "<%= row(""").Replace("»", """) %>")
                    If pXElem.Elements.Count > 0 Then
                        FixDelimeter(pXElem.Elements)
                    End If
                Next
    
            Catch ex As Exception
    
                Throw
    
            Finally
    
                pXElem = Nothing
    
            End Try
    
        End Function
    Any suggestions for inserting the characters unescaped would be welcome!
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    maybe a CDATA section?

    Comment

    Working...