欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

asp.net實(shí)現(xiàn)輸出xml的方法

 更新時(shí)間:2015年11月28日 15:52:07   作者:happy664618843  
這篇文章主要介紹了asp.net實(shí)現(xiàn)輸出xml的方法,涉及asp.net針對(duì)xml節(jié)點(diǎn)的查詢、創(chuàng)建、修改、生成等操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了asp.net實(shí)現(xiàn)輸出xml的方法。分享給大家供大家參考,具體如下:

#region 根據(jù)xml節(jié)點(diǎn) 查詢xml節(jié)點(diǎn)的值并作修改
/// <summary>
/// 根據(jù)xml節(jié)點(diǎn) 查詢xml節(jié)點(diǎn)的值并作修改
/// </summary>
/// <param name="fileName">要加載的xml文件</param>
/// <param name="tagName">xml節(jié)點(diǎn)的名稱</param>
/// <param name="newXmlText">修改后的值</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 保存修改后xml文件內(nèi)容
//保存修改后xml文件內(nèi)容
public void SaveXml(string fileName)
{
  doc.Save(Server.MapPath(fileName));
}
#endregion
string selNodeName="http://url/data";
string fileName = "meituanAPI.xml";
GetXmlbySelNodel(fileName, selNodeName, "website", "腳本之家");
GetXmlbySelNodel(fileName, selNodeName, "siteurl", "www.dbjr.com.cn");
GetXmlbySelNodel(fileName, selNodeName, "city", "杭州");
GetXmlbySelNodel(fileName, selNodeName, "tip", "送ipad 抽獎(jiǎng)!!");
GetXmlbySelNodel(fileName, "http://data/shops", "name", "上海洲信 信息技術(shù)有限公司!");
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()

或者

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

希望本文所述對(duì)大家asp.net程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論