修改后的数据怎么保存到XML了真人手机网页版:

2019-11-26 作者:美高梅-运维   |   浏览(101)

table demo

   近来想做一个flash的美食指南与asp.net举办人机联作. 参谋了数不完英特网的资料,最终有以下心得,写出来记一下。

大器晚成、动态加载菜单
    菜单的始末如下(menu.xml):
<?xml version="1.0" encoding="utf-8"?>
<navigation>
 <menu id="2" menutext="编辑剧中人物" menuurl="EditRole.aspx">
 </menu>
<menu id="4" menutext="应用程序分配" menuurl="PrincipalInApp.aspx">
 </menu>
 <menu id="5" menutext="权限管理" menuurl="PrincipalInResource.aspx">
</menu>
</navigation>

只要动态加载呢?

  1)把以menu.xml文件放到网址的根目录之下,然后在flash的as中写如下的as脚本.
  
mymenu = new XML();
mymenu.load("menu.xml");
mymenu.ignoreWhite = true;
mymenu.onLoad = findThefild;
var passItOn = "";
menu_text = "";
var menu_array = new Array();
var submenu_array = new Array();
var menuurl_array = new Array();
var submenuurl_array = new Array();
var tempArray:Array = new Array();


这么就足以把菜单加载到flash中,至于什么展现,就和好开展管理了.


 二、  给菜单中增加动态参数.
     大家超级多日子利用的url都是如EditRole.aspx?rolename=role1之类,那时候理应怎么着把"?rolename=role1"动态的传给flash呢.
     作者试验了好些个主意,最终的结果如下. 
1)  说一下有了flash之后的asp.net页面包车型大巴生成顺序.举例小编的页面是editrole.aspx在这里页面中有八个flash菜单.
     editrole.aspx-->flash-->与flash通讯的页面.
2)  如何把动态参数字传送给flash呢,作者使用的是xml让asp.net与flash实行通讯.
3)  那么动态参数怎样获得呢?那将在借用第七个页面,也便是特地用来与flash举办相互的页面.而不能够接收所点击的菜单的页面.
4)  如上在第贰个张开的页面如EditRole.aspx?rolename=role第11中学把"?rolename=role1"保存到cookie或缓存或seession中,
      然后则特意与flash实行通讯的页面把"?rolename=role1"编写成xml,然后reponse.wirte(参数xml字符串),传给flash.

    代码:

      1.editrole.aspx页面中的代码.
       protected void Page_Load(object sender, EventArgs e)
        {
            this.txtUserName.Text = this.UserName;
            //this.Description.Text = ReponseXML();
            if (!IsPostBack)
            {
                ShowUserInfo();
               this.WirteCookie();
            }

           
        }
       
         public void WirteCookie()
        {
       
            //加密程序提供程序的称号
            string symmProvider = "DESCryptoServiceProvider";
            //须要加密的xml字符串
            string stringToEncrypt = this.ReponseXML();
            //加密后的字符串
            string encryptedContentsBase64 = Cryptographer.EncryptSymmetric(symmProvider, stringToEncrypt);

      //写cookies
            Response.Cookies["UserSettings"]["uid"] = encryptedContentsBase64;

            Response.Cookies["UserSettings"]["ur"] =this.UserRole;
                Response.Cookies["UserSettings"].Expires = DateTime.Now.AddHours(1);

  
           
        }

           protected string ReponseXML()
        {
        string param="";
             int index=Request.Url.ToString().IndexOf("?");
          if (index>0)
          {
               param=Request.Url.ToString().Substring(index);
         
          }
        
          return  "<LOGIN><USRENAME name="user" right="1" urlParam="" + param + "">"+param+"</USERNAME></LOGIN>";
           
        }
