TUPLE: comment { text string } ;
C: <comment> comment
+TUPLE: cdata { text string } ;
+C: <cdata> cdata
+
TUPLE: directive ;
TUPLE: element-decl < directive
C: <unescaped> unescaped
UNION: xml-data
- tag comment string directive instruction unescaped ;
+ tag comment cdata string directive instruction unescaped ;
TUPLE: xml-chunk seq ;
C: <xml-chunk> xml-chunk
[ "?>" take-string append <instruction> ]
} cond ;
-: take-cdata ( -- string )
+: take-cdata ( -- cdata )
depth get zero? [ bad-cdata ] when
- "[CDATA[" expect "]]>" take-string ;
+ "[CDATA[" expect "]]>" take-string <cdata> ;
DEFER: make-tag ! Is this unavoidable?
<rss version=\"2.0\">
<channel>
<item>
- <description>Python has a n class property in [&#8230;]</description>
+ <description><![CDATA[Python has a n class property in […]]]></description>
</item>
</channel>
</rss>"
dup dup "y" attr "z" set-attr
T{ name { space "blah" } { main "z" } } attr
] unit-test
-[ "foo" ] [ "<boo><![CDATA[foo]]></boo>" string>xml children>string ] unit-test
[ "<!-- B+, B, or B--->" string>xml ] must-fail
[ ] [ "<?xml version='1.0'?><!-- declarations for <head> & <body> --><foo/>" string>xml drop ] unit-test
{ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<foo>\n bar\n</foo>" }
[ "<foo> bar </foo>" string>xml pprint-xml>string ] unit-test
{ "<foo'>" } [ "<foo'>" <unescaped> xml>string ] unit-test
+{ "<![CDATA[<&'\"]]>" } [ "<&'\"" <cdata> xml>string ] unit-test
: test-file ( -- path )
"test.xml" temp-file ;
M: comment write-xml
"<!--" write text>> write "-->" write ;
+M: cdata write-xml
+ "<![CDATA[" write text>> write "]]>" write ;
+
: write-decl ( decl name quot: ( decl -- slot ) -- )
"<!" write swap write bl
[ name>> write bl ]