How to resolve the algorithm XML/Output step by step in the OCaml programming language
How to resolve the algorithm XML/Output step by step in the OCaml programming language
Table of Contents
Problem Statement
Create a function that takes a list of character names and a list of corresponding remarks and returns an XML document of
Let's start with the solution:
Step by Step solution about How to resolve the algorithm XML/Output step by step in the OCaml programming language
Source code in the ocaml programming language
# #directory "+xml-light" (* or maybe "+site-lib/xml-light" *) ;;
# #load "xml-light.cma" ;;
# let data = [
("April", "Bubbly: I'm > Tam and <= Emily");
("Tam O'Shanter", "Burns: \"When chapman billies leave the street ...\"");
("Emily", "Short & shrift");
] in
let tags =
List.map (fun (name, comment) ->
Xml.Element ("Character", [("name", name)], [(Xml.PCData comment)])
) data
in
print_endline (
Xml.to_string_fmt (Xml.Element ("CharacterRemarks", [], tags)))
;;
<CharacterRemarks>
<Character name="April">Bubbly: I'm > Tam and <= Emily</Character>
<Character name="Tam O'Shanter">Burns: "When chapman billies leave the street ..."</Character>
<Character name="Emily">Short & shrift</Character>
</CharacterRemarks>
- : unit = ()
#directory "+xmlm"
#load "xmlm.cmo"
open Xmlm
let datas = [
("April", "Bubbly: I'm > Tam and <= Emily");
("Tam O'Shanter", "Burns: \"When chapman billies leave the street ...\"");
("Emily", "Short & shrift");
]
let xo = make_output (`Channel stdout)
let () =
output xo (`Dtd None);
output xo (`El_start (("", "CharacterRemarks"), []));
List.iter (fun (name, content) ->
output xo (`El_start (("", "Character"), [(("", "name"), name)]));
output xo (`Data content);
output xo (`El_end);
) datas;
output xo (`El_end);
print_newline()
You may also check:How to resolve the algorithm Optional parameters step by step in the TIScript programming language
You may also check:How to resolve the algorithm Loops/With multiple ranges step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm String matching step by step in the Visual Basic programming language
You may also check:How to resolve the algorithm Last letter-first letter step by step in the Julia programming language
You may also check:How to resolve the algorithm Empty program step by step in the LC3 Assembly programming language