asp.net implementation of XML output method _ Practical Skills

Source: Internet
Author: User

The example in this article describes how asp.net implements the output XML. Share to everyone for your reference, specific as follows:

#region Query XML node values based on XML nodes and make modifications///<summary>///Query XML node values based on XML nodes and make modifications///</summary>///<param name= "file Name > XML file to load </param>///<param name= "TagName" >xml node names </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
  #endregion #region Save the modified XML file contents after saving modified XML file contents public void SaveXML (string fileName) { Doc. Save (Server.MapPath (fileName));
} #endregion string Selnodename= "//url/data";
String fileName = "Meituanapi.xml";
Getxmlbyselnodel (FileName, Selnodename, "website", "cloud-dwelling community");
Getxmlbyselnodel (FileName, Selnodename, "SiteURL", "www.jb51.net");
Getxmlbyselnodel (FileName, Selnodename, "City", "Hangzhou");
Getxmlbyselnodel (FileName, Selnodename, "Tip", "Send the ipad lottery!!");
Getxmlbyselnodel (FileName, "//data/shops", "name", "Shanghai Chau Xin 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 to ASP.net program design.

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.