XML/Input: Difference between revisions

Content added Content deleted
No edit summary
(Using lang tags now. J example seems incompatible. I'll get in touch with the Geshi folks.)
Line 3: Line 3:
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]].
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>
<lang xml><Students>
<Student Name="April" />
<Student Name="April" />
<Student Name="Bob" />
<Student Name="Bob" />
<Student Name="Chad" />
<Student Name="Chad" />
<Student Name="Dave" />
<Student Name="Dave" />
<Student Name="Emily" />
<Student Name="Emily" />
</Students>
</Students></lang>


Expected Output
Expected Output
Line 100: Line 100:
J's system includes several XML processing libraries. This task is probably best addressed using XPath (this is the type of problem XPath was designed to solve), but the task description implicitly discourages that method. So we can use the SAX library instead:
J's system includes several XML processing libraries. This task is probably best addressed using XPath (this is the type of problem XPath was designed to solve), but the task description implicitly discourages that method. So we can use the SAX library instead:


load'xml/sax'
<lang j> load'xml/sax'
saxclass 'Students'
saxclass 'Students'
Line 106: Line 106:
cocurrent'base'
cocurrent'base'
process_Students_ XML
process_Students_ XML</lang>
April
April
Bob
Bob
Line 114: Line 114:


and the definition of <tt>XML</tt>:
and the definition of <tt>XML</tt>:
XML =: noun define
<lang j> XML =: noun define
<Students>
<Students>
<Student Name="April" />
<Student Name="April" />
Line 122: Line 122:
<Student Name="Emily" />
<Student Name="Emily" />
</Students>
</Students>
)
)</lang>


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