我有一个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=result
和runat=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>**<div id="certacell_cert"><link
href="http://www.certacell.com/static/css/certificate.bootstrap.css" rel="stylesheet" /><link href="http://www.certacell.com/static/css/certificate.new.css" rel="stylesheet" />
<style> 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;} </style> <div class="container header col-lg-12" ><img style="margin-top: 1%;"
class="col-lg-3" src="http://www.certacell.com/static/images/cert/logo.png"><h1 style="margin-top: 2%; color: #ffffff; text-shadow: black 0.2em 0.2em 0.3em;" class="" > | Device History
Report</h1></div> <div class="separator container" ></div><div class="content container" style="padding-top: 1%;"><div class="col-lg-6 text-center"
style="padding-top: 4%;"><h4 class=""> Certification Created on: 12 Sep 2013 04:01pm </h4><h4 class=""> Unique Certification ID:</h4><h2 class=""> SEZQ-5701-
X98H-72</h2><div class=""></div> <div class="text-left col-lg-offset-2 clearfix"><hr class="col-lg-9" > <div class="clearfix"></div><span
style="margin-top: 10%; font-size: x-large"> Device Carrier: AT&T Wireless </span> <br class="clearfix"><span style="margin-top: 10%; font-size: x-large"> Device Manufacturer: NA
</span> <br class="clearfix"><span style="margin-top: 10%; font-size: x-large"> Device History: Clean </span></div></div> <div class="col-lg-6"> <br
class="clearfix"><div class="col-lg-offset-1"><div class="row"><img src="http://www.certacell.com/static/images/cert/check.png" class="col pull-left"> <span
style="font-size: large; padding-left: 4%; " class="col-lg-9"> This device is Clear for Activation on AT&T Wireless</span></div> <br class="clearfix"><div
class="row"><img src="http://www.certacell.com/static/images/cert/check.png" class="col pull-left"> <span style="font-size: large; padding-left: 4%;" class="col-lg-9"> This
device is Certified to be an Authentic NA Device</span></div> <br class="clearfix"><div class="row"><img src="http://www.certacell.com/static/images/cert/check.png"
class="col pull-left"> <span style="font-size: large; padding-left: 4%; padding-top: 10px;" class="col-lg-9"> This device has NOT been reported lost or stolen </span></div></div>
<br class="clearfix"><div style="color: gray; font-size: larger">To verify this ceriticate’s authenticity please visit <a href="http://www.certacell.com"
target="_blank">www.CertaCell.com</a>.<br class="clearfix"> Certificate is subject to Certacell <a href="http://www.certacell.com" target="_blank">terms and
conditions.</a></div></div></div><div class="separator container" ></div></div>**</cert_data>**<clean>True</clean></document>
是否可以返回'** cert_data 标签'的数据并将其显示为dvd?**
帮助表示赞赏!