1 自定义业务类 TO XElement类型
XmlSerializer serializer = new XmlSerializer(typeof(CFEDataAnalysis));
System.IO.Stream writer = new System.IO.MemoryStream();
serializer.Serialize(writer, analysis);
byte[] Result = new byte[writer.Length];
writer.Seek(0, SeekOrigin.Begin);
writer.Read(Result, 0, Convert.ToInt32(writer.Length));
XElement analysisContent = XElement.Parse(System.Text.Encoding.Default.GetString(Result));
System.IO.Stream writer = new System.IO.MemoryStream();
serializer.Serialize(writer, analysis);
byte[] Result = new byte[writer.Length];
writer.Seek(0, SeekOrigin.Begin);
writer.Read(Result, 0, Convert.ToInt32(writer.Length));
XElement analysisContent = XElement.Parse(System.Text.Encoding.Default.GetString(Result));
2 XElement类型 TO 自定义业务类
CFEDataAnalysis cfeDataAnalysis = new CFEDataAnalysis();
XElement analysisContent = dataAnalysi.AnalysisContent;
XmlSerializer serializer = new XmlSerializer(typeof(CFEDataAnalysis));
using (StringReader reader = new StringReader(analysisContent.ToString()))
{
cfeDataAnalysis = (CFEDataAnalysis)serializer.Deserialize(reader);
}
XElement analysisContent = dataAnalysi.AnalysisContent;
XmlSerializer serializer = new XmlSerializer(typeof(CFEDataAnalysis));
using (StringReader reader = new StringReader(analysisContent.ToString()))
{
cfeDataAnalysis = (CFEDataAnalysis)serializer.Deserialize(reader);
}