let channel_of_xmls xmls =
let f s =
try
match List.find (find_ele s) xmls with
Element (_,_,[PCData s]) -> s
| Element (_,_,[]) -> ""
| _ -> raise Not_found
with Not_found ->
failwith ("Parse error: no correct "^s)
in
let f_opt s =
try
match List.find (find_ele s) xmls with
Element (_,_,[PCData s]) -> Some s
| _ -> None
with Not_found -> None
in
let pubdate =
match f_opt "pubdate" with
None -> None
| Some s ->
try Some (Rss_date.parse s)
with _ -> None
in
let builddate =
match f_opt "lastbuilddate" with
None -> None
| Some s ->
try Some (Rss_date.parse s)
with _ -> None
in
let ttl =
match f_opt "ttl" with
None -> None
| Some s ->
try Some (int_of_string s)
with _ -> None
in
{ ch_title = f "title" ;
ch_link = f "link" ;
ch_desc = f "description" ;
ch_language = f_opt "language" ;
ch_copyright = f_opt "copyright" ;
ch_managing_editor = f_opt "managingeditor" ;
ch_webmaster = f_opt "webmaster" ;
ch_pubdate = pubdate ;
ch_last_build_date = builddate ;
ch_categories = get_categories xmls ;
ch_generator = f_opt "generator" ;
ch_docs = f_opt "docs" ;
ch_ttl = ttl ;
ch_image = get_image xmls ;
ch_text_input = get_text_input xmls ;
ch_items = items_of_xmls xmls ;
}