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

xml?

 [1/8] from: gchiu::compkarori::co::nz at: 15-Nov-2000 11:26


On Wed, 15 Nov 2000 00:15:51 +1300 "Andrew Martin" <[Al--Bri--xtra--co--nz]> wrote:
> >> parse dataline [ > [ thru "<HB>" copy HB to "</HB>" > [ thru "<WBC>" copy WBC to "</WBC>" > [ thru "<PLATELETS>" copy PLATELETS to "</PLATELETs>" > [ thru "<ESR>" copy ESR to "</ESR>" > [ to end
Thanks Andrew. I already had a brute force method working, and was trying to create something more generalised. -- Graham Chiu

 [2/8] from: gchiu:compkarori at: 15-Nov-2000 11:36


On Tue, 14 Nov 2000 10:02:40 -0600 Joel Neely <[joel--neely--fedex--com]> wrote:
> 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
Hi Joel, My fault. I removed the enclosing data tags before sending my message :-)
> nit-picky-ness firmly > in place... ;-) , the demo script below, %xml2obj.r > > REBOL [] > > phlarp: parse-xml {
parse-xml? Hey, an undocumented function :-) It is not mentioned in the core.pdf. And thanks for the example ... now to see if I can understand it <g> -- Graham Chiu

 [3/8] 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 ""

 [4/8] from: gchiu:compkarori at: 14-Nov-2000 22:56


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. Eg. tagblock: [ "HB" "WBC" "PLATELETS" "ESR" ] FBC: make object! [ HB: none WBC: none PLATELETS: none ESR: none ] ; dataline: "<HB>105</HB><WBC>7.1</WBC><PLATELETS>400</PLATELETs><ESR>100</ESR>" grabtags: func [ dataline [string!] /local headtag tailtag results result ] [ results: make block! 4 foreach element tagblock [ headtag: rejoin [ "<" element ">" ] tailtag: rejoin [ "</" element ">" ] parse dataline [ thru headtag copy result to tailtag ] ( { how does one set the appropriate instance variable eg. FBC/ESR gets set to 100} ) ] ] So, looking for an elegant solution to setting the instance variables ... -- Graham Chiu

 [5/8] from: al:bri:xtra at: 15-Nov-2000 0:15


Try this:
>> dataline:
<HB>105</HB><WBC>7.1</WBC><PLATELETS>400</PLATELETs><ESR>100</ESR> == {<HB>105</HB><WBC>7.1</WBC><PLATELETS>400</PLATELETs><ESR>100</ESR>}
>> >> parse dataline [
[ thru "<HB>" copy HB to "</HB>" [ thru "<WBC>" copy WBC to "</WBC>" [ thru "<PLATELETS>" copy PLATELETS to "</PLATELETs>" [ thru "<ESR>" copy ESR to "</ESR>" [ to end [ ] == true
>> hb
== "105"
>> wbc
== "7.1"
>> platelets
== "400"
>> esr
== "100" Repeat as needed. BTW, it depends upon the data being in that _EXACT_ order, but I haven't got time tonight/this morning to produce a full XML solution that uses objects. Maybe next week. Andrew Martin ICQ: 26227169 http://members.nbci.com/AndrewMartin/

 [6/8] from: brigby:fdmsoft at: 18-Jan-2001 10:24


I'm a newbie to rebol and am looking at xml parsing and generation functionality. Basically I want to be able to connect to database on my server and extract information in XML format and the reverse. What parts of Rebol should I be looking at? I don't see any reference to XML in the Official Guide .. are there any other sources that might steer me in the correct direction? Sorry for the simplicity of this query, but I hope it will save a lot of searching. Brian

 [7/8] from: rebol:techscribe at: 18-Jan-2001 11:31


Hi Brian, looked at parsing, generally speaking, and take a close look at the parse-xml function and the xml-language object. The parse-xml function btw is no more thatn a shortcut, it simply calls the xml-language/parse-xml
>> write %xml.r mold xml-language
will do the trick. Hope this helps, Elan Brian Rigby wrote:

 [8/8] from: brigby:fdmsoft at: 18-Jan-2001 14:12


Thanks for the help. Brian