开发者

Xml in Dot net 3.5:how to load xml document into object of class generated from schema?

开发者 https://www.devze.com 2022-12-12 09:08 出处:网络
I have defined schema for xml in file \"packetTemplate.xsd\".Using ms tool \"xsd.exe\" i havegeneratedclass \"PacketTemplate\" 开发者_开发百科corresponding to schema.Does dot net provides api that can

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

精彩评论

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