I'm having dufficulty figuring out how to serialize a String property
[
XmlElement("DescriptionDelimiter1")]publicString DescriptionDelimiter1
{
get { return _DescriptionDelimiter1; }
set { _DescriptionDelimiter1 = value; }
}
Granted, I don't really need the XmlElement tag but just in case I want to change the name of the XML element...
Anyway, what I get in XML is
<
ImportProfiles><ImportProfileName="HPH Import Profile">
<ConcatenateDescriptions>true</ConcatenateDescriptions>
<DescriptionDelimiter1 />
<DescriptionDelimiter2>\r\n</DescriptionDelimiter2>
<DescriptionDelimiter3>\t</DescriptionDelimiter3>
<ImportProfile>
</ImportProfiles>
The problem is when serialized, if the value is " " or a single space, the result is <DescriptionDelimiter1 /> which when deserialized sets the string's value to "" with is not the value I need. I've looked into using CData but there doesn't seem to be a simple way to implement it... I expect
<DescriptionDelimiter1> </DescriptionDelimiter1>
or
<DescriptionDelimiter1><[CDATA[ ]]></DescriptionDelimiter1>
Is there some setting I can use when serializing the object to indication the process should not trim away whitespace?
The following is the method used to serialize my object:
publicstaticString Serialize(DataImportBase dib){
System.Type[] ArrType = newType[1];
ArrType[0] = typeof(System.DBNull);
XmlSerializer xs = newXmlSerializer(typeof(DataImportBase), ArrType);
System.IO.MemoryStream aMemoryStream = new System.IO.MemoryStream();
xs.Serialize(aMemoryStream, dib);
return System.Text.Encoding.UTF8.GetString(aMemoryStream.ToArray());
}
Thanks for any assistance!!!
Chris