Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
22
Task/XML-Input/8th/xml-input.8th
Normal file
22
Task/XML-Input/8th/xml-input.8th
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
\ Load the XML text into the var 'x':
|
||||
quote *
|
||||
<Students>
|
||||
<Student Name="April" Gender="F" DateOfBirth="1989-01-02" />
|
||||
<Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" />
|
||||
<Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" />
|
||||
<Student Name="Dave" Gender="M" DateOfBirth="1992-07-08">
|
||||
<Pet Type="dog" Name="Rover" />
|
||||
</Student>
|
||||
<Student DateOfBirth="1993-09-10" Gender="F" Name="Émily" />
|
||||
</Students>
|
||||
* xml:parse var, x
|
||||
|
||||
\ print only xml nodes which have a tag of 'Student' and whose attributes are not empty
|
||||
: .xml \ xml --
|
||||
xml:tag@ "Student" s:cmp if drop ;; then
|
||||
xml:attrs null? if drop ;; then
|
||||
|
||||
"Name" m:@ . cr drop ;
|
||||
|
||||
\ Iterate over the XML document in the var 'x'
|
||||
x @ ' .xml xml:each bye
|
||||
30
Task/XML-Input/Lasso/xml-input-1.lasso
Normal file
30
Task/XML-Input/Lasso/xml-input-1.lasso
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
// makes extracting attribute values easier
|
||||
define xml_attrmap(in::xml_namedNodeMap_attr) => {
|
||||
local(out = map)
|
||||
with attr in #in
|
||||
do #out->insert(#attr->name = #attr->value)
|
||||
return #out
|
||||
}
|
||||
|
||||
local(
|
||||
text = '<Students>
|
||||
<Student Name="April" Gender="F" DateOfBirth="1989-01-02" />
|
||||
<Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" />
|
||||
<Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" />
|
||||
<Student Name="Dave" Gender="M" DateOfBirth="1992-07-08">
|
||||
<Pet Type="dog" Name="Rover" />
|
||||
</Student>
|
||||
<Student DateOfBirth="1993-09-10" Gender="F" Name="Émily" />
|
||||
</Students>
|
||||
',
|
||||
xml = xml(#text)
|
||||
)
|
||||
|
||||
local(
|
||||
students = #xml -> extract('//Student'),
|
||||
names = array
|
||||
)
|
||||
with student in #students do {
|
||||
#names -> insert(xml_attrmap(#student -> attributes) -> find('Name'))
|
||||
}
|
||||
#names -> join('<br />')
|
||||
11
Task/XML-Input/Lasso/xml-input-2.lasso
Normal file
11
Task/XML-Input/Lasso/xml-input-2.lasso
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
// not using XML or Xpath
|
||||
'<hr />'
|
||||
local(
|
||||
regexp = regexp(-find = `<Student.*?Name="(.*?)"`, -input = #text, -ignoreCase),
|
||||
names = array
|
||||
)
|
||||
|
||||
while( #regexp -> find) => {
|
||||
#names -> insert(#regexp -> matchstring(1))
|
||||
}
|
||||
#names -> join('<br />')
|
||||
18
Task/XML-Input/Lingo/xml-input.lingo
Normal file
18
Task/XML-Input/Lingo/xml-input.lingo
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
q = QUOTE
|
||||
r = RETURN
|
||||
xml = "<Students>"&r&\
|
||||
" <Student Name="&q&"April"&q&" Gender="&q&"F"&q&" DateOfBirth="&q&"1989-01-02"&q&" />"&r&\
|
||||
" <Student Name="&q&"Bob"&q&" Gender="&q&"M"&q&" DateOfBirth="&q&"1990-03-04"&q&" />"&r&\
|
||||
" <Student Name="&q&"Chad"&q&" Gender="&q&"M"&q&" DateOfBirth="&q&"1991-05-06"&q&" />"&r&\
|
||||
" <Student Name="&q&"Dave"&q&" Gender="&q&"M"&q&" DateOfBirth="&q&"1992-07-08"&q&">"&r&\
|
||||
" <Pet Type="&q&"dog"&q&" Name="&q&"Rover"&q&" />"&r&\
|
||||
" </Student>"&r&\
|
||||
" <Student DateOfBirth="&q&"1993-09-10"&q&" Gender="&q&"F"&q&" Name="&q&"Émily"&q&" />"&r&\
|
||||
"</Students>"
|
||||
|
||||
parser = xtra("xmlparser").new()
|
||||
parser.parseString(xml)
|
||||
res = parser.makePropList()
|
||||
repeat with c in res.child
|
||||
put c.attributes.name
|
||||
end repeat
|
||||
2
Task/XML-Input/LiveCode/xml-input.livecode
Normal file
2
Task/XML-Input/LiveCode/xml-input.livecode
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
put revXMLCreateTree(fld "FieldXML",true,true,false) into currTree
|
||||
put revXMLAttributeValues(currTree,"Students","Student","Name",return,-1)
|
||||
14
Task/XML-Input/Nim/xml-input.nim
Normal file
14
Task/XML-Input/Nim/xml-input.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import xmlparser, xmltree, streams
|
||||
|
||||
let doc = newStringStream """<Students>
|
||||
<Student Name="April" Gender="F" DateOfBirth="1989-01-02" />
|
||||
<Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" />
|
||||
<Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" />
|
||||
<Student Name="Dave" Gender="M" DateOfBirth="1992-07-08">
|
||||
<Pet Type="dog" Name="Rover" />
|
||||
</Student>
|
||||
<Student DateOfBirth="1993-09-10" Gender="F" Name="Émily" />
|
||||
</Students>"""
|
||||
|
||||
for i in doc.parseXml.findAll "Student":
|
||||
echo i.attr "Name"
|
||||
13
Task/XML-Input/Sidef/xml-input.sidef
Normal file
13
Task/XML-Input/Sidef/xml-input.sidef
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
require('XML::Simple');
|
||||
|
||||
var ref = %S'XML::Simple'.XMLin('<Students>
|
||||
<Student Name="April" Gender="F" DateOfBirth="1989-01-02" />
|
||||
<Student Name="Bob" Gender="M" DateOfBirth="1990-03-04" />
|
||||
<Student Name="Chad" Gender="M" DateOfBirth="1991-05-06" />
|
||||
<Student Name="Dave" Gender="M" DateOfBirth="1992-07-08">
|
||||
<Pet Type="dog" Name="Rover" />
|
||||
</Student>
|
||||
<Student DateOfBirth="1993-09-10" Gender="F" Name="Émily" />
|
||||
</Students>');
|
||||
|
||||
ref{:Student}.each { say _{:Name} };
|
||||
Loading…
Add table
Add a link
Reference in a new issue