Rosetta Code/Count examples: Difference between revisions

(→‎{{header|Java}}: lines too long)
Line 689:
<lang ocaml>open Http_client.Convenience
 
let repl_quote s =
let reg = Str.regexp_string "&#039;" in
(Str.global_replace reg "%27" s)
 
let repl_space s =
let s = String.copy s in
Line 699 ⟶ 700:
done;
(s)
 
let count_ex s =
let pat = Str.regexp_string "=={{header|" in
Line 709 ⟶ 710:
in
aux 0 0
 
let get_child child xml =
 
let child =
List.find
(function Xml.Element (tag,_,_) when tag = child -> true | _ -> false) xml
in
Xml.children child
let () =
let url = "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&\
cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml" in
 
let xml = Xml.parse_string (http_get url) in
 
let total = ref 0 in
at_exit (fun () -> Printf.printf "\n Total: %d\n" !total);
 
let f = function
| Xml.Element ("cm", attrs, _) ->
Line 732 ⟶ 739:
| _ -> ()
in
 
match xml with
| Xml.Element ("api", []_, ch) ->
[Xml.Element (let query = get_child "query", [],ch in
let [Xml.Elementcatmb = get_child ("categorymembers", [], cms)])]) -> List.iter fquery cmsin
List.iter f catmb
| _ -> ()</lang>