如何避免输出的XML文件无法在前台js脚本中使用。
2006-11-14 11:52 迷路中的路人甲 阅读(278) 评论(0) 编辑 收藏 举报 1 DataSet ds;
2 if(BizFacade.DataAccess.GetChildInfoByParentID(Convert.ToInt64(userid),out ds))
3 {
4 tree="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
5 tree+="<xtree>";
6 tree+="<nodetype>" + newtreeid + "</nodetype>\n";
7 tree+="<oldid>" + oldtreeid + "</oldid>\n";
8 tree+="<success>true</success>\n";
9 tree+="<tree>\n";
10 if(ds.Tables[0].Rows.Count>0)
11 {
12 for(int i=0;i<ds.Tables[0].Rows.Count;i++)
13 {
14 tree += "<leaf>\n";
15 tree += "<id>"+ds.Tables[0].Rows[i]["userid"].ToString() + "</id>";
16 tree += "<level>"+levelID.ToString()+"</level>\n";
17 tree += "<name>"+HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["username"].ToString())+"</name>\n";
18 tree += "<depart>"+HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["depart"].ToString())+"</depart>\n";
19 tree += "<duty>"+HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["duty"].ToString())+"</duty>\n";
20 tree += "<isforder>"+ds.Tables[0].Rows[i]["isforder"].ToString()+"</isforder>\n";
21 tree += "</leaf>\n";
22 }
23 }
24 tree+="</tree>\n</xtree>\n";
25 }
26 Response.Clear();
27 Response.ContentType = "text/xml"; //最重要的一句
28 Response.Write(tree);
2 if(BizFacade.DataAccess.GetChildInfoByParentID(Convert.ToInt64(userid),out ds))
3 {
4 tree="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
5 tree+="<xtree>";
6 tree+="<nodetype>" + newtreeid + "</nodetype>\n";
7 tree+="<oldid>" + oldtreeid + "</oldid>\n";
8 tree+="<success>true</success>\n";
9 tree+="<tree>\n";
10 if(ds.Tables[0].Rows.Count>0)
11 {
12 for(int i=0;i<ds.Tables[0].Rows.Count;i++)
13 {
14 tree += "<leaf>\n";
15 tree += "<id>"+ds.Tables[0].Rows[i]["userid"].ToString() + "</id>";
16 tree += "<level>"+levelID.ToString()+"</level>\n";
17 tree += "<name>"+HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["username"].ToString())+"</name>\n";
18 tree += "<depart>"+HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["depart"].ToString())+"</depart>\n";
19 tree += "<duty>"+HttpUtility.UrlEncodeUnicode(ds.Tables[0].Rows[i]["duty"].ToString())+"</duty>\n";
20 tree += "<isforder>"+ds.Tables[0].Rows[i]["isforder"].ToString()+"</isforder>\n";
21 tree += "</leaf>\n";
22 }
23 }
24 tree+="</tree>\n</xtree>\n";
25 }
26 Response.Clear();
27 Response.ContentType = "text/xml"; //最重要的一句
28 Response.Write(tree);
增加输入类型,这样在前台利用responseXML的时候,就能够获取到该XML对象,并且能够进行继续操作了。