100分求解远程读取网站源代码问题
我要读“魔兽英雄榜”网站的源代码,网址是:
http://cn.wowarmory.com/character-sheet.xml?r=%E8%AF%95%E7%82%BC%E4%B9%8B%E7%8E%AF&n=%E6%9C%88%E4%B8%8B
其中参数"r=%E8%AF%95%E7%82%BC%E4%B9%8B%E7%8E%AF"是我输入的服务器名,解码后为:"r=试练之环";“n=%E6%9C%88%E4%B8%8B”是玩家名,解码后为"n=月下"
现在打开这个网面后我查看源代码为xml格式:
<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="/layout/character-sheet.xsl"?><page globalSearch="1" lang="zh_cn" requestUrl="/character-sheet.xml">
<characterInfo>
<character battleGroup="Battle Group 18" charUrl="r=%E8%AF%95%E7%82%BC%E4%B9%8B%E7%8E%AF&n=%E6%9C%88%E4%B8%8B" class="圣骑士" classId="2" faction="部落" factionId="1" gender="女性" genderId="1" guildName="燃烧末日黎明" guildUrl="r=%E8%AF%95%E7%82%BC%E4%B9%8B%E7%8E%AF&n=%E7%87%83%E7%83%A7%E6%9C%AB%E6%97%A5%E9%BB%8E%E6%98%8E&p=1" lastModified="2009年4月1日" level="70" name="月下" points="1150" prefix="" race="血精灵" raceId="10" realm="试炼之环" suffix="">
...............略
</page>
这个网页的源代码这就略了,你可以打开网页自己查看,
但是我用程序读的时后却是html格式:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
....略
</body>
</html>
我的程序是这样写的:
//根据Url地址生成静态页保持
protected void Button2_Click(object sender, EventArgs e)
{
Encoding code = Encoding.GetEncoding("utf-8");
StreamReader sr = null;
StreamWriter sw = null;
string str = null;
//读取远程路径
WebRequest temp = WebRequest.Create("这里是上面的网址");
WebResponse myTemp = temp.GetResponse();
sr = new StreamReader(myTemp.GetResponseStream(), code);
//读取
try
{
sr = new StreamReader(myTemp.GetResponseStream(), code);
str = sr.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sr.Close();
}
string fileName = DateTime.Now.ToString("yyyyMMddHHmmss") + ".xml";
//写入
try
{
sw = new StreamWriter(Server.MapPath("htm/") + fileName, false, code);
sw.Write(str);
sw.Flush();
}
catch (Exception ex)
{
throw ex;
}
finally
{
sw.Close();
Response.Write("恭喜<a href=htm/" + fileName + " target=_blank>" + fileName + "</a>已经生成,保存在htm文件夹下!");
}
}
我现在就是想把这个网站的xml格式读取出来,不要html格式的,请问怎么写程序,
另外为什么网页打开后我查看源代码是xml格式的,而我用程序读的时候却是html格式的呢?