[ASP.NET]XML轉成Class

摘要:[ASP.NET]XML轉成Class--待整理

   記錄用

 StringReader ssr;
 XmlReader XR;
 XmlDocument xmlDoc = new XmlDocument();
ssr = new StringReader(Result); 
//讀取xml的字串
xmlDoc.Load(ssr);
//取得要取得資料的區塊
string teststr = ( xmlDoc.ChildNodes[1].InnerXml.ToString());
//再將資料倒進XmlReader
XR = XmlReader.Create(new StringReader(teststr));
//宣告要轉的class
QueryResult newclass;
//要先轉成對應的xmltype
  XmlTypeMapping myTypeMapping = (new SoapReflectionImporter().ImportTypeMapping(typeof(QueryResult)));

XmlSerializer mySerializer = new XmlSerializer(myTypeMapping);
//執行反序列化 
newclass = (QueryResult)mySerializer.Deserialize(XR);