What is the best way to serialize a large collection of objects? I am attempting to serialize and validate against a schema a large collection of items about 70,000 items in c#.
XML file is not created. I have tried with a 1,000 items, it works fine with less items.
public void SerializeObject( Ojbect MyObj)
{
XmlSerializer serializer = new XmlSerializer(MyObj.GetType());
StreamWriter sw = new StreamWriter(“c:\file.xml”);
serializer.Serialize(streamWriter, myObj);
sw.Flush();
sw.Close();
}
public void Validate()
{
XmlSchema xmlSchema = “c:\myschema.xsd”
XmlReaderSettings xmlReaderSettings = new XmlReaderSettings();
xmlReaderSettings.ValidationType = ValidationType.Schema;
xmlReaderSettings.Schemas.Add(xmlSchema);
XmlReader xmlReader = XmlReader.Create(xmlStream, xmlReaderSettings);
while (xmlReader.Read())
{
//do some stuff
}
}