xml/transform
src/xml/transform.tur
rewrite an XML document as it streams past.
Since: 0.2.0
defn
sax-transform-opts
(sax-transform-opts [src : cstr opts : ParseOpts f : (fn [SaxEvent])
transform an in-memory document.
Parameters
| src | the document | |
| opts | parse options (`namespaces`, limits, entities) | |
| f | one event in (owned), the events to write out |
Returns
(Result String TransformError) -- the rewritten document, owned by the caller; InputError when src does not parse, OutputError when the writer refuses what f returned (the parse stops there).
Example
(sax-transform-opts src (with (default-parse-opts) [namespaces false])
sax-keep)
Since: 0.2.0
defn
sax-transform
(sax-transform [src : cstr f : (fn [SaxEvent])
transform an in-memory document with the safe default
Parameters
| src | the document | |
| f | one event in (owned), the events to write out |
Returns
(Result String TransformError)
Example
;; Rename every <item> to <entry>.
(sax-transform src
(fn [ev : SaxEvent] : (Cons SaxEvent)
(match ev
(StartElement n as) (if (string=? n "item")
(do (release n)
(tcons-of (StartElement (from-cstr "entry") as) (tnil)))
(sax-keep ev))
(EndElement n) (if (string=? n "item")
(do (release n)
(tcons-of (EndElement (from-cstr "entry")) (tnil)))
(sax-keep ev))
_ (sax-keep ev))))
Since: 0.2.0
defn
sax-transform-file
(sax-transform-file [in-path : cstr out-path : cstr opts : ParseOpts f : (fn [SaxEvent])
transform a file into another, streaming both.
Parameters
| in-path | the document to read | |
| out-path | the file to write (created or truncated) | |
| opts | parse options | |
| f | one event in (owned), the events to write out |
Returns
(Result nil TransformError) -- OutputError (IoFailed) when out-path cannot be created or written.
Example
(sax-transform-file "in.xml" "out.xml" (default-parse-opts) sax-keep)
Since: 0.2.0
Internal definitions
__xt-finish-- internal: the parse's outcome, then the writer's.