<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Where did the time go? - Silverlight</title>
    <link>http://blog.j-maxx.net/</link>
    <description>Brain Powered</description>
    <language>en-us</language>
    <copyright>Jeff Klawiter</copyright>
    <lastBuildDate>Sun, 06 Jun 2010 00:17:49 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>Jeff.Klawiter@sierra-bravo.com</managingEditor>
    <webMaster>Jeff.Klawiter@sierra-bravo.com</webMaster>
    <item>
      <trackback:ping>http://blog.j-maxx.net/Trackback.aspx?guid=ddec503d-058c-4c14-8d31-140047924fe1</trackback:ping>
      <pingback:server>http://blog.j-maxx.net/pingback.aspx</pingback:server>
      <pingback:target>http://blog.j-maxx.net/PermaLink,guid,ddec503d-058c-4c14-8d31-140047924fe1.aspx</pingback:target>
      <dc:creator>Jeff Klawiter</dc:creator>
      <wfw:comment>http://blog.j-maxx.net/CommentView,guid,ddec503d-058c-4c14-8d31-140047924fe1.aspx</wfw:comment>
      <wfw:commentRss>http://blog.j-maxx.net/SyndicationService.asmx/GetEntryCommentsRss?guid=ddec503d-058c-4c14-8d31-140047924fe1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently I have added 4 new projects to SVN for Html Agility Pack. 
</p>
        <ol>
          <li>
            <a href="#HAPLight">HAPLight</a>: a Silverlight implementation 
</li>
          <li>
            <a href="#HAPCompact">HAPCompact</a>: a .NET CF 3.5 version 
</li>
          <li>
            <a href="#DotNet4">HAP for .NET 4.0</a>: taking advantage of DynamicObject. 
</li>
          <li>
            <a href="#UnitTests">Unit Tests</a>
          </li>
        </ol>
        <p>
All of these are works in progress and should be considered in alpha stages thus no
binary releases for them yet. To use them you’ll need to download them from SVN. <a title="http://htmlagilitypack.codeplex.com/SourceControl/list/changesets" href="http://htmlagilitypack.codeplex.com/SourceControl/list/changesets">http://htmlagilitypack.codeplex.com/SourceControl/list/changesets</a></p>
        <a name="HAPLight">
        </a>
        <h3>HAPLight
</h3>
        <p>
Bringing Html Agility Pack to Silverlight was relatively simple, thanks to Silverlight
supporting XPATH and XpathNavigator. There have been two losses so far, HtmlCmdLine
and HtmlWeb. HtmlWeb is a big loss and I don't plan on leaving it that way. Silverlight
requires all web requests to be Asyncronous which HtmlWeb surely is not. So at some
point I will be making a version of HtmlWeb that exposes Asynchronous methods for
downloading pages and returning them as HtmlDocuments. For now you can do this yourself
without much code using WebClient.DownloadstringAsync()
</p>
        <a name="HAPCompact">
        </a>
        <h3>HAPCompact
</h3>
        <p>
Again making a port of Html Agility Pack to .NET CF wasn't too difficult. One of the
biggest issues is .NET CF has no XPathNavigator support. There are no good free implementations
and I don't expect there ever will be. So HAPCompact will need to rely on using LINQ
to Objects. This project needs to be built with Visual Studio 2008. Unfortunately
VS2010 did not include any .NET compact framework support. I've been trying to look
into a way of taking advantage of VS2010's multi-targeting to add back in compilation
support. I have many projects at work that are in .NET CF 2.0 and 3.5.
</p>
        <a name="DotNet4">
        </a>
        <h3>Html Agility Pack for .NET 4.0
</h3>
        <p>
.NET 4.0 shipped with the Dynamic Language Runtime included. C# was updated in turn
to include a dynamic typing system. I thought it would be interesting to see if HAP
could take advantage of these features to dynamically access HtmlNodes and HtmlAttributes. 
This project so far is a partial class that makes HtmlNode inherit from DynamicObject.
This may change later to have it just implement an interface instead. The advantage
of this is you can access first level child nodes and attributes without . Something
like documentElement.Html.Body.Div to get the first &lt;div&gt; on the page.
</p>
        <p>
