I have the following serialization method:
Private Function SerializeData(ByVal data As cData) As String If data IsNot Nothing Then Dim xml_stream As New MemoryStream() Dim sr As StreamReader Dim xs As New XmlSerializer(GetType(cData)) xml_stream = New MemoryStream() Try xs.Serialize(xml_stream, data) xml_stream.Position = 0 sr = New StreamReader(xml_stream) Return sr.ReadToEnd() Finally If sr IsNot Nothing Then sr.Close() xml_stream.Close() End Try Else Return 'No data' End If End Function
however it returns the xml the nested elements indented. Is there a way to shut that off on the serializer, or do I need to just run a find replace routine to get rid of it all?
Essentially, what I want to see is:
<root><child1>data</child1><child2>data</child2></root>
Use the Serialize override that accepts an XmlWriter parameter. Create the XmlWriter using XmlWriter::Create, passing in an XmlWriterSettings object with the Indent property set to false.