Skip to content

Instantly share code, notes, and snippets.

@yawaramin
Created May 24, 2025 03:53
Show Gist options
  • Save yawaramin/2b2813d89c65acbac8a70d05d343d7e5 to your computer and use it in GitHub Desktop.
Save yawaramin/2b2813d89c65acbac8a70d05d343d7e5 to your computer and use it in GitHub Desktop.
Simplified RSS2 decoder in OCaml using the Ezxmlm library
type item = {
title : string;
categories : string list;
link : string;
description : string;
pub_date : string;
}
type channel = {
title : string;
link : string;
description : string;
items : item list;
}
type rss2 = { channels : channel list }
open Ezxmlm
let ( .?[] ) nodes tag = member tag nodes
let ( .??[] ) nodes tag = members tag nodes
let data = function [`Data d] -> d | _ -> assert false
let item xml = {
title = data xml.?["title"];
categories = List.map data xml.??["category"];
link = data xml.?["link"];
description = data xml.?["description"];
pub_date = data xml.?["pubDate"];
}
let channel xml = {
title = data xml.?["title"];
link = data xml.?["link"];
description = data xml.?["description"];
items = List.map item xml.??["item"];
}
let rss2 xml = { channels = List.map channel xml.?["rss"].??["channel"] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment