Using HTML Agility Pack with WP7.5

Topics: Developer Forum, User Forum
Dec 10, 2011 at 5:25 AM

Hi,

I'm trying to compile the source for WP7.5. Is there a guide or a reference to follow for compiling the source for WP7.5? I'm trying to extract the text from a given URL and I would want my WP7 app to do that.

 

Thanks

Dec 10, 2011 at 11:41 AM

There is w WP 7.5 binary available in the Nuget package http://nuget.org/packages/HtmlAgilityPack

Dec 10, 2011 at 12:10 PM

Thanks a lot. Will look into it and give an update.

Dec 10, 2011 at 12:55 PM

I successfully added HtmlAgilityPack to my project. However, I tried the following code to extract the body text:

 HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();

   
// There are various options, set as needed
    htmlDoc
.OptionFixNestedTags=true;

   
// filePath is a path to a file containing the html
    htmlDoc
.Load(filePath);

   
// Use:  htmlDoc.LoadXML(xmlString);  to load from a string

   
// ParseErrors is an ArrayList containing any errors from the Load statement
   
if (htmlDoc.ParseErrors!=null && htmlDoc.ParseErrors.Count>0)
   
{
       
// Handle any parse errors as required

   
}
   
else
   
{

       
if (htmlDoc.DocumentNode != null)
       
{
           
HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body");

           
if (bodyNode != null)
           
{
               
// Do something with bodyNode
           
}
       
}
   
}

and I receive the following error when building the project. 

Error 1 The type 'System.Xml.XPath.IXPathNavigable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml.XPath, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. D:\test\test\MainPage.xaml.cs 58

 

Can you please let me know what the issue is? Thanks for the help.

Dec 10, 2011 at 2:21 PM

Reference the System.Xml assembly in the project that is using the agility pack would be my first guess. I was going to say perhaps the internal library isn't but it is according to the latest source. Are you using this in an internal say Core project? Usually the Silverlight app projects reference System.Xml for you but not the Library projects if I recall correctly.

Dec 10, 2011 at 2:27 PM

I followed the nuget method of installing HtmlAgility Pack and in fact added the System.Xml reference again after I received this error. However, I still get the same error although I've referenced the library from my project. Can you elaborate on what you meant when you said abt a core project? I am developing a WP7 app using the Silverlight framework for Win Phones. This is just a part of the code I'm trying to work with. Can you let me know where to find the library projects? Yes, I did find System.Xml being referenced already and I added it again just out of curiosity although it went in vain. Thanks.

Dec 10, 2011 at 3:25 PM

I got same error The type 'System.Xml.XPath.IXPathNavigable' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Xml.XPath, Version=2.0.5.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.

Dec 10, 2011 at 4:19 PM

Found working version here - https://github.com/Windcape/HtmlAgilityPackWP/downloads

Dec 10, 2011 at 5:43 PM

add a reference to System.Xml.XPath that comes with the Silverlight 4 SDK. WP7 Mango is compatible with SL4 libraries . The dll can be found at C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client on X64 systems

Dec 11, 2011 at 1:05 AM

Thanks @darthobiwan. I rectified issue with referencing and I'm able to build and run my project without errors.

Dec 24, 2011 at 9:28 AM

Thank you very much @ep_wp7.

May 25, 2013 at 3:28 PM
Thanks. That sorted it for me darthobiwan!