Module Rss
module Rss: sig .. end
Types
type date = Netdate.t
val string_of_date : ?fmt:string -> date -> string
Format a date/time record as a string according to the format
string fmt.
fmt : The format string. It consists of zero or more
conversion specifications and ordinary characters. All ordinary
characters are kept as such in the final string. A conversion
specification consists of the '%' character and one other
character. See Netdate.format_to for more details.
Default: "%d %b %Y".
type email = string
can be, for example: foo@bar.com (Mr Foo Bar)
type pics_rating = string
type skip_hours = int list
0 .. 23
type skip_days = int list
0 is Sunday, 1 is Monday, ...
type url = Neturl.url
type category = {
|
cat_name : string; |
|
cat_domain : url option; |
}
type image = {
|
image_url : url; |
|
image_title : string; |
|
image_link : url; |
|
image_height : int option; |
|
image_width : int option; |
|
image_desc : string option; |
}
type text_input = {
|
ti_title : string; |
|
ti_desc : string; |
|
ti_name : string; |
|
ti_link : url; |
}
type enclosure = {
|
encl_url : url; |
|
encl_length : int; |
|
encl_type : string; |
}
type guid =
| |
Guid_permalink of url |
| |
Guid_name of string |
type source = {
|
src_name : string; |
|
src_url : url; |
}
type cloud = {
|
cloud_domain : string; |
|
cloud_port : int; |
|
cloud_path : string; |
|
cloud_register_procedure : string; |
|
cloud_protocol : string; |
}
type 'a item_t = {
|
item_title : string option; |
|
item_link : url option; |
|
item_desc : string option; |
|
item_pubdate : date option; |
|
item_author : email option; |
|
item_categories : category list; |
|
: url option; |
|
item_enclosure : enclosure option; |
|
item_guid : guid option; |
|
item_source : source option; |
|
item_data : 'a option; |
}
An item may represent a "story". Its description is a synopsis of
the story (or sometimes the full story), and the link points to
the full story.
type namespace = string * string
A namespace is a pair (name, url).
type ('a, 'b) channel_t = {
|
ch_title : string; |
|
ch_link : url; |
|
ch_desc : string; |
|
ch_language : string option; |
|
ch_copyright : string option; |
|
ch_managing_editor : email option; |
|
ch_webmaster : email option; |
|
ch_pubdate : date option; |
|
ch_last_build_date : date option; |
|
ch_categories : category list; |
|
ch_generator : string option; |
|
ch_cloud : cloud option; |
|
ch_docs : url option; |
|
ch_ttl : int option; |
|
ch_image : image option; |
|
ch_rating : pics_rating option; |
|
ch_text_input : text_input option; |
|
ch_skip_hours : skip_hours option; |
|
ch_skip_days : skip_days option; |
|
ch_items : 'b item_t list; |
|
ch_data : 'a option; |
|
ch_namespaces : namespace list; |
}
type item = unit item_t
type channel = (unit, unit) channel_t
Building items and channels
val item : ?title:string ->
?link:url ->
?desc:string ->
?pubdate:date ->
?author:email ->
?cats:category list ->
?comments:url ->
?encl:enclosure ->
?guid:guid -> ?source:source -> ?data:'a -> unit -> 'a item_t
item() creates a new item with all fields set to None. Use the
optional parameters to set fields.
val channel : title:string ->
link:url ->
desc:string ->
?language:string ->
?copyright:string ->
?managing_editor:email ->
?webmaster:email ->
?pubdate:date ->
?last_build_date:date ->
?cats:category list ->
?generator:string ->
?cloud:cloud ->
?docs:url ->
?ttl:int ->
?image:image ->
?rating:pics_rating ->
?text_input:text_input ->
?skip_hours:skip_hours ->
?skip_days:skip_days ->
?data:'a ->
?namespaces:namespace list ->
'b item_t list -> ('a, 'b) channel_t
channel items creates a new channel containing items. Other
fields are set to None unless the corresponding optional
parameter is used.
val compare_item : ?comp_data:('a -> 'a -> int) -> 'a item_t -> 'a item_t -> int
val copy_item : 'a item_t -> 'a item_t
val copy_channel : ('a, 'b) channel_t -> ('a, 'b) channel_t
Manipulating channels
val keep_n_items : int -> ('a, 'b) channel_t -> ('a, 'b) channel_t
keep_n_items n ch returns a copy of the channel, keeping only
n items maximum.
val sort_items_by_date : 'a item_t list -> 'a item_t list
Sort items by date, older last.
val merge_channels : ('a, 'b) channel_t -> ('a, 'b) channel_t -> ('a, 'b) channel_t
merge_channels c1 c2 merges the given channels in a new channel,
sorting items using
Rss.sort_items_by_date. Channel information are
copied from the first channel
c1.
Reading channels
type xmltree =
| |
E of Xmlm.tag * xmltree list |
| |
D of string |
This represents XML trees. Such XML trees are given to
functions provided to read additional data from RSS channels and items.
val xml_of_source : Xmlm.source -> xmltree
Read an XML tree from a source.
Raises Failure in case of error.
exception Error of string
Use this exception to indicate an error is functions given to make_opts used
to read additional data from prefixed XML nodes.
type ('a, 'b) opts
Options used when reading source.
val make_opts : ?schemes:(string, Neturl.url_syntax) Hashtbl.t ->
?base_syntax:Neturl.url_syntax ->
?read_channel_data:(xmltree list -> 'a option) ->
?read_item_data:(xmltree list -> 'b option) -> unit -> ('a, 'b) opts
See Neturl documentation for schemes and base_syntax options.
They are used to parse URLs.
read_channel_data : provides a way to read additional information from the
subnodes of the channels. All these subnodes are prefixed by an expanded namespace.
read_item_data : is the equivalent of read_channel_data parameter but
is called of each item with its prefixed subnodes.
val default_opts : (unit, unit) opts
val channel_t_of_file : ('a, 'b) opts -> string -> ('a, 'b) channel_t * string list
channel_[t_]of_X returns the parsed channel and a list of encountered errors.
Note that only namespaces declared in the root not of the XML tree are added to ch_namespaces field.
Raises Failure if the channel could not be parsed.
val channel_t_of_string : ('a, 'b) opts -> string -> ('a, 'b) channel_t * string list
val channel_t_of_channel : ('a, 'b) opts ->
Pervasives.in_channel -> ('a, 'b) channel_t * string list
val channel_t_of_xmls : ('a, 'b) opts -> xmltree list -> ('a, 'b) channel_t * string list
Read a channel from XML trees. These trees correspond to nodes under the "channel" XML node
of a reguler RSS document.
val channel_of_file : string -> channel * string list
val channel_of_string : string -> channel * string list
val channel_of_channel : Pervasives.in_channel -> channel * string list
Writing channels
type 'a data_printer = 'a -> xmltree list
val print_channel : ?channel_data_printer:'a data_printer ->
?item_data_printer:'b data_printer ->
?indent:int ->
?date_fmt:string ->
?encoding:string -> Format.formatter -> ('a, 'b) channel_t -> unit
val print_file : ?channel_data_printer:'a data_printer ->
?item_data_printer:'b data_printer ->
?indent:int ->
?date_fmt:string ->
?encoding:string -> string -> ('a, 'b) channel_t -> unit