Rosetta Code/Count examples: Difference between revisions

m
Line 268:
-I +netstring netstring.cma -I +netclient netclient.cma -I +xml-light xml-light.cma countex.ml
 
<lang ocaml>letopen repl_quote s =Http_client.Convenience
 
let title = repl_quote titles in=
let reg = Str.regexp_string "&#039;" in
(Str.global_replace reg "%27" s)
Line 294 ⟶ 296:
cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" in
 
let strxml = Http_client.ConvenienceXml.parse_string (http_get url) in
let xml = Xml.parse_string str in
 
let total = ref 0 in
Line 303 ⟶ 304:
| Xml.Element ("cm", attrs, _) ->
let _title = List.assoc "title" attrs in
let title = repl_quote (repl_space _title) in
let title = repl_quote title in
let url = "http://www.rosettacode.org/w/index.php?title="^ title ^"&action=raw" in
let strn = Http_client.Convenience.count_ex (http_get url) in
let n = count_ex str in
Printf.printf "%s: %d\n%!" _title n;
total := n + !total;