write-xml ( xml -- )
Writing XML
Next:xml>string ( xml -- string )


Vocabulary
xml.writer

Inputs and outputs
xmlan XML document


Word description
Prints the contents of an XML document to output-stream.

Notes
This does not preserve what type of quotes were used or what data was omitted from version declaration, as that information isn't present in the XML data representation. The whitespace in the text nodes of the original document is preserved.

See also
xml>string, pprint-xml, pprint-xml>string

Definition
IN: xml.writer

GENERIC: write-xml ( xml -- )


Methods
USING: accessors xml.data xml.writer xml.writer.private ;

M: attlist-decl write-xml "ATTLIST" [ att-defs>> ] write-decl ;


USING: accessors io xml.data xml.writer ;

M: comment write-xml "<!--" write text>> write "-->" write ;


USING: io xml.data xml.writer xml.writer.private ;

M: contained-tag write-xml write-tag "/>" write ;


USING: accessors io xml.data xml.writer ;

M: directive write-xml "<!" write text>> write 62 write1 nl ;


USING: accessors io kernel xml.data xml.writer
xml.writer.private ;

M: doctype-decl write-xml
?indent "<!DOCTYPE " write
[ name>> write bl ]
[ external-id>> [ write-xml bl ] when* ]
[ internal-subset>> write-internal-subset ">" write ] tri ;


USING: accessors xml.data xml.writer xml.writer.private ;

M: element-decl write-xml
"ELEMENT" [ content-spec>> ] write-decl ;


USING: accessors io kernel namespaces xml.data xml.writer
xml.writer.private ;

M: entity-decl write-xml
"<!ENTITY " write
[ pe?>> [ " % " write ] when ] [ name>> write " \"" write ]
[
def>> f xml-pprint? [ write-xml ] with-variable
"\">" write
] tri ;


USING: accessors io xml.data xml.writer ;

M: instruction write-xml "<?" write text>> write "?>" write ;


USING: accessors xml.data xml.writer xml.writer.private ;

M: notation-decl write-xml "NOTATION" [ id>> ] write-decl ;


USING: kernel math xml.writer ;

M: number write-xml "Numbers are not allowed in XML" throw ;


USING: combinators kernel namespaces xml.data xml.writer
xml.writer.private ;

M: open-tag write-xml
xml-pprint? get [
{
[ write-start-tag ]
[
sensitive? not xml-pprint? get and
xml-pprint? set
]
[ write-children ]
[ write-end-tag ]
} cleave
] dip xml-pprint? set ;


USING: accessors io kernel xml.data xml.writer
xml.writer.private ;

M: prolog write-xml
"<?xml version=" write
[ version>> write-quoted ]
[ drop " encoding=\"UTF-8\"" write ]
[ standalone>> [ " standalone=\"yes\"" write ] when ] tri
"?>" write ;


USING: accessors io kernel xml.data xml.writer
xml.writer.private ;

M: public-id write-xml
"PUBLIC" write bl
[ pubid-literal>> write-quoted bl ]
[ system-literal>> write-quoted ] bi ;


USING: sequences xml.writer ;

M: sequence write-xml [ write-xml ] each ;


USING: io kernel namespaces sequences strings
unicode.categories wrap.strings xml.entities xml.writer
xml.writer.private ;

M: string write-xml
escape-string xml-pprint? get [
dup [ blank? ] all?
[ drop "" ]
[ nl 80 indent-string wrap-indented-string ] if
] when write ;


USING: accessors io xml.data xml.writer xml.writer.private ;

M: system-id write-xml
"SYSTEM" write bl system-literal>> write-quoted ;


USING: accessors io xml.data xml.writer ;

M: unescaped write-xml string>> write ;


USING: accessors combinators xml.data xml.writer ;

M: xml write-xml
{
[ prolog>> write-xml ]
[ before>> write-xml ]
[ body>> write-xml ]
[ after>> write-xml ]
} cleave ;