In C# to use these features you need to indicate the object is dynamic. Simply assigning
the node to a variable typed as dynamic will suffice. I had hoped to use @ for getting
attributes but found that it is completely lost so to access attributes a prefix of
_ is needed. Here are some examples taken from the unit tests:
</p>
        <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:f1fe2ef8-b4a8-49b3-b582-ac5596512217" class="wlWriterEditableSmartContent">
          <pre name="code" class="c#">[Test]
public void TestGetAttribute()
{
    var doc = new HtmlDocument();
    doc.LoadHtml("&lt;html&gt;&lt;body class=\"asdfasd\"&gt;&lt;p&gt;asdf asdf sdf&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;");
    dynamic docElement = doc.DocumentNode;
    var item = docElement.Html.Body._Class;
    Assert.IsNotNull(item);
    Assert.IsInstanceOf&lt;HtmlAttribute&gt;(item);
}

[Test]
public void TestGetMember()
{
    var doc = new HtmlDocument();
    doc.LoadHtml("&lt;html&gt;&lt;body&gt;&lt;p&gt;asdf asdf sdf&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;");
    dynamic docElement = doc.DocumentNode;
    var item = docElement.Html.Body;
    Assert.IsNotNull(item);
    Assert.IsInstanceOf&lt;HtmlNode&gt;(item);
}</pre>
        </div>
        <p>
        </p>
        <p>
        </p>
        <p>
Other ideas I’m having with this is to introduce some kind of domain specific language
for doing more specific accessing like documentElement.Html.Body.First_Div or documentElement.Html.Body.ById_Header
. This will be limited of course due to lack of symbols that could be used. 
</p>
        <a name="UnitTests">
        </a>
        <h3>Unit Tests
</h3>
        <p>
I’ve begun adding Unit Tests to Html Agility Pack. This will be a long process to
even approach a good code coverage percentage. There is quite a bit of code in the
library and some of it could use a good refactoring. So as I’m writing unit tests
I may be doing some refactoring as well. Along with this may come some introductions
of breaking changes with some of the methods or properties within the API. Thus this
next version may be 2.0.
</p>
        <img width="0" height="0" src="http://blog.j-maxx.net/aggbug.ashx?id=ddec503d-058c-4c14-8d31-140047924fe1" />
      </body>
      <title>New Html Agility Pack Versions and Features</title>
      <guid isPermaLink="false">http://blog.j-maxx.net/PermaLink,guid,ddec503d-058c-4c14-8d31-140047924fe1.aspx</guid>
      <link>http://blog.j-maxx.net/2010/06/06/NewHtmlAgilityPackVersionsAndFeatures.aspx</link>
      <pubDate>Sun, 06 Jun 2010 00:17:49 GMT</pubDate>
      <description>&lt;p&gt;
