J
Julie
Hi everyone,
I have a method that serializes an object to xml. I was wondering if there
is a way to stop the namespaces from appearing? (these:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema")
Public Shared Function Serialize(Of T)(ByVal options As T) As String
Dim lsResult As String = String.Empty
Dim loSerializer As Xml.Serialization.XmlSerializer = Nothing
Dim loStringWriter As System.IO.StringWriter = Nothing
Dim loXmlWriter As Xml.XmlTextWriter = Nothing
If options Is Nothing Then Return lsResult
Try
loSerializer = New
Xml.Serialization.XmlSerializer(options.GetType)
loStringWriter = New System.IO.StringWriter()
loXmlWriter = New Xml.XmlTextWriter(loStringWriter)
loXmlWriter.Formatting = Xml.Formatting.None
loSerializer.Serialize(loXmlWriter, options)
lsResult = loStringWriter.ToString
Catch ex As Exception
Throw ex
Finally
If loStringWriter IsNot Nothing Then loStringWriter.Close()
End Try
Return lsResult
End Function
I have a method that serializes an object to xml. I was wondering if there
is a way to stop the namespaces from appearing? (these:
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema")
Public Shared Function Serialize(Of T)(ByVal options As T) As String
Dim lsResult As String = String.Empty
Dim loSerializer As Xml.Serialization.XmlSerializer = Nothing
Dim loStringWriter As System.IO.StringWriter = Nothing
Dim loXmlWriter As Xml.XmlTextWriter = Nothing
If options Is Nothing Then Return lsResult
Try
loSerializer = New
Xml.Serialization.XmlSerializer(options.GetType)
loStringWriter = New System.IO.StringWriter()
loXmlWriter = New Xml.XmlTextWriter(loStringWriter)
loXmlWriter.Formatting = Xml.Formatting.None
loSerializer.Serialize(loXmlWriter, options)
lsResult = loStringWriter.ToString
Catch ex As Exception
Throw ex
Finally
If loStringWriter IsNot Nothing Then loStringWriter.Close()
End Try
Return lsResult
End Function