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>
This behavior is based on the XSLT specification, which defines that the whitespace will be preserved if: An ancestor element of the text node has an xml:space attribute with a value of preserve , and no closer ancestor element has xml:space with a value of default .
XML serialization is the process of converting XML data from its representation in the XQuery and XPath data model, which is the hierarchical format it has in a Db2® database, to the serialized string format that it has in an application.
Xml Serializer serializes only public member of object but Binary Serializer serializes all member whether public or private. In Xml Serialization, some of object state is only saved but in Binary Serialization, entire object state is saved.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With