Class from XSD.exe ... now what

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
 
M

Marc Gravell

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top