Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a jQuery-like library written in C#? [closed]

Tags:

jquery

c#

.net

xml

I love jQuery. I am probably going to have some XML parsing and manipulation using C#. It would be a piece of cake doing it in jQuery.

Is there a C# library that implements jQuery's functionality?

like image 707
Hugo Estrada Avatar asked Jul 16 '09 18:07

Hugo Estrada


2 Answers

Linq to XML, for what you want to do.

like image 58
Robert Harvey Avatar answered Oct 06 '22 00:10

Robert Harvey


Old question but new answer. I've recently released version 1.1 of CsQuery, a jQuery port for .NET 4 written in C# that I've been working on for about a year. Also on NuGet as "CsQuery"

The current release implements all CSS2 & CSS3 selectors, all jQuery extensions, and all jQuery DOM manipulation methods. It's got extensive test coverage including all the tests from jQuery and sizzle (the jQuery CSS selection engine). I've also included some performance tests for direct comparisons with Fizzler; for the most part CsQuery dramatically outperforms it. The exception is actually loading the HTML in the first place where Fizzler is faster; I assume this is because fizzler doesn't build an index. You get that time back after your first selection, though.

There's documentation on the github site, but at a basic level it works like this:

Create from a string of HTML

CQ dom = CQ.Create(htmlString);

Load synchronously from the web

CQ dom = CQ.CreateFromUrl("http://www.jquery.com");

Load asynchronously (non-blocking)

CQ.CreateFromUrlAsync("http://www.jquery.com", responseSuccess => {
    Dom = response.Dom;        
}, responseFail => {
    ..
});

Run selectors & do jQuery stuff

var childSpans = dom["div > span"];
childSpans.AddClass("myclass");

the CQ object is like thejQuery object. The property indexer used above is the default method (like $(...).

Output:

string html = dom.Render();
like image 39
Jamie Treworgy Avatar answered Oct 06 '22 01:10

Jamie Treworgy