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.