usingSystem;usingSystem.Collections.Generic;usingsystem.web;usingSystem.Web.Services;usingSystem.Web.Script.Serialization;usingSystem.Xml;usingSystem.Collections;usingSystem.Linq;/// <summary>///Summary description of Wsxml/// </summary>[WebService (Namespace ="http://tempuri.org/")][webservicebinding (ConformsTo=wsiprofiles.basicprofile1_1)]//to allow the Web service to be called from the script using ASP. NET AJAX, uncomment the downstream. [System.Web.Script.Services.ScriptService] Public classWSxml:System.Web.Services.WebService { PublicWsxml () {//If you are using a design component, uncomment the following line//InitializeComponent ();} [WebMethod] Public stringHelloWorld () {return "Hello World"; } [WebMethod] Public stringSaveXML (stringCName,stringAgestringMobilestringEmailstringads) {DateTime dt=DateTime.Now; stringCDate =dt. ToString (); XmlDocument xmldoc=NewXmlDocument (); stringXmlfilepath = HttpContext.Current.Server.MapPath ("~/data/content.xml"); XmlDoc. Load (Xmlfilepath); //Find root nodeXmlNode chat = xmldoc. selectSingleNode ("Chat"); //Use an XPath expression to select all the TP child nodes in the documentXmlNodeList typenodelist = xmldoc. SelectNodes ("/CHAT/TP"); stringstr =string. Empty; //defines a list generic collectionlist<string> mlist =Newlist<string>(); if(Typenodelist! =NULL) { stringMBL =string. Empty; foreach(XmlNode Tpnodeinchtypenodelist) { //Attribute named Mobile is obtained by attributesMBL = tpnode.attributes["Mobile"]. Value; //loops Add Mobile to the list generic collectionmlist. ADD (MBL); } } //Find out if a list exists if(mlist. Contains (MOBILE)) {return "your mobile phone number has been registered, do not re-register"; } //Create a nodeXmlElement infor = xmldoc. CreateElement ("TP"); Infor. SetAttribute ("CName", CName); Infor. SetAttribute (" Age", age); Infor. SetAttribute ("Mobile", mobile); Infor. SetAttribute ("Email", email); Infor. SetAttribute ("Ads", ADS); Infor. SetAttribute ("CDate", CDate); //Save the file by storing the root nodeChat. AppendChild (infor); XmlDoc. Save (Xmlfilepath); return "congratulations on your successful registration!"; } [WebMethod] Public stringreadxmltable () {XmlDocument xmldoc=NewXmlDocument (); stringXmlfilepath = HttpContext.Current.Server.MapPath ("~/data/content.xml"); XmlDoc. Load (Xmlfilepath); //Use an XPath expression to select all the TP child nodes in the documentXmlNodeList typenodelist = xmldoc. SelectNodes ("/CHAT/TP"); stringstr =string. Empty; //defining a sorteddictionary generic collectionsorteddictionary<string,string> SD =Newsorteddictionary<string,string>(); if(Typenodelist! =NULL) { stringCName =string. Empty, age =string. Empty, mobile =string. Empty, email =string. Empty, Ads =string. Empty, CDate =string. Empty; foreach(XmlNode Tpnodeinchtypenodelist) { //Get property named CNAME by attributesCName = tpnode.attributes["CName"]. Value; Age= tpnode.attributes[" Age"]. Value; Mobile= tpnode.attributes["Mobile"]. Value; Email= tpnode.attributes["Email"]. Value; Ads= tpnode.attributes["Ads"]. Value; CDate= tpnode.attributes["CDate"]. Value; Sd. ADD (CDate, CName+","+ Age +","+ Mobile +","+ Email +","+ads); } //foreach (keyvaluepair<string, string> item in SD) is a positive-order ASC//use generic Collections and LINQ to sort the time types in reverse desc foreach(keyvaluepair<string,string> IteminchSD. Reverse ()) {str+ = Item. Value +","+ Convert.todatetime (item. Key). ToString ("yyyy mm month DD Day HH") +"|"; } } returnStr. Substring (0Str. Length-1); }}
. NET generic collection sorting, finding