繁体   English   中英

在简单的WP8应用程序中出现XML错误

[英]Error with XML in a simple WP8 application

我的代码是这样的:

namespace MyNSpace
{
    public partial class MainPage : PhoneApplicationPage
    {
        public MainPage()
        {
            InitializeComponent();
        }

        async private void ButtonParse_Click(object sender, RoutedEventArgs e)
        {
            HttpClient client = new HttpClient();
            var doc = new HtmlAgilityPack.HtmlDocument();
            string url = "www.mysite.com";
            string html = await client.GetStringAsync(url);
            doc.LoadHtml(html);
            HtmlNodeCollection tl = doc.DocumentNode.SelectNodes("//div[@class=\"photo\"]/a/img");
            //I must still write this part
        }
    }
}

我在var doc = new HtmlAgilityPack.HtmlDocument();上收到此错误var doc = new HtmlAgilityPack.HtmlDocument(); 线:

类型'System.Xml.XPath.IXPathNavigable'在未引用的程序集中定义。 您必须添加对程序集'System.Xml.XPath,Version = 2.0.5.0,Culture = neutral,

为什么? 我读到人们如果没有手动加载某些System.Xml.XPath.dll并编写“使用”行,就会遇到此问题。 如果尝试手动导入DLL,则会收到错误消息,我试图添加对不兼容程序集的引用。 这是我第一次为Windows Phone编程,因此如果出现问题,我也不会感到惊讶。

确保已添加对System.Xml.XPath.dll Silverlight版本的引用。 这是在Windows Phone Project中使用HtmlAgilityPack所必需的。

我仅使用Windows Phone 7.5进行了测试,但根据本文,它似乎也适用于Windows Phone 8项目(请参阅该链接中的文章元数据 > 兼容平台部分)。 在我的情况下, .dll驻留在以下路径中:

C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client

暂无
暂无

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

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