8,906
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Xml.Serialization;
[XmlRoot("book")]
public class Book{
[XmlElement("author")]
public string author;
public Book(){}
public Book(string author){
this.author=author;
}
}
/*这个类包含形式为[XmlRoot()]和[XmlElement()]的说明,XmlSerializer类将利
用这些说明:
*/
<%@ WebHandler Language="c#" Class="TestHttpHandler2" %>
using System;
using System.IO;
using System.Web;
using System.Xml;
using System.Xml.Serialization;
public class TestHttpHandler2:IHttpHandler{
public void ProcessRequest(HttpContext context){
//String containing the author name
string author=context.Request.QueryString.Get("author");
//outputStream to serialize the result to
stream outputStream=context.Response.OutputStream;
//Set resulting content type
context.Response.ContentType="application/xml";
//Create Book instance and serialize it
Book book=new Book(author);
Xmlserializer xmlSerializer=new XmlSerializer(typeof(Book));
xmlserializer.Serialize(outputStream,book);
}
public bool IsReusable{ get {return true;} }
}