XML/Output: Difference between revisions

From Rosetta Code
< XML
Content added Content deleted
(added ocaml)
(Moved output to the right place)
Line 7: Line 7:
</Students>
</Students>


=={{header|Visual Basic .NET}}==
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)


Output
Sample Output


<Students>
<Students>
Line 24: Line 17:
<Student Name="Emily" />
<Student Name="Emily" />
</Students>
</Students>

=={{header|Visual Basic .NET}}==
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)



=={{header|OCaml}}==
=={{header|OCaml}}==

Revision as of 17:39, 1 January 2009

Task
XML/Output
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>

Visual Basic .NET

       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)


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 = ()