dom/writer
write a stream of SaxEvents back out as markup.
Since: 0.2.0
SaxWriter
(SaxWriter)
a streaming serializer. Release with `sax-writer-free`.
write-error-message
(write-error-message [e : WriteError] :)
a one-line description of a WriteError.
| e | the error |
cstr -- a static message.
(write-error-message (IoFailed)) ; => "could not write the output file"
Since: 0.2.0
transform-error-message
(transform-error-message [e : TransformError] :)
a one-line description of a TransformError.
| e | the error |
cstr -- borrowed from e (an InputError's message) or static.
(transform-error-message (OutputError (IoFailed))) ; => "could not write the output file"
Since: 0.2.0
transform-error-release
(transform-error-release [e : TransformError] :)
release what a TransformError owns.
| e | the error, not used afterwards |
(transform-error-release e)
Since: 0.2.0
sax-writer-new
(sax-writer-new [flavor : DomFlavor] :)
a writer that keeps its output in memory.
| flavor | `(XmlFlavor)` or `(HtmlFlavor)`: whose escaping and checks |
(Option SaxWriter) -- none only when out of memory. Release with `sax-writer-free`.
(match (sax-writer-new (XmlFlavor)) (Some w) ... (None) ...)
Since: 0.2.0
sax-writer-to-file
(sax-writer-to-file [flavor : DomFlavor path : cstr])
a writer that streams its output to a file.
| flavor | `(XmlFlavor)` or `(HtmlFlavor)` | |
| path | the file to create (truncated if it exists) |
(Result SaxWriter WriteError) -- IoFailed when the file cannot be created. Release the writer with `sax-writer-free`.
(sax-writer-to-file (XmlFlavor) "out.xml")
Since: 0.2.0
sax-write!
(sax-write! [w : SaxWriter ev : SaxEvent] :)
write one event.
| w | the writer | |
| ev | the event |
(Result nil WriteError) -- the writer's first refusal, again on every later call.
(sax-write! w (StartElement (from-cstr "a") (tnil)))
Since: 0.2.0
sax-write-all!
(sax-write-all! [w : SaxWriter evs : (Cons SaxEvent)] :)
write a list of events in order.
| w | the writer | |
| evs | the events, borrowed |
(Result nil WriteError) -- stops at the first refusal.
(sax-write-all! w (tcons-of (StartElement (from-cstr "a") (tnil))
(tcons-of (EndElement (from-cstr "a")) (tnil))))
Since: 0.2.0
sax-writer-finish!
(sax-writer-finish! [w : SaxWriter] :)
end the output and take it.
| w | the writer |
(Result String WriteError) -- the document, owned by the caller (empty for a file writer). An Err is the writer's first refusal.
(match (sax-writer-finish! w) (Ok s) (println (to-cstr s)) (Err e) ...)
Since: 0.2.0
sax-writer-free
(sax-writer-free [w : SaxWriter] :)
release a writer (closing its file, if any).
| w | the writer, not used afterwards |
(sax-writer-free w)
Since: 0.2.0
sax-transform-handler
(sax-transform-handler [w : SaxWriter f : (fn [SaxEvent])
a SAX handler that runs each event through f
| w | the writer the output goes to | |
| f | the transform: one event in, zero or more out |
(fn [SaxEvent] SaxControl) -- for any tur-xml or tur-html SAX entry point, including the push parsers.
(sax-parser-new (sax-transform-handler w sax-keep)) ; identity
Since: 0.2.0
sax-keep
(sax-keep [ev : SaxEvent] :)
the identity transform: the event, unchanged.
| ev | the event (owned, per `sax-transform-handler`) |
(Cons SaxEvent) -- a one-element list holding ev.
(sax-transform src sax-keep) ; => src, re-serialized
Since: 0.2.0
Internal definitions
__wr-error-- internal: a turdom error code as a WriteError.__wr-done-- internal: a turdom error code as a Result.__wr-nullp-- internal: is this a null pointer?__wr-new-raw-- internal.__wr-to-file-raw-- internal.__wr-err-raw-- internal: the sticky error, 0 when none.__wr-start-- internal.__wr-attr-- internal.__wr-end-- internal.__wr-chars-- internal.__wr-comment-- internal.__wr-pi-- internal.__wr-cdata-- internal.__wr-doctype-- internal.__wr-finish-raw-- internal: the output (malloc'd), or NULL on a refusal.__wr-null-cstr?-- internal.__wr-free-raw-- internal.__wr-html?-- internal.__wr-attrs-- internal: write a start tag's attributes, stopping at the__wr-event-- internal: write one event; the turdom code.__wr-list-- internal: write events in order; the first refusal's code.__wr-drain-- internal: write the events a transform returned, release