string strXML = "<?xml version=\"1.0\"?>";
strXML+="<books><bookdata id=\"1\">";
strXML+="<title>C# premier</title>";
strXML += "<year>2005</year>";
strXML+="<publisher> Qinghua University Press</publisher>";
strXML+="<Author>hou </Author>";
strXML+="<pagers>500 </pagers>";
strXML+="<description> c# fundation knowledge</description>";
strXML+="<Price>50.00</Price>";
strXML+="</bookdata>";
strXML+="<bookdata id=\"2\">";
strXML+="<title>xml premier</title>";
strXML+="<year>2005</year>";
strXML+="<publisher> Peking University Press</publisher>";
strXML+="<Author>Leo </Author>";
strXML+="<pagers>400 </pagers>";
strXML+="<description> xml fundation knowledge</description>";
strXML+="<Price>45.00</Price>";
strXML+="</bookdata>";
strXML+="<bookdata id=\"3\">";
strXML+="<title>UML</title>";
strXML+="<year>2005</year>";
strXML+="<publisher> Peking University Press</publisher>";
strXML+=" <Author>James </Author>";
strXML+=" <pagers>650 </pagers>";
strXML+=" <description>UML fundation knowledge</description>";
strXML += " <Price>85.00</Price>";
strXML+=" </bookdata></books>";
Response.ContentType = "text/xml";
Response.Charset = "UTF-8";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(strXML);
doc.Save(Response.OutputStream);
Response.End();
读取现有的xml:
Response.ContentType = "text/xml";
Response.Charset = "UTF-8";
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
string strPath = @"~/login/xmlfile";
doc.Load(Server.MapPath(strPath + "/books.xml"));//requests.xml是服务器上xml文件
Response.Write(doc.DocumentElement.OuterXml);
Response.End();
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/wsdgqs/archive/2008/03/31/2233662.aspx