Recently I have added 4 new projects to SVN for Html Agility Pack. 
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;a href="#HAPLight"&gt;HAPLight&lt;/a&gt;: a Silverlight implementation 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="#HAPCompact"&gt;HAPCompact&lt;/a&gt;: a .NET CF 3.5 version 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="#DotNet4"&gt;HAP for .NET 4.0&lt;/a&gt;: taking advantage of DynamicObject. 
&lt;/li&gt;
&lt;li&gt;
&lt;a href="#UnitTests"&gt;Unit Tests&lt;/a&gt; 
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
All of these are works in progress and should be considered in alpha stages thus no
binary releases for them yet. To use them you’ll need to download them from SVN. &lt;a title="http://htmlagilitypack.codeplex.com/SourceControl/list/changesets" href="http://htmlagilitypack.codeplex.com/SourceControl/list/changesets"&gt;http://htmlagilitypack.codeplex.com/SourceControl/list/changesets&lt;/a&gt;
&lt;/p&gt;
&lt;a name="HAPLight"&gt;&lt;/a&gt; 
&lt;h3&gt;HAPLight
&lt;/h3&gt;
&lt;p&gt;
Bringing Html Agility Pack to Silverlight was relatively simple, thanks to Silverlight
supporting XPATH and XpathNavigator. There have been two losses so far, HtmlCmdLine
and HtmlWeb. HtmlWeb is a big loss and I don't plan on leaving it that way. Silverlight
requires all web requests to be Asyncronous which HtmlWeb surely is not. So at some
point I will be making a version of HtmlWeb that exposes Asynchronous methods for
downloading pages and returning them as HtmlDocuments. For now you can do this yourself
without much code using WebClient.DownloadstringAsync()
&lt;/p&gt;
&lt;a name="HAPCompact"&gt;&lt;/a&gt; 
&lt;h3&gt;HAPCompact
&lt;/h3&gt;
&lt;p&gt;
Again making a port of Html Agility Pack to .NET CF wasn't too difficult. One of the
biggest issues is .NET CF has no XPathNavigator support. There are no good free implementations
and I don't expect there ever will be. So HAPCompact will need to rely on using LINQ
to Objects. This project needs to be built with Visual Studio 2008. Unfortunately
VS2010 did not include any .NET compact framework support. I've been trying to look
into a way of taking advantage of VS2010's multi-targeting to add back in compilation
support. I have many projects at work that are in .NET CF 2.0 and 3.5.
&lt;/p&gt;
&lt;a name="DotNet4"&gt;&lt;/a&gt; 
&lt;h3&gt;Html Agility Pack for .NET 4.0
&lt;/h3&gt;
&lt;p&gt;
.NET 4.0 shipped with the Dynamic Language Runtime included. C# was updated in turn
to include a dynamic typing system. I thought it would be interesting to see if HAP
could take advantage of these features to dynamically access HtmlNodes and HtmlAttributes.&amp;#160;
This project so far is a partial class that makes HtmlNode inherit from DynamicObject.
This may change later to have it just implement an interface instead. The advantage
of this is you can access first level child nodes and attributes without . Something
like documentElement.Html.Body.Div to get the first &amp;lt;div&amp;gt; on the page.
&lt;/p&gt;
&lt;p&gt;
In C# to use these features you need to indicate the object is dynamic. Simply assigning
the node to a variable typed as dynamic will suffice. I had hoped to use @ for getting
attributes but found that it is completely lost so to access attributes a prefix of
_ is needed. Here are some examples taken from the unit tests:
&lt;/p&gt;
&lt;div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:812469c5-0cb0-4c63-8c15-c81123a09de7:f1fe2ef8-b4a8-49b3-b582-ac5596512217" class="wlWriterEditableSmartContent"&gt;&lt;pre name="code" class="c#"&gt;[Test]
public void TestGetAttribute()
{
    var doc = new HtmlDocument();
    doc.LoadHtml("&amp;lt;html&amp;gt;&amp;lt;body class=\"asdfasd\"&amp;gt;&amp;lt;p&amp;gt;asdf asdf sdf&amp;lt;/p&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;");
    dynamic docElement = doc.DocumentNode;
    var item = docElement.Html.Body._Class;
    Assert.IsNotNull(item);
    Assert.IsInstanceOf&amp;lt;HtmlAttribute&amp;gt;(item);
}

[Test]
public void TestGetMember()
{
    var doc = new HtmlDocument();
    doc.LoadHtml("&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;&amp;lt;p&amp;gt;asdf asdf sdf&amp;lt;/p&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;");
    dynamic docElement = doc.DocumentNode;
    var item = docElement.Html.Body;
    Assert.IsNotNull(item);
    Assert.IsInstanceOf&amp;lt;HtmlNode&amp;gt;(item);
}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Other ideas I’m having with this is to introduce some kind of domain specific language
for doing more specific accessing like documentElement.Html.Body.First_Div or documentElement.Html.Body.ById_Header
. This will be limited of course due to lack of symbols that could be used. 
&lt;/p&gt;
&lt;a name="UnitTests"&gt;&lt;/a&gt; 
&lt;h3&gt;Unit Tests
&lt;/h3&gt;
&lt;p&gt;
I’ve begun adding Unit Tests to Html Agility Pack. This will be a long process to
even approach a good code coverage percentage. There is quite a bit of code in the
library and some of it could use a good refactoring. So as I’m writing unit tests
I may be doing some refactoring as well. Along with this may come some introductions
of breaking changes with some of the methods or properties within the API. Thus this
next version may be 2.0.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://blog.j-maxx.net/aggbug.ashx?id=ddec503d-058c-4c14-8d31-140047924fe1" /&gt;</description>
      <comments>http://blog.j-maxx.net/CommentView,guid,ddec503d-058c-4c14-8d31-140047924fe1.aspx</comments>
      <category>C# 4.0</category>
      <category>Html Agility Pack</category>
      <category>Silverlight</category>
    </item>
  </channel>
</rss>