XML/Output: Difference between revisions

From Rosetta Code
< XML
Content added Content deleted
(Moved output to the right place)
m (Alphabetized, highlighting, lots of extra spaces)
Line 1: Line 1:
{{task}}Given the list of names and the below template, generate an XML document.
{{task}}

Given the list of names and the below template, generate an XML document.


<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|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}}==
<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 = ()
</pre>
</lang>
=={{header|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>

Revision as of 18:09, 17 February 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>

OCaml

<lang ocaml>

  1. #directory "+site-lib/xml-light" (* or maybe just "+xml-light" *) ;;
  1. #load "xml-light.cma" ;;
  1. 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>