⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 對c#初學者參考..為課題asp.net 2.0教材代碼
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.Serialization;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Double price = 49.99;
        DateTime publicationdate = new DateTime(2005, 1, 1);
        String isbn = "1-057-610-0";
        Author a = new Author();
        a.FirstName = "Scott";
        a.LastName = "Hanselman";

        XmlWriterSettings settings = new XmlWriterSettings();
        settings.Indent = true;
        settings.NewLineOnAttributes = true;

        Response.ContentType = "text/xml";

        XmlSerializerFactory factory = new XmlSerializerFactory();

        using (XmlWriter writer =
                XmlWriter.Create(Response.OutputStream, settings))
        {
            //Note the artificial, but useful, indenting
            writer.WriteStartDocument();
            writer.WriteStartElement("bookstore");
            writer.WriteStartElement("book");
            writer.WriteStartAttribute("publicationdate");
            writer.WriteValue(publicationdate);
            writer.WriteEndAttribute();
            writer.WriteStartAttribute("ISBN");
            writer.WriteValue(isbn);
            writer.WriteEndAttribute();
            writer.WriteElementString("title", "ASP.NET 2.0");
            writer.WriteStartElement("price");
            writer.WriteValue(price);
            writer.WriteEndElement(); //price
            XmlSerializer xs = factory.CreateSerializer(typeof(Author));
            xs.Serialize(writer, a);
            writer.WriteEndElement(); //book
            writer.WriteEndElement(); //bookstore
            writer.WriteEndDocument();
        }

    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -