Tuesday, January 31, 2012

XDcoument Linq to AXML

public class FeedDefintion
{
public string State { get; set; }
public string Zip { get; set; }
}
public void ProcessRequest(HttpContext context)
{
//write your handler implementation here.
XDocument xdoc = XDocument.Load(context.Server.MapPath("Listings.xml"));




var feeds = from feed in xdoc.Descendants("Categories")
select new FeedDefintion { State = feed.Element("State").Value, Zip = feed.Element("Zip").Value };
List fl = feeds.ToList();


System.Web.Script.Serialization.JavaScriptSerializer oSerializer =
new System.Web.Script.Serialization.JavaScriptSerializer();

string sJSON = oSerializer.Serialize(fl);

//context.Response.ContentType = "application/json";
context.Response.ContentType = "application/json";

sJSON = context.Request.QueryString["callback"] + "(" + sJSON + ");";
context.Response.Write(sJSON);
}

No comments: