Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] PS: RFC: addressbook.r

From: ingo::2b1::de at: 31-Oct-2000 14:58

Sorry, my previous post missed a helper script, that's needed to make it work ... Here it is. P.S.: you can change yamm/import %xml-helper.r to do %xml-helper.r without any bad side-effects. regards, Ingo -- Attached file included as plaintext by Listar -- [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 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 "</" trim tag ">"] ] 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 ] ] xml-structure: ['document none! xml-element-contents] xml-element-node: [into [xml-element-name xml-element-attributes xml-element-contents]] xml-element-name: [set elt-name string! (print elt-name)] xml-element-attributes: [none! | block!] xml-element-contents: [none! | into [some [xml-element-node | string! ]]] xml-target: http://p.moreover.com/cgi-local/page?index_devoper+xml parse parse-xml read xml-target xml-structure