简体   繁体   English

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

[英]Error with XML in a simple WP8 application

My code is this: 我的代码是这样的:

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
        }
    }
}

I get this error on the var doc = new HtmlAgilityPack.HtmlDocument(); 我在var doc = new HtmlAgilityPack.HtmlDocument();上收到此错误var doc = new HtmlAgilityPack.HtmlDocument(); line: 线:

The type 'System.Xml.XPath.IXPathNavigable' is defined in an assembly that is not referenced. 类型'System.Xml.XPath.IXPathNavigable'在未引用的程序集中定义。 You must add a reference to assembly 'System.Xml.XPath, Version=2.0.5.0, Culture=neutral, 您必须添加对程序集'System.Xml.XPath,Version = 2.0.5.0,Culture = neutral,

Why? 为什么? I read that people got this problem if they didn't load a certain System.Xml.XPath.dll both manually and writing the Using line. 我读到人们如果没有手动加载某些System.Xml.XPath.dll并编写“使用”行,就会遇到此问题。 If I try to import the DLL manually, I get an error that I'm trying to add a reference to an assembly that is not compatible. 如果尝试手动导入DLL,则会收到错误消息,我试图添加对不兼容程序集的引用。 It's the first time I'm programming for Windows Phone, so I won't be surprised if it's a little problem. 这是我第一次为Windows Phone编程,因此如果出现问题,我也不会感到惊讶。

Make sure you added reference to Silverlight version of System.Xml.XPath.dll . 确保已添加对System.Xml.XPath.dll Silverlight版本的引用。 That's required to use HtmlAgilityPack in Windows Phone Project. 这是在Windows Phone Project中使用HtmlAgilityPack所必需的。

I've tested with Windows Phone 7.5 only, but based on this article it seems to be working for Windows Phone 8 project too (see Article Metadata > Compatibility Platform(s) section in that link). 我仅使用Windows Phone 7.5进行了测试,但根据本文,它似乎也适用于Windows Phone 8项目(请参阅该链接中的文章元数据 > 兼容平台部分)。 In my case the .dll resides in this path : 在我的情况下, .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