Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to serialize asp.net classes to generate xml files

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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 ().

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report