Class from XSD.exe ... now what

  • Thread starter Thread starter Lee Franke
  • Start date Start date
L

Lee Franke

I have an XSD and I generated a class with xsd.exe.

I added it to my project. I can instantiate all of the appropriate classes
and set values.

How do I get it to write out the resulting XML?
Also how do I make sure all of the sub classes within the XSD class are
properly attached to the parent class and are generated as well?

thanks,

lee
 
How do I get it to write out the resulting XML?
XmlSerializer ser = new XmlSerializer(typeof(YourClassType));
ser.Serialize(output, yourObject);

where "output" could be a Stream, TextWriter, XmlWriter, etc; for
simple cases, perhaps via StringBuilder:
StringBuilder sb = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(sb)) {
XmlSerializer ser = new XmlSerializer(typeof(YourType));
ser.Serialize(writer, yourObject);
writer.Close();
}
string xml = sb.ToString();
Also how do I make sure all of the sub classes within the XSD class are
properly attached to the parent class and are generated as well?
Can you perhaps illustrate what you mean with a simple xsd example?

Marc
 
Back
Top