Insights and discoveries
from deep in the weeds
Outsharked

Wednesday, June 13, 2012

CsQuery 1.1 Released, and available on NuGet

CsQuery 1.1 has been released. This is a major milestone; the library now implements every CSS2 and CSS3 selector.

Additionally, CsQuery is now available on NuGet:

    PM> Install-Package CsQuery

There are two important API changes from prior versions.

  • The IDomElement.NodeName method now returns its results in uppercase. Formerly, results were returned in lowercase. So any code that tests for node type with a string will break, e.g.
        CQ results = dom["div, span"];
        foreach (IDomObject item in results) {
    //        if (item.NodeName=="div") {
            if (item.NodeName=="DIV") {
                ...
            }
        }
    

    I realize this can easily break code in ways that the compiler cannot detect and apologize for this; but this is important to be consistent with the browser DOM. This was a long time coming.

  • The CsQuery.Server object has been removed. Methods for loading a DOM from an http server have been replaced with static methods on the CQ object:
        // synchronous
        var doc = CQ.CreateFromUrl("http://www.jquery.com");
      
        // asynchronous with delegates to call upon completion
        CQ.CreateFromUrlAsync("http://www.jquery.com", responseSuccess => {
            Dom = response.Dom;        
        }, responseFail => {
            ..
        });
    
        // asynchronous using IPromise (similar to C#5 Task)
        var promise = CQ.CreateFromUrlAsync("http://www.jquery.com");
        var promise2 = CQ.CreateFromUrlAsync("http://www.cnn.com");
    
        promise.Then(successDelegate);
        promise2.Then(successDelegate,failDelegate);
    
        When.All(promise,promise2).Then(allFinishedDelegate);
    
    See Creating a new DOM and Promises in the readme for more details.

New Features in 1.1

Implemented all missing CSS pseudoclass selectors:

    :nth-last-of-type(N)              :nth-last-child(N)    
    :nth-of-type(N)                   :only-child
    :only-of-type                     :empty
    :last-of-type                     :first-of-type
Implemented all missing jquery pseudoclass selectors:
    :parent                           :hidden
    :header
  • Added IDomObject.Name property
  • Added IDomObject.Type property

Bug Fixes

  • Don't consider html node a child when targeted by child-targeting selectors (consistent with browser behavior)
  • Fix checkbox lists in Forms.RestorePost
  • Pseudoselectors from a descendant combinator only returning direct descendant matches (e.g., div :empty)
  • Issue #5 - Remove enforcement of unique id attribute when parsing HTML

CsQuery is a complete port of jQuery written in C# for .NET4. For documentation and more information please see the GitHub repository and posts about CsQuery on this blog.

No comments:

Post a Comment