我创建了一个XPathDocumnet并给它一个xml file,但是它没有加载文档。我的意思是,它需要无穷大的加载,因为没有异常或类似的东西。代码如下:
string root = @"http://emtehan.roshd.ir";
WebClient webclient = new WebClient();
webclient.DownloadFile(root, "doc.xml");
XPathDocument document = new XPathDocument("doc.xml");发布于 2012-05-13 00:04:49
问题出在你的目标站点--它没有使用标准的标签,我的意思是在解析xml时有问题。看起来你只是想从代码中提取urls。所以使用一个示例httpclient来下载行html内容,然后使用ereg函数来提取urls。此外,如果你只是想利用一个网站,有很多很好的应用程序,比如websote offline explorer(试用版),甚至是一些开源项目(refrence:google.com!)
*ereg方法比解析所有代码要快得多!查看一些开源项目的代码,它们都是这样工作的。
发布于 2012-05-12 22:00:40
您可以引用System.Xml.Linq.dll
代码在这里
///Reference the namespace
using System.Xml.Linq;
try
{
///Read xml from url
var doc = XDocument.Load("MyUrl");
///Write it to local file
doc.Save("MyFile.xml");
}
catch(Exception exception)
{
MessageBox.Show(exception.Message);
}它能解决这个问题吗?
编辑的
var response = HttpWebRequest.Create("http://emtehan.roshd.ir/").GetResponse() as HttpWebResponse;
var output = new StreamReader(response.GetResponseStream()).ReadToEnd();它将html转换为字符串,然后您可以执行任何操作
https://stackoverflow.com/questions/10564202
复制相似问题