XmlTextAttribute:[XmlType(Namespace="http://www.mingchentest.com/", TypeName="Mixed")]
public class MixedTest {
public string Bold1;
[XmlText]
public string InnerText;
public string Bold2;
public override string ToString() {
return Bold1 + InnerText + Bold2;
}
public static void Main() {
MixedTest mt = new MixedTest();
mt.Bold1 = "Header:";
mt.Bold2 = "Foot:";
mt.InnerText = " Something here ";
Console.WriteLine(mt);
XmlSerializer xs = new XmlSerializer(typeof(MixedTest));
using(FileStream fs = new FileStream("mixed.xml", FileMode.Create, FileAccess.Write)) {
xs.Serialize(fs, mt);
}
using(FileStream fs = new FileStream("mixed.xml", FileMode.Open, FileAccess.Read)) {
MixedTest mt1 = xs.Deserialize(fs) as MixedTest;
if (mt1 != null) {
Console.WriteLine(mt1);
}
}
}
}
public class MixedTest {
public string Bold1;
[XmlText]
public string InnerText;
public string Bold2;
public override string ToString() {
return Bold1 + InnerText + Bold2;
}
public static void Main() {
MixedTest mt = new MixedTest();
mt.Bold1 = "Header:";
mt.Bold2 = "Foot:";
mt.InnerText = " Something here ";
Console.WriteLine(mt);
XmlSerializer xs = new XmlSerializer(typeof(MixedTest));
using(FileStream fs = new FileStream("mixed.xml", FileMode.Create, FileAccess.Write)) {
xs.Serialize(fs, mt);
}
using(FileStream fs = new FileStream("mixed.xml", FileMode.Open, FileAccess.Read)) {
MixedTest mt1 = xs.Deserialize(fs) as MixedTest;
if (mt1 != null) {
Console.WriteLine(mt1);
}
}
}
}
解决方案 »
- 紧急求助!!!!
- asp.net本地运行网站时,提示:无法启动程序"http:localhost:9810/Web/Default.aspx"
- datagridview绑定值
- 我在别人的源代码中改一下服务器地址,报生成错误是怎么回事?新手
- 求一个正则表达式
- treeView前面的“+”号不点击下,不显示!
- 用VS2005的,帮我试试
- 重金奖---解决如下问题者
- web service问题!!!
- DataGridView 中批量删除写入数据库的语句(access)是怎样写的?
- 【紧急求助】 关于textbox在自己的函数中如何调用的问题
- 如何在datatable中,去掉一行。例如知道某行第几列的值,从而把这一行删掉?
不过问题好像没有解决
如果把
mt.InnerText = " Something here ";
改为
mt.InnerText = " ";
Deserialize后
mt1。InnerText=null
空格还是不能取道
如果非要用Serialization实现的话,只能自己实现IXmlSerializable接口了。