• <label id="pxtpz"><meter id="pxtpz"></meter></label>
      1. <span id="pxtpz"><optgroup id="pxtpz"></optgroup></span>

        當(dāng)前位置:雨林木風(fēng)下載站 > 技術(shù)開發(fā)教程 > 詳細(xì)頁面

        ASP.NET中的XML表單控件

        ASP.NET中的XML表單控件

        更新時間:2022-05-13 文章作者:未知 信息來源:網(wǎng)絡(luò) 閱讀次數(shù):

        導(dǎo) 讀:介紹了有關(guān)ASP.NET中XML控件的使用,有個小BUG:在WEBFORM.ASPX中出現(xiàn)的XML控件,其中的transformsource屬性設(shè)定了樣式表文件路徑,可是在文章出處沒有找到這個XSL文件.:( 自己解決吧.
        在這個代碼中揭示了微軟在ASP.NET架構(gòu)中隱藏的一個WEB表單控件,即<asp:xml runat=server/>,我只給代碼,不給解釋,大家自己下課后去研究吧。
        另外,由于是beta1,在這個控件中你使用的xslt里面不能使用<xsl:sort>,當(dāng)然,亦不能使用那個order-by了,因為它支持的xsl空間是帶"1999"的那個,而不是原來的那個。
        另外,我從微軟得到的回答就是在beta2里面,它將支持<xsl:sort>,就可以全部轉(zhuǎn)向xml+xsl了,而不用再為源代碼保密問題頭疼了。
        請看下例:
        webform2.cs
                                        -
        using System;
        using System.Collections;
        using System.ComponentModel;
        using System.Data;
        using System.Drawing;
        using System.Web;
        using System.Web.SessionState;
        using System.Web.UI;
        using System.Web.UI.WebControls;
        using System.Web.UI.HtmlControls;
        using System.Text;
        using System.IO;
        using System.Xml;

        public class WebForm2 : Page
        {
            public StringBuilder outputQ;
            public StringBuilder outputXml;
              public DocumentNavigator nav = null;
            public HtmlInputFile XmlFile;
            
            public System.Web.UI.WebControls.Xml MyXml;

            public System.Web.UI.WebControls.TextBox TextBox1;        
            public System.Web.UI.WebControls.TextBox TextBox2;
            public System.Web.UI.WebControls.TextBox TextBox3;        
            public System.Web.UI.WebControls.Button Query;
            public System.Web.UI.WebControls.Label FileLabel;
          
            public void On_KeyUp(object sender, System.EventArgs e)
            {
                Response.Write("Works");
            }

            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    //
                    // Evals true first time browser hits the page
                    //
                }
            }

            public void Query_Click(object sender, System.EventArgs e)
            {
                HttpPostedFile xmlfile = XmlFile.PostedFile;
                 XmlDocument doc = new XmlDocument();    
                 MyXml.Document = new XmlDocument();    
        //        TextBox2.Text="";
        //        TextBox3.Text="";

                if (xmlfile.FileName != String.Empty)
                {
                    try
                    {
                        FileLabel.Text= xmlfile.FileName;

                        MyXml.Document.Load(xmlfile.FileName);
                        outputXml = new StringBuilder();
                        XmlTextReader reader = new XmlTextReader (xmlfile.FileName);
                        ShowDocument();
                        TextBox3.Text = outputXml.ToString();

                        outputQ = new StringBuilder();
                        doc.Load(xmlfile.FileName);
                        DocumentNavigator nav = new DocumentNavigator(doc);
                        // Perform the query e.g. "descendant::book/price"
                        XPathQuery(nav, TextBox1.Text);
                        TextBox2.Text = outputQ.ToString();

                    }
                    catch (Exception exp) {
                        //outputQ.Append("</xmp><font color=\"#FF6600\">"+ exp.Message+"</font><xmp>");
                    }
                    finally {}
                }
                else if (FileLabel.Text != String.Empty)
                {
                    try
                    {
                        MyXml.Document.Load(FileLabel.Text);
                        outputXml = new StringBuilder();
                        XmlTextReader reader = new XmlTextReader (FileLabel.Text);
                        ShowDocument();
                        TextBox3.Text = outputXml.ToString();

                        ShowDocument();

                        outputQ = new StringBuilder();
                        doc.Load(FileLabel.Text);
                        DocumentNavigator nav = new DocumentNavigator(doc);
                        // Perform the query e.g. "descendant::book/price"
                        XPathQuery(nav, TextBox1.Text);
                        TextBox2.Text = outputQ.ToString();

                    }
                    catch (Exception exp) {
                        outputQ.Append("</xmp><font color=\"#FF6600\">"+ exp.Message+"</font><xmp>");
                    }
                    finally {}
                }
            }

            private void XPathQuery(XmlNavigator navigator, String xpathexpr )
            {
                try
                {
                    // Save context node position
                    navigator.PushPosition();
                    navigator.Select (xpathexpr);
                    FormatXml(navigator);

                    // Restore context node position
                    navigator.PopPosition();        
                }
                catch (Exception e)
                {
                }
            }
            
        //***************************** Navigator ************************************
            private void FormatXml (XmlNavigator navigator)
            {
                while (navigator.MoveToNextSelected())
                {
                    switch (navigator.NodeType)
                    {
                    case XmlNodeType.ProcessingInstruction:
                        Format (navigator, "ProcessingInstruction");
                        break;
                    case XmlNodeType.DocumentType:
                        Format (navigator, "DocumentType");
                        break;
                    case XmlNodeType.Document:
                        Format (navigator, "Document");
                        break;
                    case XmlNodeType.Comment:
                        Format (navigator, "Comment");
                        break;
                    case XmlNodeType.Element:
                        Format (navigator, "Element");
                        break;
                    case XmlNodeType.Text:
                        Format (navigator, "Text");
                        break;
                    case XmlNodeType.Whitespace:
                        Format (navigator, "Whitespace");
                        break;
                    }
                }
                outputQ.Append("\r\n");
            }

            // Format the output
            private void Format (XmlNavigator navigator, String NodeType)
            {
                String value = String.Empty;
                String name = String.Empty;

                if (navigator.HasChildren)
                {
                    name = navigator.Name;
                    navigator.MoveToFirstChild();
                    if (navigator.HasValue)
                    {
                        value = navigator.Value;
                    }
                }
                else
                {
                    if (navigator.HasValue)
                    {
                        value = navigator.Value;
                        name = navigator.Name;
                    }
                }
                outputQ.Append(NodeType + "<" + name + ">" + value);
                outputQ.Append("\r\n");
            }

        // ********************************** XmlReader *****************************
            public void ShowDocument ()
            {
                outputXml = new StringBuilder();
                XmlTextReader reader = new XmlTextReader (FileLabel.Text);

                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.ProcessingInstruction:
                        Format (reader, "ProcessingInstruction");
                        break;
                    case XmlNodeType.DocumentType:
                        Format (reader, "DocumentType");
                        break;
                    case XmlNodeType.Comment:
                        Format (reader, "Comment");
                        break;
                    case XmlNodeType.Element:
                        Format (reader, "Element");
                        break;
                    case XmlNodeType.Text:
                        Format (reader, "Text");
                        break;
                    case XmlNodeType.Whitespace:
                        break;
                    }
                }
                TextBox3.Text = outputXml.ToString();
            }

            protected void Format(XmlReader reader, String NodeType)
            {
                // Format the output
                for (int i=0; i < reader.Depth; i++)
                {
                    outputXml.Append('\t');
                }

                outputXml.Append(reader.Prefix + NodeType + "<" + reader.Name + ">" + reader.Value);

                // Display the attributes values for the current node
                if (reader.HasAttributes)
                {
                    outputXml.Append(" Attributes:");

                    for (int j=0; j < reader.AttributeCount; j++)
                    {
                        outputXml.Append(reader[j]);
                    }
                }
                outputXml.Append("\r\n");
            }

            /// ************************* DOM *********************************
            protected void ShowDocument(XmlNode node)
            {
                if (node != null)
                    Format (node);

                if (node.HasChildNodes)
                {
                    node = node.FirstChild;
                    while (node != null)
                    {
                        ShowDocument(node);
                        node = node.NextSibling;
                    }
                }
            }

            // Format the output
            private void Format (XmlNode node)
            {
                if (!node.HasChildNodes)
                {
                   outputXml.Append("\t" + "<" + node.Value + ">");
                }

                else
                {
                    outputXml.Append("<" + node.Name + ">");
                    if (XmlNodeType.Element == node.NodeType)
                    {
                        XmlNamedNodeMap map = node.Attributes;
                        foreach (XmlNode attrnode in map)
                            outputXml.Append(" " + attrnode.Name + "<" + attrnode.Value + "> ");
                    }
                    outputXml.Append("\r\n");
                }
            }
        }


        下面就是webform2.aspx了
        webform2.aspx
                                        ---
        <%@ Import Namespace="System" %>
        <%@ Import Namespace="System.IO" %>
        <%@ Assembly Name="System.Xml" %>
        <%@ Import Namespace="System.Xml" %>
        <%@ Page Language="C#" Inherits="WebForm2" Src="WebForm2.cs" Debug="true" %>

        <HTML><HEAD>

          <script runat="server" language="C#">
            // Put page script here
                public void On_KeyUp(object sender, System.EventArgs e)
            {
                Response.Write("Works");
            }

          </script>

        <!--<link REL="STYLESHEET" HREF="default.css" TYPE="text/css">-->
        <TITLE>test</TITLE>
        </HEAD>

        <BODY   >

            
        <form method="post" action="WebForm2.aspx" runat="server" enctype="multipart/form-data">
          
        <div align="left">
        <table>
          <tr>
            <td>XML Document:</td>
            <td><input type=file id="XmlFile" runat=server>         FileName:</td>
            <td><asp:label id="FileLabel" runat="server"></asp:label></td>
          </tr>

          <tr>
            <td>XPath Expression</td>
            <td><asp:textbox id=TextBox1 runat="server" Height="20" Width="300" text=".//text()"
        OnKey_Up="On_KeyUp"></asp:textbox></td>
            <td><asp:button type=submit OnClick="Query_Click" runat="server" Height="20" Width="91"
        text="Query"></asp:button></td>
          </tr>
        </table>

        </br>
        <table>
          <tr><td>Output from Query</td><td>XML Data</td><tr>
          <tr><td>Query Display: <asp:dropdownlist runat="server">
                                 <asp:listitem>Descriptive</asp:listitem>
                                 <asp:listitem>XML</asp:listitem>
                                 </asp:dropdownlist>
          </td><tr>
          <tr>
            <td width="50%" valign="top" align="left"><asp:textbox id=TextBox2 runat="server" Height="400"
        Width="350" TextMode="MultiLine" Rows="10"></asp:textbox></td>
            <td width="50%" valign="top" align="left"><asp:xml id="MyXml" transformsource="test.xsl"
        runat=server/></asp:xml></td>
          </tr>
        </table>
        </div>

            <td><asp:textbox id=TextBox3 runat="server" Height="1" Width="5" TextMode="MultiLine"
        Rows="110"></asp:textbox></td>

        </form>
            
        </BODY>
        </HTML>

        溫馨提示:喜歡本站的話,請收藏一下本站!

        本類教程下載

        系統(tǒng)下載排行

        主站蜘蛛池模板: xvideos亚洲永久网址| 天天操夜夜操免费视频| 国产偷窥女洗浴在线观看亚洲 | 日韩精品亚洲人成在线观看| 亚洲高清免费视频| ZZIJZZIJ亚洲日本少妇JIZJIZ| 欧洲亚洲综合一区二区三区 | 成人免费毛片内射美女APP| 亚洲国产精品成人久久久| 91成人免费在线视频| 国产成+人+综合+亚洲专| 免费无码又爽又刺激聊天APP| 亚洲一区二区三区无码国产| 国产99视频精品免费观看7| 国产v亚洲v天堂a无| 好吊妞在线成人免费| 成人精品国产亚洲欧洲| 久久国产成人精品国产成人亚洲 | 国产精品久久免费| 亚洲精品一二三区| 免费真实播放国产乱子伦| 国产黄在线观看免费观看不卡| 亚洲AV一宅男色影视| 免费v片在线观看视频网站| 亚洲一区二区无码偷拍| 免费人成激情视频| 久草免费手机视频| 亚洲制服丝袜中文字幕| 亚洲精品无码久久久| 一区二区免费视频| 亚洲精品动漫免费二区| 亚洲精品无码久久久久sm| 精品无码免费专区毛片| 在线91精品亚洲网站精品成人| 亚洲中文字幕久久精品无码APP| 老汉精品免费AV在线播放| 久久综合久久综合亚洲| 亚洲精品高清一二区久久| 无人在线观看免费高清| 亚洲av无码专区亚洲av不卡| 亚洲人成伊人成综合网久久久|