【问题标题】:how can i load the contents of an xml file at a url into a string?如何将 url 处的 xml 文件的内容加载到字符串中?
【发布时间】:2010-06-24 09:06:16
【问题描述】:

如何将 url 中的 xml 文件的内容加载到字符串中?

例如http://www.example.com/test.xml有一个xml文件

我希望将 xml 的文本分配给一个字符串。 如何使用 c# 做到这一点?

谢谢

【问题讨论】:

    标签: c# asp.net


    【解决方案1】:

    好吧,在我看来,它是 XML 的事实无关紧要 - 只需将其作为字符串下载:

    WebClient client = new WebClient();
    string text = client.DownloadString(url);
    

    【讨论】:

    【解决方案2】:

    获取 xml 文件的其他方法是通过 HttpRequest,然后您可以解析 XML,如果这是您需要的: previous question on the matter (with code sample)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多