Programming Generate XML under Special Schema

VS 2010 offer the method to generate XML sample file from Schema Define Diagram Tree.

But, how can we programming generate a XML?

XmlSerializer


I create a method name: GenerateXMLbySerialize(object myoject, string xml).

The flow ot this method is :

1. create a XMLSerializer

XMLSerializer serializer = new XmlSerilizer( System.Type of your data class);

2. create a XMLWriter to generate a XML file

XMLWriter writer = XMLWriter.create( XML file);

3. Serialize class to XML

serializer.Serializ(writer, instance of class);


Problem i match is on  System.Type of your data class

If we pass an object to this method, but it need System.type for initial a XMLSerializer.

And we can not use typeof(), for its parameter is a type, not a variable.

A object instance is a variable, not a Type.

So, how to do?

myobject.gettype()

resolve this problem.


until now, after the XMLis generated, we found that there is nothing in it.

Why?

Because i did not assign value to class's instance.

Just remember that if we want a XML contains data, we need to assign these value to the class instance before it is serialized.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值