Get the App
SLTechnology News&Howtos  ›  Development  › 

How to serialize asp.net classes to generate xml files

Shulou Source: shulou.com Published: 2022-06-03 10:58:23 10月01日 Update

This article introduces the relevant knowledge of "how to serialize asp.net classes to generate xml files". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

According to the requirements of the design, the original API XML files of multiple products are developed as follows:

Http://www.xxxxx.com/todaydetials.aspx?id=143 likes to buy 114 http://www.xxxxx.com/ Hangzhou 2011-2-9 2011-2-15 3880 2088

Now the demand is to have several URL nodes according to the API XML file corresponding to the commodity information in the database! By serializing the class into a XML file, and then reading the corresponding generated XML file, you can display the information of multiple commodity XML as follows:

First of all, define the data of each node of the XML and the relationship classes of the parent and child nodes:

# region defines data entity class xml data structure public class urlset {public List urlList {get; set;}} public class url {public string loc {get; set;} public List dataList {get; set;}} public class data {public List displayList {get; set;}} public class display {public string website {get; set;} public string siteurl {get; set;} public string city {get; set } public string webSitetitle {get; set;} public string image {get; set;} public string startTime {get; set;} public string endTime {get; set;} public double value {get; set;} public double price {get; set;} public double rebate {get; set;} public int bought {get; set;}} # endregion

Step 2: # region defines the entity class for obtaining website information

Public class WebSiteInfo {/ Product title / public string title {get; set;} / public DateTime createtime {get; set;} / Product Picture / public string productimg {get; set;} / Market Price / public decimal market_price {get; set } / public decimal team_price {get; set;} / public decimal zhekou_price {get; set;} / public string cityName {get; set;} / public DateTime begin_time {get; set } / end time / public DateTime end_time {get; set;} / merchant name / / public string merchants_id {get; set;} / public string description {get; set;} / minimum number of buyers / public int lowBuNo {get; set } / public string Address {get; set;} / public string Telphone {get; set;} / public string cCode {get; set;} / folder name / public string folderName {get; set } / Group purchase status / public string StatusMessage {get; set;} / current buyers / public int nownumber {get; set;} / item number / public int productID {get; set;}} # endregion

Step 3: get the database commodity information record and add it to the collection of objects (Arraylist):

# region get xml entity class information / get xml entity class information / public static ArrayList GetWebModelInfo () {ArrayList list = new ArrayList () String strSQL = "select a.id, a.accountantsIDrect a.cCoderea.prodCodereagea.Now number, a.titlerea.createtimecorea.productimgrea.marketcopyright pricerea.teamcodes pricemema.zhekouwritten pricecoveragea.cityNamestamenta.beginedtimestampa.endtimes timestampa.endgame timestampagea.lowBuyNorecoverb.AddressPower.Tel from tg_product as a left join tg_merchants as b on a.merchantsID=b.merchants_id where a.ispublic=1 and statue >-1 and getdate ().

Tags: Commodity file data time sequence information name merchant generation city database number of people group purchase picture character string entity object market market price Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Linux Apple OPPO Reno vpn