Mega Code Archive

 
Categories / ASP.Net / XML
 

Set response type to XML

<%@ Page Language="C#"%> <%@ Import Namespace="System.Xml" %> <%@ Import Namespace="System.Xml.Schema" %> <script runat="server">         void Page_Load(object sender, EventArgs e)     {         Response.ContentType = "text/xml";         string xmlPath = MapPath("Authors.xml");                     XmlReader reader = XmlReader.Create(xmlPath);         XmlSchemaSet schemaSet = new XmlSchemaSet();         XmlSchemaInference schema = new XmlSchemaInference();         schemaSet = schema.InferSchema(reader);         foreach (XmlSchema schemaObj in schemaSet.Schemas())         {             schemaObj.Write(Response.Output);         }           }    </script> <%-- <?xml version="1.0"?> <authors>   <author>     <authorID>000-00-0001</authorID>     <lastName>Nancy</lastName>     <firstName>Lee</firstName>     <phone>999 999-9999</phone>     <address>9999 York St.</address>     <city>Regina</city>     <state>LA</state>     <zip>99999</zip>     <contract>true</contract>   </author>   <author>     <authorID>000-00-0002</authorID>     <lastName>First</lastName>     <firstName>Last</firstName>     <phone>415 986-7020</phone>     <address>No Name St.</address>     <city>Vancouver</city>     <state>BC</state>     <zip>88888</zip>     <contract>true</contract>   </author>  </authors> --%>