I'm trying the DownloadData
method from the WebClient
. My current problem is that I haven't been able to figure out how to convert the ASCII
result (<
to <
, \n
, >
to >
) which is produced from Encoding.ASCII.GetString(myDataBuffer);
, out of this page.
(source: 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;
}
}
Code for PMIDCrawler is available on my other SO question regarding the DownloadStringCompletedEventHandler
. Although output from string html = HttpUtility.HtmlDecode(nHtml);
is not valid HTML (OR XML) (Due it not responding to xml
http headers), after receiving content from Encoding.ASCII.GetString
.