Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/XML-XPath/Rascal/xml-xpath-1.rascal
Normal file
23
Task/XML-XPath/Rascal/xml-xpath-1.rascal
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import lang::xml::DOM;
|
||||
import Prelude;
|
||||
|
||||
public void get_first_item(loc a){
|
||||
D = parseXMLDOM(readFile(a));
|
||||
top-down-break visit(D){
|
||||
case E:element(_,"item",_): return println(xmlPretty(E));
|
||||
};
|
||||
}
|
||||
|
||||
public void print_prices(loc a){
|
||||
D = parseXMLDOM(readFile(a));
|
||||
for(/element(_,"price",[charData(/str p)]) := D)
|
||||
println(p);
|
||||
}
|
||||
|
||||
public list[str] get_names(loc a){
|
||||
D = parseXMLDOM(readFile(a));
|
||||
L = [];
|
||||
for(/element(_,"name",[charData(/str n)]) := D)
|
||||
L += n;
|
||||
return L;
|
||||
}
|
||||
20
Task/XML-XPath/Rascal/xml-xpath-2.rascal
Normal file
20
Task/XML-XPath/Rascal/xml-xpath-2.rascal
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
rascal>get_first_item(|file:///Users/.../Desktop/xmlpath.xml|)
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item stock="12" upc="123456789">
|
||||
<name>Invisibility Cream</name>
|
||||
<price>14.50</price>
|
||||
<description>Makes you invisible</description>
|
||||
</item>
|
||||
|
||||
|
||||
ok
|
||||
|
||||
rascal>print_prices(|file:///Users/.../Desktop/xmlpath.xml|)
|
||||
14.50
|
||||
23.99
|
||||
4.95
|
||||
3.56
|
||||
ok
|
||||
|
||||
rascal>get_names(|file:///Users/.../Desktop/xmlpath.xml|)
|
||||
list[str]: ["Invisibility Cream","Levitation Salve","Blork and Freen Instameal","Grob winglets"]
|
||||
Loading…
Add table
Add a link
Reference in a new issue