62,046
社区成员
发帖
与我相关
我的任务
分享
public XmlDocument List()
{
XmlDocument doc = new XmlDocument();
StringBuilder sb = new StringBuilder();
IList<CityInfo> list = iCity.InfoList();
sb.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?> ");
sb.Append("<data>");
if (list != null && list.Count > 0)
{
foreach (CityInfo item in list)
{
sb.Append(string.Format("<area id={0} title={1} alpha={2} value={3}/>",item.ID,item.Title,item.Alpha,item.Value));
}
}
sb.Append("</data>");
doc.InnerXml = sb.ToString();
return doc;
}
SELECT * FROM 表 FOR XML RAW ('area'), ROOT('data')
namespace TacCs2013.AjaxRequest
{
/// <summary>
/// JbCs 的摘要说明
/// </summary>
public class JbCs : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
// context.Response.Write("Hello World");
//获取传过来的参数ID
int id= int.Parse(context.Request["id"].ToString());
//创建DataTable 名字为tab
DataTable tab = new DataTable();
//把从sql中读出的数据加入tab中
tab= DBtac.Rdt(id, false);
//创建一个xml(可读可写)xw
XmlTextWriter xw = new XmlTextWriter(HttpContext.Current.Response.OutputStream, null);
//设置输出的格式
xw.Formatting = Formatting.Indented;
//把tab中数据加入xw中
tab.WriteXml(xw);
//回收
GC.Collect();
xw.Flush();
xw.Close();
//返回xml
HttpContext.Current.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
namespace TacCs2013.AjaxRequest
{
/// <summary>
/// ajaxPagings 的摘要说明
/// </summary>
public class ajaxPagings : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//context.Response.Write("Hello World");
string where = "";//条件
int pages = 0;//显示多少跳数据
int thisPage = 0;//要显示的是多少页
int countPag = 0;//总共有多少数据
if (context.Request.QueryString["pages"] != null && context.Request.QueryString["pages"].ToString() != "" && context.Request.QueryString["thisPage"] != null && context.Request.QueryString["thisPage"].ToString() != "")
{
int.TryParse(context.Request.QueryString["pages"].ToString(), out pages);
int.TryParse(context.Request.QueryString["thisPage"].ToString(), out thisPage);
DataSet ds = new DataSet();
ds = DBtac.SelectTac(where, pages, thisPage, out countPag);
XmlTextWriter xm = new XmlTextWriter(HttpContext.Current.Response.OutputStream, null);
xm.Formatting = Formatting.Indented; //格式化输出
xm.WriteStartDocument(); //开始编写节点
xm.WriteStartElement("ShopInformation"); //编写节点
xm.WriteElementString("tAC", countPag.ToString()); //编写节点
ds.WriteXml(xm);
xm.WriteEndElement(); //结束节点编写
GC.Collect();
xm.Flush();
xm.Close();
HttpContext.Current.Response.End();
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}