네이버 오늘의 환율 시세 출력에서 last_update 추가 (C#)

// 네이버 오늘의 환율 시세 출력 (C#)
public void DownloadTodayCurrencyExchangeRates()
{
WebClient client = new WebClient();
client.Headers.Add(“Referer”, “http://blog.naver.com/usback“);
Stream xmlDataStream = client.OpenRead(
http://www.naver.com/include/timesquare/widget/exchange.xml“);
XmlReader reader = XmlReader.Create(xmlDataStream);
reader.MoveToContent();

// last_update
reader.ReadToFollowing(“last_update”);
string lastUpdate = reader.ReadElementContentAsString(“last_update”,
reader.NamespaceURI);
int year = int.Parse(lastUpdate.Substring(0, 4));
int month = int.Parse(lastUpdate.Substring(4, 2));
int day = int.Parse(lastUpdate.Substring(6, 2));
int hour = int.Parse(lastUpdate.Substring(8, 2));
int minute = int.Parse(lastUpdate.Substring(10, 2));
int second = int.Parse(lastUpdate.Substring(12, 2));
lastUpdated = new DateTime(year, month, day, hour, minute, second);

while (reader.ReadToFollowing(“currency”))
{
reader.ReadToFollowing(“hname”);
string hname = reader.ReadElementContentAsString(“hname”,
reader.NamespaceURI);
reader.ReadToFollowing(“standard”);
double standard = reader.ReadElementContentAsDouble(“standard”,
reader.NamespaceURI);
reader.ReadToFollowing(“buy”);
double buy = reader.ReadElementContentAsDouble(“buy”,
reader.NamespaceURI);
reader.ReadToFollowing(“sell”);
double sell = reader.ReadElementContentAsDouble(“sell”,
reader.NamespaceURI);
reader.ReadToFollowing(“sign”);
string sign = reader.ReadElementContentAsString(“sign”,
reader.NamespaceURI);
Console.WriteLine(“{0}\t{1}\t{2}\t{3}\t{4}”, hname, standard, buy, sell, sign);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *