views:

55

answers:

2

hi, I want to generate html content based on a result returned by http url.

http://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=X1-ZWz1c239bjatxn_5taq0&address=2114+Bigelow+Ave&citystatezip=Seattle%2C+WA

This page will give you some xml results. I want to convert to use that xml to generate html. I am not getting any idea where to start? any guide line/ sample code for asp.net?

For details
http://www.zillow.com/howto/api/GetDeepSearchResults.htm

thanks

A: 

To fetch the data you can use the HttpWebRequest class, this is an example I have to hand but it may be slightly overdone for your needs (and you need to make sure you're doing the right thing - I suspect the above to be a GET rather than a POST) hmm, I'm going to tick the WIKI box please feel free to fix the code (-:

Uri baseUri = new Uri(this.RemoteServer);

HttpWebRequest rq = (HttpWebRequest)HttpWebRequest.Create(new Uri(baseUri, action));
rq.Method = "POST";
rq.ContentType = "application/x-www-form-urlencoded";

rq.Accept = "text/xml";
rq.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

Encoding encoding = Encoding.GetEncoding("UTF-8");
byte[] chars = encoding.GetBytes(body);
rq.ContentLength = chars.Length;

using (Stream stream = rq.GetRequestStream())
{
    stream.Write(chars, 0, chars.Length);
    stream.Close();
}

XDocument doc;
WebResponse rs = rq.GetResponse();
using (Stream stream = rs.GetResponseStream())
{
    using (XmlTextReader tr = new XmlTextReader(stream))
    {
        doc = XDocument.Load(tr);
        responseXml = doc.Root;
    }

    if (responseXml == null)
    {
        throw new Exception("No response");
    }
 }

 return responseXml;

Once you've got the data back you need to render HTML, lots and lots of choices - if you just want to convert what you've got into HTML with minimal further processing then you can use XSLT - which is a question all on its own. If you need to do stuff with it then the question is too vague and you'll need to be more specific.

Murph
A: 

Create a xsl stylesheet, and inject the stylesheet element into the resulting xml from teh page

Midhat