如何阅读返回的XML内容并在asp.net中显示为HTML?

时间:2014-01-16 10:13:32

标签: c# asp.net xml-parsing httpresponse readxml

我有一个HttpWebRequest,远程URL从中返回XML作为响应。现在,我想解析此XML并阅读内容并显示为DIV HTML内容。

网络版请求:

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

显示为Div:

result.InnerHtml = GetWebSiteContents(url);

从上面的代码中我收到XML发送的URL回复。现在,我想展示解析此XML并将数据展示到一个DIV说div与id=resultrunat=server

重新设定的XML响应

<?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>

是否可以返回'** cert_data 标签'的数据并将其显示为dvd?**

帮助表示赞赏!

0 个答案:

没有答案