XML/Input: Difference between revisions
< XML
Content added Content deleted
(added ocaml) |
No edit summary |
||
Line 18: | Line 18: | ||
Dave |
Dave |
||
Emily |
Emily |
||
=={{header|ActionScript}}== |
|||
<actionscript> |
|||
package |
|||
{ |
|||
import flash.display.Sprite; |
|||
public class Spectrum extends Sprite |
|||
{ |
|||
public function Spectrum() |
|||
{ |
|||
var xml:XML = <Students> |
|||
<Student Name="April" /> |
|||
<Student Name="Bob" /> |
|||
<Student Name="Chad" /> |
|||
<Student Name="Dave" /> |
|||
<Student Name="Emily" /> |
|||
</Students>; |
|||
for each(var node:XML in xml..Student) |
|||
{ |
|||
trace(node.@Name); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
</actionscript> |
|||
=={{header|Visual Basic .NET}}== |
=={{header|Visual Basic .NET}}== |
Revision as of 08:00, 14 January 2009
XML/Input
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 below XML fragment, extract the list of names using whatever means desired. If the only viable method is to use XPath, refer the reader to the task XML_and_XPath.
<Students> <Student Name="April" /> <Student Name="Bob" /> <Student Name="Chad" /> <Student Name="Dave" /> <Student Name="Emily" /> </Students>
Expected Output
April Bob Chad Dave Emily
ActionScript
<actionscript> package {
import flash.display.Sprite;
public class Spectrum extends Sprite { public function Spectrum() { var xml:XML = <Students> <Student Name="April" /> <Student Name="Bob" /> <Student Name="Chad" /> <Student Name="Dave" /> <Student Name="Emily" /> </Students>; for each(var node:XML in xml..Student) { trace(node.@Name); } } }
} </actionscript>
Visual Basic .NET
Dim xml = <Students> <Student Name="April"/> <Student Name="Bob"/> <Student Name="Chad"/> <Student Name="Dave"/> <Student Name="Emily"/> </Students> Dim names = (From node In xml...<Student> Select node.@Name).ToArray For Each name In names Console.WriteLine(name) Next
OCaml
# #directory "+site-lib/xml-light" (* or maybe just "+xml-light" *) ;; # #load "xml-light.cma" ;; # let x = Xml.parse_string " <Students> <Student Name=\"April\" /> <Student Name=\"Bob\" /> <Student Name=\"Chad\" /> <Student Name=\"Dave\" /> <Student Name=\"Emily\" /> </Students>" in Xml.iter (function (Xml.Element ("Student", [("Name", name)], [])) -> print_endline name | _ -> ()) x ;; April Bob Chad Dave Emily - : unit = ()