AccessBlog.net

News, links, downloads, tips and tricks on Microsoft Access and related

About Me Search
Alex
Name:Alex Dybenko

Location:Moscow, Russia

Monday, December 26, 2011

Replace special characters for XML

If you are writing custom function for XML export – do not forget to replace predefined XML characters, else XML parsing function may fail. There are only 5 characters, so function looks pretty simple:

Function XMLSpecialChars(ByVal varText As Variant) As String 
  varText = varText & ""
  varText = Replace(varText, "&", "&")
  varText = Replace(varText, "'", "'")
  varText = Replace(varText, """", """)
  varText = Replace(varText, ">", ">")
  varText = Replace(varText, "<", "&lt;")
  XMLSpecialChars = varText
End Function

Labels: