我有一个包含以下内容的课程:
[Serializable]
public class ClsStatus
{
public byte[] Image { get; set; }
public string Status { get; set; }
public List<string> Servers { get; set; }
}
现在我在做:
System.Drawing.Image image = null;
byte[] imageBytes = null;
// Create an image of the chart.
using (MemoryStream s = new MemoryStream())
{
chart.ExportToImage(s, System.Drawing.Imaging.ImageFormat.Jpeg);
image = System.Drawing.Image.FromStream(s);
imageBytes = s.ToArray();
}
ClsStatus status = new ClsStatus();
List<string> servers = new List<string>();
servers.Add("Server1");
servers.Add("Server2");
servers.Add("Server2");
status.Image = imageBytes;
status.Status = "Up & Running";
status.Servers = servers;
//XML Serialization
XmlDocument doc = new XmlDocument();
XmlSerializer serializer = new XmlSerializer(status.GetType());
MemoryStream stream = new MemoryStream();
try
{
serializer.Serialize(stream, status);
stream.Position = 0;
doc.Load(stream);
Response.ContentType = "text/xml";
Response.Clear();
Response.Write(doc.InnerXml);
}
catch
{
throw;
}
My Desired out put和上面代码的内容在这里: http://i.stack.imgur.com/YgKgH.jpg
有没有人可以帮助我解决我的问题?
此致 Mohin酒店
答案 0 :(得分:1)
XML几乎是一种基于文本的格式,这意味着您无法在XML文档中“看到图像”。
最接近的是将二进制图像数据编码为“文本”字符串(通常通过Base64编码),然后将字符串嵌入到XML文档中。这正是你现在所得到的。