: <contained-tag> ( name attrs -- tag )
f <tag> ;
-PREDICATE: contained-tag < tag children>> empty? ;
-PREDICATE: open-tag < tag children>> empty? not ;
+PREDICATE: contained-tag < tag children>> >boolean not ;
+PREDICATE: open-tag < tag children>> >boolean ;
TUPLE: unescaped string ;
C: <unescaped> unescaped
$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
-"USING: splitting xml.writer xml.syntax ;
+"USING: sequences splitting xml.writer xml.syntax ;
\"one two three\" \" \" split
[ [XML <item><-></item> XML] ] map
<XML <doc><-></doc> XML> pprint-xml"
</doc>" }
"Here is an example of the locals version:"
{ $example
-"USING: locals urls xml.syntax xml.writer ;
+"USING: kernel locals urls xml.syntax xml.writer ;
[let
3 :> number
f :> false
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<x number=\"3\" url=\"http://factorcode.org/\" string=\"hello\" word=\"drop\"/>" }
"XML interpolation can also be used, in conjunction with " { $vocab-link "inverse" } " in pattern matching. For example:"
-{ $example "USING: xml.syntax inverse ;
+{ $unchecked-example "USING: xml.syntax inverse ;
: dispatch ( xml -- string )
{
{ [ [XML <a><-></a> XML] ] [ \"a\" prepend ] }
{ "a" "c" { "a" "c" f } } [
"<?xml version='1.0'?><x><-a-><b val=<-c->/><-></x>"
string>doc
- [ second var>> ]
- [ fourth "val" attr var>> ]
+ [ first var>> ]
+ [ second "val" attr var>> ]
[ extract-variables ] tri
] unit-test
] unit-test
{ "<test name=\"bob\"/>" } [
- "test" { { "name" "bob" } } { } <tag> xml>string
+ "test" { { "name" "bob" } } <contained-tag> xml>string
] unit-test
combinators.short-circuit io io.encodings.binary
io.encodings.utf8 io.files io.streams.byte-array
io.streams.string kernel namespaces sequences splitting strings
-xml.autoencoding xml.data xml.elements xml.errors xml.name
-xml.state xml.tokenize ;
+vectors xml.autoencoding xml.data xml.elements xml.errors
+xml.name xml.state xml.tokenize ;
IN: xml
<PRIVATE
M: object process add-child ;
+M: string process [ add-child ] unless-empty ;
+
M: prolog process
xml-stack get
{ V{ { f V{ "" } } } V{ { f V{ } } } } member?
} case ;
: read-xml-chunk ( stream -- seq )
- [ check ] 1 read-seq <xml-chunk> ;
+ [ check ] 1 read-seq dup empty? [ "" suffix! ] when <xml-chunk> ;
: string>xml ( string -- xml )
<string-reader> read-xml ;