How to Read returned XML content and show as HTML in asp.net?

569 Views Asked by At

I have a HttpWebRequest from which the remote URL which returns an XML as reponse. Now, i want to parse this XML and read the content and show in to a DIV as HTML content.

Web Request:

protected string GetWebSiteContents(string url)
    {
        // Create HttpWebRequest
        HttpWebRequest httpWebReq = (HttpWebRequest)WebRequest.Create(url);
        httpWebReq.UserAgent = ".NET Framework Client";

        HttpWebResponse httpWebRes = (HttpWebResponse)httpWebReq.GetResponse();
        StreamReader sr = new StreamReader(httpWebRes.GetResponseStream());

        // Read the stream a line at a time and place each one into the stringbuilder
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        string strLine;
        while ((strLine = sr.ReadLine()) != null)
        {
            // Ignore blank lines
            if (strLine.Length > 0) 
                sb.Append(strLine);
        }
        sr.Close();
        httpWebRes.Close();
        return sb.ToString();
    }
enter code here

Show into Div:

result.InnerHtml = GetWebSiteContents(url);

From above code i am getting the XML Response from URL sent. Now, i want to show Parse this XML and show data into a DIV say div with id=result with runat=server.

Reuturned XML Response:

<?xml version="1.0" encoding="UTF-8"?><document><cert_link>http://certacell.com/embed/cert.html?certid=SEZQ-5701-X98H-72</cert_link><cert_id>SEZQ-5701-X98H-72</cert_id>**<cert_data>**&lt;div id=&quot;certacell_cert&quot;&gt;&lt;link 

href=&quot;http://www.certacell.com/static/css/certificate.bootstrap.css&quot; rel=&quot;stylesheet&quot; /&gt;&lt;link href=&quot;http://www.certacell.com/static/css/certificate.new.css&quot; rel=&quot;stylesheet&quot; /&gt; 

&lt;style&gt; hr { -moz-border-bottom-colors: none; -moz-border-left-colors: none; -moz-border-right-colors: none; -moz-border-top-colors: none; border-color: gray; border-image: none; border-right: 0 none; border-style: solid none none; 

border-width: 1px 0 0; margin-bottom: 20px; margin-top: 20px;} a { color: #4067f9; text-decoration: none;} &lt;/style&gt; &lt;div class=&quot;container header col-lg-12&quot; &gt;&lt;img style=&quot;margin-top: 1%;&quot; 

class=&quot;col-lg-3&quot; src=&quot;http://www.certacell.com/static/images/cert/logo.png&quot;&gt;&lt;h1 style=&quot;margin-top: 2%; color: #ffffff;  text-shadow: black 0.2em 0.2em 0.3em;&quot; class=&quot;&quot; &gt; | Device History 

Report&lt;/h1&gt;&lt;/div&gt; &lt;div class=&quot;separator container&quot; &gt;&lt;/div&gt;&lt;div class=&quot;content container&quot; style=&quot;padding-top: 1%;&quot;&gt;&lt;div class=&quot;col-lg-6 text-center&quot; 

style=&quot;padding-top: 4%;&quot;&gt;&lt;h4 class=&quot;&quot;&gt;   Certification Created on: 12 Sep 2013 04:01pm &lt;/h4&gt;&lt;h4 class=&quot;&quot;&gt; Unique Certification ID:&lt;/h4&gt;&lt;h2 class=&quot;&quot;&gt; SEZQ-5701-

X98H-72&lt;/h2&gt;&lt;div class=&quot;&quot;&gt;&lt;/div&gt; &lt;div class=&quot;text-left col-lg-offset-2 clearfix&quot;&gt;&lt;hr class=&quot;col-lg-9&quot; &gt; &lt;div class=&quot;clearfix&quot;&gt;&lt;/div&gt;&lt;span 

style=&quot;margin-top: 10%; font-size: x-large&quot;&gt;   Device Carrier: AT&amp;T Wireless &lt;/span&gt; &lt;br class=&quot;clearfix&quot;&gt;&lt;span style=&quot;margin-top: 10%; font-size: x-large&quot;&gt;  Device Manufacturer: NA  

&lt;/span&gt; &lt;br class=&quot;clearfix&quot;&gt;&lt;span style=&quot;margin-top: 10%; font-size: x-large&quot;&gt;  Device History: Clean &lt;/span&gt;&lt;/div&gt;&lt;/div&gt; &lt;div class=&quot;col-lg-6&quot;&gt; &lt;br 

class=&quot;clearfix&quot;&gt;&lt;div class=&quot;col-lg-offset-1&quot;&gt;&lt;div class=&quot;row&quot;&gt;&lt;img src=&quot;http://www.certacell.com/static/images/cert/check.png&quot; class=&quot;col pull-left&quot;&gt; &lt;span 

style=&quot;font-size: large; padding-left: 4%; &quot; class=&quot;col-lg-9&quot;&gt;  This device is Clear for Activation on AT&amp;T Wireless&lt;/span&gt;&lt;/div&gt; &lt;br class=&quot;clearfix&quot;&gt;&lt;div 

class=&quot;row&quot;&gt;&lt;img src=&quot;http://www.certacell.com/static/images/cert/check.png&quot; class=&quot;col pull-left&quot;&gt; &lt;span style=&quot;font-size: large; padding-left: 4%;&quot; class=&quot;col-lg-9&quot;&gt; This 

device is Certified to be an Authentic NA Device&lt;/span&gt;&lt;/div&gt;  &lt;br class=&quot;clearfix&quot;&gt;&lt;div class=&quot;row&quot;&gt;&lt;img src=&quot;http://www.certacell.com/static/images/cert/check.png&quot; 

class=&quot;col pull-left&quot;&gt; &lt;span style=&quot;font-size: large; padding-left: 4%; padding-top: 10px;&quot; class=&quot;col-lg-9&quot;&gt; This device has NOT been reported lost or stolen &lt;/span&gt;&lt;/div&gt;&lt;/div&gt; 

&lt;br class=&quot;clearfix&quot;&gt;&lt;div style=&quot;color: gray; font-size: larger&quot;&gt;To verify this ceriticate’s authenticity please visit &lt;a href=&quot;http://www.certacell.com&quot; 

target=&quot;_blank&quot;&gt;www.CertaCell.com&lt;/a&gt;.&lt;br class=&quot;clearfix&quot;&gt; Certificate is subject to Certacell &lt;a href=&quot;http://www.certacell.com&quot; target=&quot;_blank&quot;&gt;terms and 

conditions.&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;separator container&quot; &gt;&lt;/div&gt;&lt;/div&gt;**</cert_data>**<clean>True</clean></document>

Is it possible to return the data of '**cert_data tag ' and show as html to a DIV ?**

Help appreciated!

0

There are 0 best solutions below