【问题标题】:How do I save xml in a webbrowser control?如何将 xml 保存在 webbrowser 控件中?
【发布时间】:2009-06-01 09:52:48
【问题描述】:

我有一个显示一些 xml 的 webbrowser 控件,当我访问文档属性时,我得到的是控件生成的 HTML,而不是 xml。如何保存文档的“来源”? (不能使用网络客户端)

【问题讨论】:

    标签: c# html xml text webbrowser-control


    【解决方案1】:

    你有原始路径不是吗?

    string urlPath = wb.Url;
    

    为什么不从那里下载源代码?

    private string GetSourceCode(string sourceUrl) {
       String url = String.Format(sourceUrl);
    
       WebClient client = new WebClient();
       client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;)"); // pass as Internet Explorer 7.0
    
       Stream data = client.OpenRead(url);
       StreamReader reader = new StreamReader(data);
       s = reader.ReadToEnd();
       data.Close();
       reader.Close();
    
       return s;
    }
    

    使用 GetSourceCode() 方法,您可以在返回的字符串中拥有整个源(原始源)...用它做你想做的事;)

    string xmlSource = GetSourceCode(wb.Url);
    

    【讨论】:

    • 他的问题具体说“(不能使用webclient)”
    猜你喜欢
    • 1970-01-01
    • 2011-08-19
    • 2013-05-09
    • 1970-01-01
    • 2013-07-06
    • 2012-08-02
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多