//与flash进行交互作用的页面.
    [WebService(Namespace = "]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class XmlRepley : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
         //   context.Response.Write("Hello World");

            string symmProvider = "DESCryptoServiceProvider";
            string stringToEncrypt = this.GetUID(context);
            string decryptedContentsBase64 = Cryptographer.DecryptSymmetric(symmProvider, stringToEncrypt);


           context.Response.Write(decryptedContentsBase64);
        }

        public string GetUID(HttpContext context)
        {
            string uid = String.Empty;
            if (context.Request.Cookies["UserSettings"] != null)
            {

                if (context.Request.Cookies["UserSettings"]["uid"] != null)
                { uid =context.Request.Cookies["UserSettings"]["uid"]; }

            }
            return uid;

        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

  
  
  
   //flash中as代码
  
  
//-----------------------------------------------------------
//鼠标点击菜单时
//-----------------------------------------------------------
function itemEvent(mc:MovieClip,url:String)
{
 
 mc.btn.onRelease = function()
 {

loginXml = new XML(); // 注释1
loginElement = loginXml.createElement("LOGIN"); // 注释2
// name node
nameElement = loginXml.createElement("USERNAME"); // 注释3
nameNode = loginXml.createTextNode("name"); // 注释4
nameNode.nodeValue = _root.username; // 注释5
nameElement.appendChild(nameNode); // 注释6
// pwd node
pwdElement = loginXml.createElement("PWD"); // 注释7
pwdNode = loginXml.createTextNode("pwd");
pwdNode.nodeValue = _root.pwd;
pwdElement.appendChild(pwdNode);
loginElement.appendChild(nameElement); // 注释8
loginElement.appendChild(pwdElement); // 注释9


loginXml.appendChild(loginElement); // 注释10

xmlRepley = new XML(); // 注释11


xmlRepley.onLoad = onLoginReply; // 注释12
function onLoginReply (success) {
if (success) { // 注释13

if (xmlRepley.firstChild.firstChild.attributes.right == "1") { // 注释14
getURL(url+xmlRepley.firstChild.firstChild.attributes.urlParam, "_self");

}
else
{
 getURL(url+"?q=错误", "_self");
}
}
}
loginXml.sendAndLoad("XmlRepley.ashx", xmlRepley); // 注释15

 }
}

 

 三、加载动态菜单项   

  以上的美食指南都以flash去读xml菜单文件,那么大器晚成旦大家有多少个不等品类的菜系,则要做八个不等的flash,
  而那多少个不财的flash中,借使菜单样式同样,只不过是菜单的剧情区别等,那么实际上是去读不相同的xml菜单文件.
  那么有未有艺术去达成成程序去给定一个flash菜单的xml数据源呢?
 
   小编试验了成都百货上千艺术,最后的结果如下.
   1)说一下有了flash之后的asp.net页面包车型客车生成顺序.举例笔者的页面是editrole.aspx在那页面中有三个flash菜单.
   editrole.aspx-->flash-->与flash通讯的页面.
   2)如何把xml菜单传给flash呢,作者动用的是xml让asp.net与flash实行通讯.
   

      代码
  1)在flash的as中写如下的as脚本,获得xml文件菜单.
     
mymenu = new XML();
mymenu.load("SendXmlMenu.ashx");
mymenu.ignoreWhite = true;
mymenu.onLoad = findThefild;
var passItOn = "";
menu_text = "";
var menu_array = new Array();
var submenu_array = new Array();
var menuurl_array = new Array();
var submenuurl_array = new Array();
var tempArray:Array = new Array();


