Surya
Surya

Reputation: 4982

Jquery like selector in Haskell

I am doing some server side html processing in Haskell. Wondering if there is an equivalent of jquery type selector engine implemetation for haskell out there that i could use. Google doesnt yield anything.

Upvotes: 7

Views: 1419

Answers (5)

Hiro
Hiro

Reputation: 505

I made a dom-selector package that supports some css selectors. This works on xml-conduit and html-conduit packages. I expect xml-conduit and html-conduit will be actively developed, since they accompany Yesod, a major web server framework for Haskell.

Upvotes: 1

Vlad the Impala
Vlad the Impala

Reputation: 15872

I'm writing a module to do just this called HandsomeSoup. It uses HXT. I also wrote a complete guide to working with HTML with HXT here.

Upvotes: 0

Don Stewart
Don Stewart

Reputation: 137977

Some possibly relevant packages:

Upvotes: 5

ADEpt
ADEpt

Reputation: 5542

Take a look at the Xtract module from the HaXml. There is a command-line tool of the same name there to test it out.

Upvotes: 1

Anthony
Anthony

Reputation: 7146

The way jQuery's selector engine (roughly) works is by utilizing existing Javascript DOM-selection/manipulation code. No one has created something like this in Haskell to my knowledge, and probably with good reason. It's easy to do with Javascript because of the DOM and existing functionality, but in Haskell, you have neither a big need for it nor is it particularly easy.

As far as writing it yourself, however, you'll just be doing a lot of nasty XML parsing. If you can tidy up the page into XHTML, you can parse it as XML; then, you can select based on if a node has children, if a node has a given attribute, what the element itself is, and so on.

Maybe you're just looking for an XML library then! If this works for you, I'd recommend HaXml. I've only used it twice yet, but I've liked it. Nothing quite like this application, however.

Upvotes: 2

Related Questions