Paste: xml syntax example
Author: | slava |
Mode: | factor |
Date: | Tue, 29 Sep 2009 02:36:11 |
Plain Text |
USING: xml.syntax xml.writer locals sequences ;
TUPLE: person name age record ;
CONSTANT: friends {
T{ person
{ name "George" }
{ age 25 }
{ record { "Posession paraphenalia" "Posession narcotics" "Break and enter" } }
}
T{ person
{ name "Derek Ray" }
{ age 31 }
{ record { "Armed robbery" "Fraud" "Rape" } }
}
T{ person
{ name "Johnny" }
{ age 17 }
{ record { "Truancy" "First-degree murder" } }
}
}
: render-record ( list -- xml )
[ [XML <li><-></li> XML] ] map [XML <ul><-></ul> XML] ;
:: render-person ( name age record -- xml )
[XML
<tr>
<td><-name-></td>
<td><-age-></td>
<td><-record-></td>
</tr>
XML] ;
: render-report ( people -- xml )
<XML
<html>
<body>
<table>
<tr><th>Name</th><th>Age</th><th>Rap sheet</th></tr>
<->
</table>
</body>
</html>
XML> ;
: do-stuff ( -- )
friends
[ [ name>> ] [ age>> ] [ record>> render-record ] tri render-person ] map
render-report
pprint-xml ;
New Annotation