简体   繁体   English

使用c#从URL下载xml文件

[英]Downloading xml file from a url using c#

I would like to download the document on this (" http://www.ploscompbiol.org/article/info%3Adoi%2F10.1371%2Fjournal.pcbi.1002244 ") page as an xml file. 我想将此文档(“ http://www.ploscompbiol.org/article/info%3Adoi%2F10.1371%2Fjournal.pcbi.1002244 ”)页面下载为xml文件。 I have tried webclient.downloadfile() but i got errors. 我试过webclient.downloadfile()但是我遇到了错误。 can anyone suggest how to go about it using c#. 任何人都可以建议如何使用c#去做。

Thanks. 谢谢。

You can use something like this: (note the URL I'm using...) 你可以使用这样的东西:( 注意我正在使用的URL ...)

public static string DownloadString(string address) 
{
    string text;
    using (var client = new WebClient()) 
    {
        text = client.DownloadString(address);
    }
    return text;
}

private static void Main(string[] args) 
{    
    var xml = DownloadString(@"http://www.ploscompbiol.org/article/fetchObjectAttachment.action?uri=info%3Adoi%2F10.1371%2Fjournal.pcbi.1002244&representation=XML");            
    File.WriteAllText("blah.xml", xml);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM