XML+XSLT+C+JQuery+Weervice组建A.Net网站.(3)_XHTML/WEB_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

XML+XSLT+C+JQuery+Weervice组建A.Net网站.(3)

作者:黑客防线网安XML教程基地 来源:黑客防线网安XML教程基地 浏览次数:0

本篇关键词:网站组建 />
黑客防线网安网讯:    输入以下代码:<%@ WebHandler Language="C#" Class="Default" %> using System;using System.Web;using System.Data.OleDb;using System.Data;using System.Xml; public class Default...

    输入以下代码:

<%@ WebHandler Language="C#" Class="Default" %>

 

using System;

using System.Web;

using System.Data.OleDb;

using System.Data;

using System.Xml;

 

public class Default : IHttpHandler

{

 

    public void ProcessRequest(HttpContext context)

    {

        OleDbConnection c = new OleDbConnection(string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=""{0}"";Persist Security Info=True", HttpContext.Current.Server.MapPath(@"~\App_Data\Database.mdb")));

        var ds = new DataSet();

        c.Open();

        //获取Url中的max参数

        var max = 0;

        Int32.TryParse(HttpContext.Current.Request.QueryString["max"],out max);

        //读取数据

        new OleDbDataAdapter(string.Format("select{0} * from [User]", max > 0 ? " top " + max : string.Empty), c).Fill(ds);

        c.Close();

        //建立XML文档

        var xml = new XmlDocument();

        xml.LoadXml(ds.GetXml());

        //添加文档声明

        xml.InsertBefore(xml.CreateXmlDeclaration("1.0", "UTF-8", null), xml.DocumentElement);

        //添加xslt声明

        var xsl = xml.CreateProcessingInstruction("xml-stylesheet", @"type=""text/xsl""   href=""Default.xslt""");

        xml.InsertBefore(xsl, xml.DocumentElement);

        //输出

        context.Response.ContentType = "application/xml";

        context.Response.Write(xml.InnerXml);

    }

 

    public bool IsReusable

    {

        get

        {

            return false;

        }

    }

 

}

再添加一个XSLT文件命名为Default.xslt输入以下代码:

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"

>

         <xsl:template match="/">

                   <html>

                            <hread>

                                     <title>XML网站测试</title>

                                     <link href="Style.css" rel="stylesheet" type="text/css"/>

                                     <script src="jquery-1.3.2.js" type="text/javascript"/>

                                     <script src="Post.js" type="text/javascript"/>

                            </hread>

                            <body>

                                     <h1>XML网站测试</h1>

                                     <ul>

                                               <xsl:for-each select="//Table">

                                                        <li>

                                                                 <a href="#">

                                                                           <xsl:value-of select="ID"/>

                                                                 </a>

                                                                 <xsl:value-of select="UserName"/>

                                                        </li>

                                               </xsl:for-each>

                                     </ul>

                                     <input type="text" name="Name" id="Name" />

                                     <input type="submit" name="PostName" id="PostName" value="提交" />

                            </body>

                   </html>

         </xsl:template>

 

</xsl:stylesheet>

注意,在XSLT中可包含用于提交数据的交互控件,但不需要为其定义事件处理,交互处理都由JS完成

    黑客防线网安服务器维护方案本篇连接:http://www.rongsen.com.cn/show-16311-1.html
网站维护教程更新时间:2012-04-06 01:18:20  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer