【发布时间】:2013-02-28 20:15:23
【问题描述】:
我正在尝试WebClient 中的DownloadData 方法。我目前的问题是我无法弄清楚如何将ASCII result(&lt; 到 <、\n、&gt; 到 >)转换为>),它是由Encoding.ASCII.GetString(myDataBuffer); 生成的,从这个page.
(来源:iforce.co.nz)
/// <summary>
/// Curl data from the PMID
/// </summary>
private void ClientPMID(int pmid)
{
//generate the URL for the client
StringBuilder pmid_url_string = new StringBuilder();
pmid_url_string.Append("http://www.ncbi.nlm.nih.gov/pubmed/").Append(pmid.ToString()).Append("?report=xml");
Uri PMIDUri = new Uri(pmid_url_string.ToString());
//declare and initialize the client
WebClient client = new WebClient();
// Download the Web resource and save it into a data buffer.
byte[] myDataBuffer = client.DownloadData(PMIDUri);
this.DownloadCompleted(myDataBuffer);
}
/// <summary>
/// Crawl over the binary from myDataBuffer
/// </summary>
/// <param name="myDataBuffer">Binary Buffer</param>
private void DownloadCompleted(byte[] myDataBuffer)
{
string download = Encoding.ASCII.GetString(myDataBuffer);
PMIDCrawler pmc = new PMIDCrawler(download, "/pre/PubmedArticle/MedlineCitation/Article");
//iterate over each node in the file
foreach (XmlNode xmlNode in pmc.crawl)
{
string AbstractTitle = xmlNode["ArticleTitle"].InnerText;
string AbstractText = xmlNode["Abstract"]["AbstractText"].InnerText;
}
}
PMIDCrawler 的代码可在我关于DownloadStringCompletedEventHandler 的其他 SO 问题中找到。虽然string html = HttpUtility.HtmlDecode(nHtml); 的输出无效HTML (OR XML)(由于它没有响应xml http 标头),但在接收到来自Encoding.ASCII.GetString 的内容后。
【问题讨论】:
-
这里是如何使用 javascript 例如stackoverflow.com/questions/5796718/html-entity-decode
标签: c# html xml ascii webclient