Sanitizing XML of serialized objects

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joepv
    New Member
    • Oct 2011
    • 1

    Sanitizing XML of serialized objects

    For a webservice I use this code to serialize the response:

    Dim XmlizedString As [String] = Nothing
    Dim memoryStream As New MemoryStream()
    Dim xs As New XmlSerializer(p Object.GetType)
    Dim xmlTextWriter As New Xml.XmlTextWrit er(memoryStream , System.Text.Enc oding.UTF8)
    xs.Serialize(xm lTextWriter, pObject)
    memoryStream = DirectCast(xmlT extWriter.BaseS tream, MemoryStream)
    Dim r As Byte() = memoryStream.To Array()
    Return r

    Unfortunately the object serialized sometimes has strings that contain bad characters like x01B. The client chokes on those. Instead of cleaning the strings before serializing (which would have to be done in literally hundreds of places) I want the serializer to just skip them. Is there a way to do that?
Working...