用response输出XML

直接在代码中组织xml:   

string strXML = "";
                strXML+="";
           
     strXML+="C# premier";
     strXML += "2005";
     strXML+=" Qinghua University Press";
     strXML+="hou ";
     strXML+="500 ";
     strXML+=" c# fundation knowledge";
     strXML+="50.00";
   strXML+="
";

   strXML+="";
     strXML+="xml premier";
     strXML+="2005";
     strXML+=" Peking University Press";
     strXML+="Leo ";
     strXML+="400 ";
     strXML+=" xml fundation knowledge";
     strXML+="45.00";
  strXML+="
";

   strXML+="";
     strXML+="UML";
     strXML+="2005";
     strXML+=" Peking University Press";
    strXML+=" James ";
    strXML+=" 650 ";
    strXML+=" UML fundation knowledge";
    strXML += " 85.00";
  strXML+="
";

            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();

 

你可能感兴趣的:(用response输出XML)