factor/basis/xml/literals/literals-docs.factor

61 lines
2.9 KiB
Factor
Raw Normal View History

2009-01-30 12:29:30 -05:00
USING: help.markup help.syntax present multiline xml.data ;
IN: xml.literals
2009-01-26 17:11:30 -05:00
2009-01-30 12:29:30 -05:00
ABOUT: "xml.literals"
2009-01-26 17:11:30 -05:00
2009-01-30 12:29:30 -05:00
ARTICLE: "xml.literals" "XML literals"
"The " { $vocab-link "xml.literals" } " vocabulary provides a convenient syntax for generating XML documents and chunks. It defines the following parsing words:"
2009-01-26 17:11:30 -05:00
{ $subsection POSTPONE: <XML }
{ $subsection POSTPONE: [XML }
2009-01-30 12:29:30 -05:00
"These can be used for creating an XML literal, which can be used with variables or a fry-like syntax to interpolate data into XML."
{ $subsection { "xml.literals" "interpolation" } } ;
2009-01-26 17:11:30 -05:00
HELP: <XML
{ $syntax "<XML <?xml version=\"1.0\"?><document>...</document> XML>" }
2009-01-30 12:29:30 -05:00
{ $description "This gives syntax for literal XML documents. When evaluated, there is an XML document (" { $link xml } ") on the stack. It can be used for interpolation as well, if interpolation slots are used. For more information about XML interpolation, see " { $link { "xml.literals" "interpolation" } } "." } ;
2009-01-26 17:11:30 -05:00
HELP: [XML
{ $syntax "[XML foo <x>...</x> bar <y>...</y> baz XML]" }
2009-01-30 12:29:30 -05:00
{ $description "This gives syntax for literal XML documents. When evaluated, there is an XML chunk (" { $link xml-chunk } ") on the stack. For more information about XML interpolation, see " { $link { "xml.literals" "interpolation" } } "." } ;
2009-01-26 17:11:30 -05:00
2009-01-30 12:29:30 -05:00
ARTICLE: { "xml.literals" "interpolation" } "XML interpolation syntax"
2009-01-26 17:11:30 -05:00
"XML interpolation has two forms for each of the words " { $link POSTPONE: <XML } " and " { $link POSTPONE: [XML } ": a fry-like form and a locals form. To splice locals in, use the syntax " { $snippet "<-variable->" } ". To splice something in from the stack, in the style of " { $vocab-link "fry" } ", use the syntax " { $snippet "<->" } ". An XML interpolation form may only use one of these styles."
$nl
"These forms can be used where a tag might go, as in " { $snippet "[XML <foo><-></foo> XML]" } " or where an attribute might go, as in " { $snippet "[XML <foo bar=<->/> XML]" } ". When an attribute is spliced in, it is not included if the value is " { $snippet "f" } " and if the value is not a string, the value is put through " { $link present } ". Here is an example of the fry style of XML interpolation:"
{ $example
2009-01-30 12:29:30 -05:00
{" USING: splitting sequences xml.writer xml.literals ;
2009-01-27 16:10:56 -05:00
"one two three" " " split
2009-01-26 17:11:30 -05:00
[ [XML <item><-></item> XML] ] map
2009-01-27 16:10:56 -05:00
<XML <doc><-></doc> XML> pprint-xml"}
{" <?xml version="1.0" encoding="UTF-8"?>
2009-01-26 17:11:30 -05:00
<doc>
<item>
one
</item>
<item>
two
</item>
<item>
three
</item>
2009-01-27 16:10:56 -05:00
</doc>"} }
2009-01-26 17:11:30 -05:00
"Here is an example of the locals version:"
{ $example
2009-01-30 12:29:30 -05:00
{" USING: locals urls xml.literals xml.writer ;
2009-01-27 16:10:56 -05:00
[let |
2009-01-26 17:11:30 -05:00
number [ 3 ]
false [ f ]
url [ URL" http://factorcode.org/" ]
string [ "hello" ]
word [ \ drop ] |
<XML
<x
number=<-number->
false=<-false->
url=<-url->
string=<-string->
word=<-word-> />
2009-01-27 16:10:56 -05:00
XML> pprint-xml ] "}
{" <?xml version="1.0" encoding="UTF-8"?>
<x number="3" url="http://factorcode.org/" string="hello" word="drop"/>"} } ;