Asp.net implements the xml output method,

Source: Internet
Author: User
Tags net xml

Asp.net implements the xml output method,

This example describes how to implement the output xml in asp.net. We will share this with you for your reference. The details are as follows:

# Region Query and modify the value of an xml Node Based on the xml node // <summary> // query and modify the value of an xml Node Based on the xml node // </summary> /// <param name = "fileName"> name of the xml file to be loaded </param> /// <param name = "tagName"> name of the xml node </param>/ // <param name = "newXmlText"> modified value </param> // <returns> </returns> public void GetXmlbySelNodel (string fileName, string selNodeName, string tagName, string newXmlText) {try {doc. load (Server. mapPath (fileName); XmlNodeList nodelist = doc. DocumentElement. selectSingleNode (selNodeName ). childNodes; foreach (XmlNode node in nodelist) {XmlElement xle = node as XmlElement; XmlNodeList list = xle. childNodes; for (int j = 0; j <list. count; j ++) {if (xle. childNodes [j]. name = tagName) {xle. childNodes [j]. innerText = newXmlText; SaveXml (fileName); break ;}}}} catch {}# endregion # region Save the modified xml file content // Save the modified xml file content public void SaveXml (st Ring fileName) {doc. save (Server. mapPath (fileName) ;}# endregionstring selNodeName = "// url/data"; string fileName = "meituanAPI. xml "; parameters (fileName, selNodeName," website "," "); GetXmlbySelNodel (fileName, selNodeName," siteurl "," Parameters "); GetXmlbySelNodel (fileName, selNodeName, "city", "Hangzhou"); GetXmlbySelNodel (fileName, selNodeName, "tip", "ipad Lucky Draw !! "); GetXmlbySelNodel (fileName," // data/shops "," name "," Shanghai zhouxin Information Technology Co., Ltd! "); DataSet ds = new DataSet (); ds. readXml (Server. mapPath ("meituanAPI. xml "); XmlTextWriter writer = new XmlTextWriter (Response. outputStream, Response. contentEncoding); ds. tables [0]. writeXml (writer); Response. contentType = "text/xml; charset = gb2312"; Response. flush (); Response. end ()

Or

Response.ClearContent();Response.ClearHeaders();Response.contentType="application/xml"';Response.WriterFile(Server.Mappath("API/54tuanAPI.xml"));Response.Flush();Response.End();

I hope this article will help you design your asp.net program.

Articles you may be interested in:
  • Detailed description of xml file instance generated by asp.net class serialization
  • How to add, delete, modify, and query XML in asp.net
  • ASP. NET XmlDocument
  • Example of XML-to-JSON method conversion in ASP. NET
  • Example of adding, deleting, and modifying xml operations in asp.net
  • Asp.net TreeView and XML generate a list tree in three steps
  • Analysis on how ASP. NET + XML creates a network Hard Disk
  • Analysis of Four Methods for ASP. NET to read XML files
  • Implementation of XML encryption and decryption in asp.net
  • Asp.net uses XML to generate a scalable custom tree
  • Asp.net XML file operation implementation code

Related Article

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.