2)在主演色页面如showRoleMenu.aspx页面中写如下代码
 protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cookies["UserSettings"]["ur"] = "r"; //新页面要开荒的菜单.
            Response.Cookies["UserSettings"].Expires = DateTime.Now.AddHours(1);  

        }
       
        在主用户页面如showUserMenu.aspx页面中写如下代码
       
 protected void Page_Load(object sender, EventArgs e)
        {
            Response.Cookies["UserSettings"]["ur"] = "u"; //新页面要开荒的菜单.
            Response.Cookies["UserSettings"].Expires = DateTime.Now.AddHours(1);  

        }
       
              
   3)在SendXmlMenu.ashx中写以下代码举办xml菜单的传给flash.   

   [WebService(Namespace = "]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class SendXmlMenu : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";
            context.Response.Write(ReadXmlMenu(context));
           
        }
        public string ReadXmlMenu(HttpContext context)
        {
            string ur = this.GetUserRole(context);
            System.Xml.XmlDocument xmldoc = new System.Xml.XmlDocument();
            string path=context.Request.PhysicalPath.Substring(0,context.Request.PhysicalPath.LastIndexOf("\"));
            path = path + "\menu\";
            switch(ur.ToLower())
            {
                case "u"://这一个参数通过cookie获得.
                    xmldoc.Load(path + "usermenu.xml");
                    return xmldoc.OuterXml;
                case "r":
                    xmldoc.Load(path + "rolemenu.xml");
                    return xmldoc.OuterXml;
                default:
                    return String.Empty;

            }

        }

        public string GetUserRole(HttpContext context)
        {
            string ur = String.Empty;
            if (context.Request.Cookies["UserSettings"] != null)
            {

                if (context.Request.Cookies["UserSettings"]["ur"] != null)
                { ur = context.Request.Cookies["UserSettings"]["ur"]; }

            }
            return ur;

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

假定有怎么样不足的地点请指正。

3.效果图:
真人手机网页版 1
4。 别的的.js以致.css文件见附属类小零部件

本文以

ajax落成拿到数据集的ashx代码 复制代码 代码如下: using System; using System.Web; using System.Data; using System.Data.SqlClient; using System.Text; using DHCC.HISH奥迪Q5.BO; public class getDataSet : IHttpHandler { public void ProcessRequest { context.Response.ContentType = "text/plain"; string result = ""; string table = context.Request.Params["table"].ToString; string value = context.Request.Params["value"].ToString; string text = context.Request.Params["text"].ToString; string sql = "SELECT " + value + "," + text + " FROM HISHR." + table + " "; BOSQLExecuter SQLexec = new BOSQLExecuter(); DataSet ds = SQLexec.GetDataSetSQLExecuter if { DataTable dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { result += "$" + dr[value].ToString() + "^" + dr[text].ToString(); } if result = result.Substring; } //依照HTTP局部须要再次回到流到页面 context.Response.Write; } public bool IsReusable { get { return false; } } } ajax保存XML的ashx代码 复制代码 代码如下: using System; using System.Web; using System.Xml; using System.IO; public class saveXML : IHttpHandler { public string xml; public void ProcessRequest { context.Response.ContentType = "text/plain"; string path = System.Web.HttpContext.Current.Request.PhysicalApplicationPath; string strXML =context.Request.Form[0]; try { if (File.Exists) { XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml; xmldoc.Save; context.Response.Write; } } catch { context.Response.Write; } } public bool IsReusable { get { return false; } } } 主页面

<html xmlns=";
<head runat="server">
<title></title>
<link rel="stylesheet" href="jscript/autoSuggest.css" type="text/css"/>
<link rel="stylesheet" href="jscript/ac.css" type="text/css"/>
<script language="Javascript" src="jscript/autoSuggest.js"></script>
<script language="Javascript" src="jscript/ac.js"></script>
function ACClient( queryurl, width, objInput, objLable )
{
this.xmldom = getXmlhttp();
this.queryurl = queryurl;
this.prolist = new Array();
this.divwidth = width;
this.objInput = objInput;
this.getEligible = function(ac) {
var eligible = new Array();
if (ac.inputText.length < 1) {
document.getElementById(objInput.name).value = "";
document.getElementById(objLable.name).value = "";
return eligible;
}
var strURL = this.queryurl + escape(ac.inputText) + "&rand=" + Math.random();
this.xmldom.open("GET", strURL, false);
try {
this.xmldom.send();
}
catch (e) {
return;
}
this.prolist = this.xmldom.responseXML.documentElement.selectNodes("/duxion/object");
if (0 == this.prolist.length) {
return eligible;
}
for (var i = 0; i < this.prolist.length; i++) {
if (i > 15)
break;
var node = this.prolist.item(i);
eligible[eligible.length] = node.getAttribute("fullcontent");
}
ac.div.style.width = this.divwidth;
return eligible;
};
this.useSuggestion = function( sel )
{
if( sel>=0 )
{
var node = this.prolist.item(sel);
if(typeof(node.getAttribute( "value" )) != "undefined")
document.getElementById(objInput.name).value = node.getAttribute( "value" );
else
document.getElementById(objInput.name).value = "";
if(typeof(node.getAttribute( "content" )) != "undefined")
document.getElementById(objLable.name).value = node.getAttribute( "content" );
else
document.getElementById(objLable.name).value = "";
if (this.objInput.name == "hidfreq_code") {
document.getElementById("txtfreq_name").value = node.getAttribute("Name");
document.getElementById("hidfreq_code").value = node.getAttribute("Code");
}
}
};
return this;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<%--div 用于展示下拉查询部分--%>
<div id="autosuggest" style="width:160px;font-size:12px;"><ul></ul></div>
<div>
<asp:TextBox ID="txtfreq_name" CssClass="needtext" runat="server" Width="100px"></asp:TextBox><asp:HiddenField
ID="hidfreq_code" runat="server" />
</div>
</form>
</body>
</html>
<script type="text/javascript">
new AutoSuggest(document.getElementById('txtfreq_name'),
new ACClient("testXml.aspx?tag=yp_frequency&value=", "200px", document.getElementById('hidfreq_code'), document.getElementById('txtfreq_name')));
</script>

真人手机网页版 2真人手机网页版 3Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

table demo

复制代码 代码如下:

        var nameQuery = from name in names
                        where name.ToString().StartsWith(strPara)
                        select name;

编辑页的xsl 复制代码 代码如下:

1。 testlist.aspx页面:

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.names.Attributes.Add("onKeyup", "findNames();");
    }
}

率先思考用什么艺术做,构思到三个主意:1、C#拼HTML构造table,改革和封存通过Ajax达成。2、XML+XSL,表现和改革用四个XSL文件来做,Ajax校勘、保存XML。3、GridView控件。 经过精心考虑,首先第三方案GridView控件满足不断要求,因为XML格式多种,只怕涉嫌到比超多的行、列归拢和行、列表头合併。第一方案太费劲,坐起来是细致活和体力活,须求变动后不佳改革。所以采用第二方案。起头读书XPath、XSLT。AJAX用js异步调用平时管理文件的主意。 1、达成选取框的绑依期现身谬误,最后发掘是在读取XML时选用了异步格局与Ajax有冲突,用后生可畏道就足以减轻了。 2、保存XML。更正后的多寡怎么保存到XML了?通过Javascript保存,js不可能保存,借使用js保存必需用hta;用AJax保存,怎能让更正后的XML传到AJAX方法里去,瞎研讨,试了两种艺术,还真让作者试出来了,源码 js: 复制代码 代码如下: var $=function {return document.getElementById;} var xmlHttp; var curControl; var curValue; function ToEdit(){ var xml = new ActiveXObject; xml.async = false; xml.load; var xsl = new ActiveXObject; xsl.async = false; xsl.load; document.write(xml.transformNode; document.close(); //绑定选用框 LoadSelect(); } //保存xml function Save(){ var oDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");//担任获得响应结果 oDoc.async = false; oDoc.resolveExternals = false; oDoc.load; var data = oDoc.selectNodes("//Data[@IsEdit='1']");//读取全体乞求大类所属小类的类名 for(var i=0; i < data.length; i++) { var nodeEdit; var nodeID; var nodeType; for(var j=0; j0) data[i].text = combox.options[combox.selectedIndex].value; } } else { data[i].text = $.value; } } var strXML = oDoc.xml; var url="saveXML.ashx"; StartRequest(url,null,After艾德it,strXML,"POST"); } function AfterEdit() { //能够毫不上面五个if语句,未有用异步格局 if(xmlHttp.readyState==4) { if { var rtn = xmlHttp.responseText; if { alert; } else { alert; } } } function Show() { // Load XML var xml = new ActiveXObject; xml.async = false; xml.load; // Load XSL var xsl = new ActiveXObject; xsl.async = false; xsl.load; document.write(xml.transformNode; document.close(); } ///////////////////绑定下接收框//////////////////////// function LoadSelect() { var allcontrols = document.all; for(var j=0;j

testlist.aspx页面: 复制代码 代码如下: html xmlns="" head runat="server" title/title link rel="stylesheet" href="jscript/autoSuggest.css...

        //总括呈现地方
        function calculateOffset(field, attr) {
            var offset = 0;
            while (field) {
                offset += field[attr];
                field = field.offsetParent;
            }
            return offset;
        }

css 复制代码 代码如下: table.admintable { border:1px solid #AEDEF2; border-collapse: collapse; } td.other{ color: #0066cc; font-size:13px; color:#05B; font-family: 新宋体; border:1px solid #AEDEF2; } td.title { width: 671px; color: #0066cc; background-color: #eef6fe; font-size:15px; color:#05B; border:1px solid #AEDEF2; filter: progid:DXImageTransform.Microsoft.gradient(startColorStr=#AEDEF2,endColorStr=ghostwhite); } td.header { width: 671px; color: #0066cc; background-color: #eef6fe; font-size:14px; color:#05B; border:1px solid #AEDEF2; } td.content { border:1px solid #AEDEF2; background:ghostwhite; font-size:13px; font-family: 新宋体; color: #333; } 突显数据页图

  • arrfield[k] + "</span>";
    if (k == arrfield.Length - 1)
    break;
    }
    objtitle.SetAttribute("fullcontent", listlable);
    root.AppendChild(objtitle);
    }
    //彰显表头
    //展现数据
    for (int i = 0; i < list_rows; i++)
    {
    listlable = "";
    DataRow drList = dtList.Rows[i];
    XmlElement obj = xmldoc.CreateElement("object");
    for (int j = 0; j < list_cols; j++)
    {
    obj.SetAttribute(dtList.Columns[j].ColumnName, drList[j].ToString());
    if (j <= arrfield.Length - 1)
    {
    //listlable += "<span style='width:" + arrwidth[j] + "'>" + GetLeftString(drList[j].ToString(), Convert.ToInt16(arrwidth[j])) + "</span>";
    listlable += "<span style='width:" + arrwidth[j] + "'>" + formatXmlNode(dtList.Columns[j].DataType.ToString(), drList[j].ToString()) + "</span>";
    }
    }
    obj.SetAttribute("fullcontent", listlable);
    root.AppendChild(obj);
    }
    //突显数据
    //Response.ContentType = "text/xml;charset=utf-8";
    //Response.ContentType = "text/xml;charset=gb2312";
    Response.ContentEncoding = System.Text.Encoding.Default;
    Response.ContentType = "text/xml";
    Response.Clear();
    Response.Write(xmldoc.OuterXml);
    Response.End();
    }
    private string formatXmlNode(string field_type, string field_value)
    {
    string return_value = field_value.Trim();
    switch (field_type)
    {
    case "System.Double":
    case "System.Decimal":
    return_value = string.Format("{0:0.###}", Convert.ToDouble(return_value));
    break;
    }
    return return_value;
    }
    }

}

编写数据页图

public partial class testXml : BaseForm
{
protected void Page_Load(object sender, EventArgs e)
{
ListXmlData();
}
private string[] arrwidth;
private string[] arrfield;
public string 田野先生list = "区域Id,区域名,区域编码,区域档次";
public string coloumwidth = "60,10,20,30";
//展现xml格式数据
private void ListXmlData()
{
//各字段的大幅
string strwhere="";
if (Request["value"] != null)
{
strwhere = string.Format(" and Code like '{0}%'", Request["value"].ToString());
}
arrfield = fieldlist.Split(',');
arrwidth = coloumwidth.Split(',');
DataTable dtList = new Districts().Search("1=1" + strwhere);// dis // SqlHelper.GetTable(subsys_db, CommandType.Text, strsql, null);
int list_cols = dtList.Columns.Count; //字段数
int list_rows = dtList.Rows.Count; //记录数
string listlable = ""; //展现内容
XmlDocument xmldoc = new XmlDocument();
XmlDeclaration dec = xmldoc.CreateXmlDeclaration("1.0", "gb2312", null);
xmldoc.InsertBefore(dec, xmldoc.FirstChild);
XmlElement root = xmldoc.CreateElement("duxion");
xmldoc.AppendChild(root);
//呈现表头
if (list_rows > 0)
{
XmlElement objtitle = xmldoc.CreateElement("object");
for (int k = 0; k < list_cols; k++)
{
listlable += "<span style='width:" + arrwidth[k] + ";text-align:center;font-weight:bold;color:#000000;padding-top:2px;'>"

        //淹没自动完结行
        function clearNames() {
            var ind = completeBody.childNodes.length;
            for (var i = ind - 1; i >= 0; i--) {
                completeBody.removeChild(completeBody.childNodes[i]);
            }
            completeDiv.style.border = "none";
        }

统计 类别 系数 分析 比例1 比例2 比例3 比例4 比例5 比例6 比例7 红 1 01 5.0 2009-10-05 21111 21 21 21 2 2 3 4 4 2 2 2 3 1 2 4 4 2 1 1 小计: 绿 4 4 4 4 4 2 4 4 5 4 4 4 4 2 4 4 6 3 4 4 4 2 3 3 7 4 4 4 4 4 4 4 8 4 4 4 4 3 4 4 9 4 4 4 4 1 5.0 2009-10-14 小计: 蓝 10 4 4 4 4 1 5.0 2009-10-14 11 4 4 4 4 1 5.0 2009-10-14 12 4 4 4 4 1 5.0 2009-10-14 小计:

2。 供查询的xml的testxml.aspx.cs文件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ";

本文由美高梅赌堵59599发布于美高梅-运维,转载请注明出处:修改后的数据怎么保存到XML了真人手机网页版:

关键词: