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

[REBOL] Re: xml?

From: joel:neely:fedex at: 14-Nov-2000 10:02

Hi, Graham, Here's my quick-and-dirty... [rebol-bounce--rebol--com] wrote:
> Maybe one day I'll get my data as XML rather than HL7, and > in preparation I've been wondering how I would go about > extracting data. >
> ; dataline: "<HB>105</HB><WBC>7.1</WBC><PLATELETS>400</PLATELETs><ESR>100</ESR>" >
Bear in mind that the above is not valid XML. There must be one top-level tag that encloses all other content. With that bit of nit-picky-ness firmly in place... ;-) , the demo script below, %xml2obj.r REBOL [] phlarp: parse-xml { <data> <HB>105</HB><WBC>7.1</WBC><PLATELETS>400</PLATELETs><ESR>100</ESR> </data> } objblock: copy [] foreach item phlarp/3/1/3 [ if block? item [ append objblock reduce [to-set-word item/1 item/3/1] ] ] objobj: make object! objblock probe objobj get in objobj 'HB produces as output
>> do %xml2obj.r
make object! [ HB: "105" WBC: "7.1" PLATELETS: "400" ESR: "100" ] == "105" Obviously a real application of this idea would traverse an entire multi-record XML tree with something more intelligent than phlarp/3/1/3 but that is "left as an exercise for the reader". Hope this helps! -jn- -- ; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677 REBOL [] foreach [order string] sort/skip reduce [ true "!" false head reverse "rekcah" none "REBOL " prin "Just " "another " ] 2 [prin string] print ""