REBOL [ Title: "XML helpers" Author: [jn "Joel Neely" iho "Ingo Hohmann"] email: [iho ingo@2b1.de] ] trim-xml: func [ {trim whitespace from parse-xml created blocks (jn)} b [block!] /local content item ][ content: third b if found? content [ while [not tail? content] [ item: first content either block? item [ trim-xml item content: next content ][ either 0 = length? trim item [ remove content ][ content: next content ] ] if none? content [print "yauk!"] ] if 0 = length? head content [ b/3: none ] ] b ] _xdump: func [ {xdump internal helper (jn)(iho)} b [block!] {xml structure} indent [string!] /start "starting the recursion" /local tag next-indent was-string out prin print ][ prin: func [s][append out s] print: func [s][append out join s newline] out: "" if start [clear out] tag: trim to-string first b prin join copy indent [join copy "<" tag] if block? second b [ foreach [n v] second b [ prin join copy " " [either string? n [trim n][n] {="} form v {"}] ] ] either not block? third b [ print " />" ][ print ">" next-indent: join copy indent " " was-string: false foreach x third b [ was-string: not any-block? x either was-string [ if 0 < length? trim x [ print join copy next-indent x ] ][ _xdump x next-indent ] ] print join copy indent [copy ""] ] if start [out] ] xdump: func [ {pretty print a block created from parse-xml (jn)(iho)} b [block!] {the xml structure from parse-xml} /complete {doesn't omit the outer blocks (normally document none [])} ][ either complete [ _xdump/start b copy "" ][ _xdump/start first third b copy "" ] ] build-xml-tag: func [ "Generates a tag from a composed block. (iho)" blk [block!] "Block of parens to evaluate and other data" /stand-alone "creates a stand-alone (self-closing) tag" /local out in ][ append out: copy # either 0 < length? blk: compose blk [ in: first head blk: next blk either not any-string? in [mold in] [in] ] [#] foreach [att val] blk [ append out rejoin [" " att {="} val {"}] ] ?? out if stand-alone [append out " /"] to-tag trim out ]