关于使用XmlSerializer 序列化和反序列化的问题?
aspx页面上有MagnetPullStrength,MagnetGrade,VisibleCustomerID三个textbox控件,现在需要将这三个框内的值以XML序...
aspx页面上有MagnetPullStrength,MagnetGrade,VisibleCustomerID三个textbox控件,现在需要将这三个框内的值以XML序列化存入到product表内ExtensionData这一列内(原话the data must be serialized into XML and stored only in the one column named ExtensionData.),并且读取的时候也要用反序列化来读取。
可是在msdn上看了还是不太明白要怎么弄
http://msdn.microsoft.com/zh-cn/library/system.xml.serialization.xmlserializer.aspx
要求的存入数据库的格式大概是这样
<ExtensionData>
<MagnetPullStrength>123
</MagnetPullStrength>
<MagnetGrade>23
<MagnetGrade>
<VisibleCustomerID>12,22,21,34,54,58639
</VisibleCustomerID>
</ExtensionData>
求助各位大大帮忙指点下 最好有代码例子 谢谢了
必须要用到XmlSerializer这个类 展开
可是在msdn上看了还是不太明白要怎么弄
http://msdn.microsoft.com/zh-cn/library/system.xml.serialization.xmlserializer.aspx
要求的存入数据库的格式大概是这样
<ExtensionData>
<MagnetPullStrength>123
</MagnetPullStrength>
<MagnetGrade>23
<MagnetGrade>
<VisibleCustomerID>12,22,21,34,54,58639
</VisibleCustomerID>
</ExtensionData>
求助各位大大帮忙指点下 最好有代码例子 谢谢了
必须要用到XmlSerializer这个类 展开
2个回答
展开全部
[XmlRootAttribute("Extensiondata", IsNullable = false)]
public class Extensiondata
{
public string MagnetPullStrength;
public string MagnetGrade;
public string VisibleCustomerID;
}
XmlSerializer serializer = new XmlSerializer(typeof(Extensiondata));
TextWriter writer = new StreamWriter(CommonLogic.SafeMapPath("images\\po.xml"));
Extensiondata po = new Extensiondata();
po.MagnetPullStrength = TextBox1.Text;
po.MagnetGrade = TextBox2.Text;
po.VisibleCustomerID = TextBox3.Text;
serializer.Serialize(writer, po);
writer.Close();
public class Extensiondata
{
public string MagnetPullStrength;
public string MagnetGrade;
public string VisibleCustomerID;
}
XmlSerializer serializer = new XmlSerializer(typeof(Extensiondata));
TextWriter writer = new StreamWriter(CommonLogic.SafeMapPath("images\\po.xml"));
Extensiondata po = new Extensiondata();
po.MagnetPullStrength = TextBox1.Text;
po.MagnetGrade = TextBox2.Text;
po.VisibleCustomerID = TextBox3.Text;
serializer.Serialize(writer, po);
writer.Close();
展开全部
建一个类
[XmlRoot("ExtensionData")]
class ExtensionData{
[XmlElement("MagnetPullStrength")]
public int MagnetPullStrength{ get; set; }
[XmlElement("MagnetGrade")]
public int MagnetGrade{ get; set; }
[XmlElement("VisibleCustomerID")]
public string VisibleCustomerID{ get; set; }
}
[XmlRoot("ExtensionData")]
class ExtensionData{
[XmlElement("MagnetPullStrength")]
public int MagnetPullStrength{ get; set; }
[XmlElement("MagnetGrade")]
public int MagnetGrade{ get; set; }
[XmlElement("VisibleCustomerID")]
public string VisibleCustomerID{ get; set; }
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询