. NET generic collection sorting, finding

Source: Internet
Author: User
Tags httpcontext xpath

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.