开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