The xos module implements an xml and html writer. The xos module extends the tos module with extra words, so the xos words work on tos variables. The module translates the normal entity references: <, >, ", & and '. All other entity references should be written with the word xos-write-raw-text. Note: balancing of start and end tags is not checked, so the module can also be used to write html output.
include ffl/xos.fs \ Example 1: Write xml output \ Create the xml output stream tos-create xos1 s" encoding" s" ISO-8859-1" s" version" s" 1.0" 2 xos1 xos-write-start-xml s" menu of the day " xos1 xos-write-comment 0 s" menu" xos1 xos-write-start-tag 0 s" food" xos1 xos-write-start-tag 0 s" name" xos1 xos-write-start-tag s" Breakfast" xos1 xos-write-text s" name" xos1 xos-write-end-tag 0 s" description" xos1 xos-write-start-tag s" two eggs & bacon or sausage & toast & hash browns" xos1 xos-write-text s" description" xos1 xos-write-end-tag 0 s" price" xos1 xos-write-start-tag s" $6.95" xos1 xos-write-text s" price" xos1 xos-write-end-tag s" cholesterol" s" yes" 1 s" health" xos1 xos-write-empty-element s" food" xos1 xos-write-end-tag s" menu" xos1 xos-write-end-tag xos1 str-get type cr \ Type the xml info \ Example 2: Write html output xos1 tos-rewrite \ Clean the output stream nil 0 s" -//W3C//DTD HTML 4.0 Transitional//EN" nil 0 s" HTML" xos1 xos-write-public-dtd 0 s" HTML" xos1 xos-write-start-tag 0 s" HEAD" xos1 xos-write-start-tag 0 s" TITLE" xos1 xos-write-start-tag s" HTML example" xos1 xos-write-text s" TITLE" xos1 xos-write-end-tag 0 s" BODY" xos1 xos-write-start-tag 0 s" H1" xos1 xos-write-start-tag s" 'Welcome'" xos1 xos-write-text \ Translate ' to ' s" H1" xos1 xos-write-end-tag s" comment " xos1 xos-write-comment s" align" s" center" 1 s" DIV" xos1 xos-write-start-tag \ = <DIV align="center"> s" Test" xos1 xos-write-text s" DIV" xos1 xos-write-end-tag s" BODY" xos1 xos-write-end-tag s" HTML" xos1 xos-write-end-tag xos1 str-get type cr