XML/Output: Difference between revisions
< XML
Content added Content deleted
(Moved output to the right place) |
m (Alphabetized, highlighting, lots of extra spaces) |
||
Line 1: | Line 1: | ||
⚫ | |||
{{task}} |
|||
⚫ | |||
<Students> |
<Students> |
||
<Student Name="XXX" /> |
<Student Name="XXX" /> |
||
</Students> |
</Students> |
||
Sample Output |
Sample Output |
||
Line 17: | Line 14: | ||
<Student Name="Emily" /> |
<Student Name="Emily" /> |
||
</Students> |
</Students> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=={{header|OCaml}}== |
=={{header|OCaml}}== |
||
<lang ocaml> |
|||
<pre> |
|||
# #directory "+site-lib/xml-light" (* or maybe just "+xml-light" *) ;; |
# #directory "+site-lib/xml-light" (* or maybe just "+xml-light" *) ;; |
||
Line 48: | Line 36: | ||
</Students> |
</Students> |
||
- : unit = () |
- : unit = () |
||
</ |
</lang> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ |
Revision as of 18:09, 17 February 2009
XML/Output
You are encouraged to solve this task according to the task description, using any language you may know.
You are encouraged to solve this task according to the task description, using any language you may know.
Given the list of names and the below template, generate an XML document.
<Students> <Student Name="XXX" /> </Students>
Sample Output
<Students> <Student Name="April" /> <Student Name="Bob" /> <Student Name="Chad" /> <Student Name="Dave" /> <Student Name="Emily" /> </Students>
OCaml
<lang ocaml>
- #directory "+site-lib/xml-light" (* or maybe just "+xml-light" *) ;;
- #load "xml-light.cma" ;;
- let students = ["April"; "Bob"; "Chad"; "Dave"; "Emily"] in
let tags_students = List.map (fun name -> Xml.Element ("Student", [("Name", name)], []) ) students in print_endline ( Xml.to_string_fmt (Xml.Element ("Students", [], tags_students))) ;;
<Students>
<Student Name="April"/> <Student Name="Bob"/> <Student Name="Chad"/> <Student Name="Dave"/> <Student Name="Emily"/>
</Students> - : unit = () </lang>
Visual Basic .NET
<lang vbnet>Dim names As String() = New String() {"April", "Bob", "Chad", "Dave", "Emily"}
Dim xml = <Students>
<%= From s In names Select <Student Name=<%= s %>/> %> </Students>
Console.WriteLine(xml)</lang>