Xml in Dot net 3.5:how to load xml document into object of class generated from schema?
I have defined schema for xml in file "packetTemplate.xsd".Using ms tool "xsd.exe" i have generated class "PacketTemplate" 开发者_开发百科corresponding to schema.Does dot net provides api that can load xml document by refering to file and returns object of class PacketTemplate.
You can find some examples here.
A snippet:
PacketTemplate myTemplate;
XmlSerializer mySerializer = new XmlSerializer(typeof(PacketTemplate));
FileStream myFileStream = new FileStream("c:/mtTestClass.xml",FileMode.Open);
myTemplate= (PacketTemplate)mySerializer.Deserialize(myFileStream);
Deserialize
has various overloads, you can also use an XmlReader
.
精彩评论