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

[REBOL] XML Dialect

From: al::bri::xtra::co::nz at: 25-Apr-2002 17:15

Carl Sassenrath wrote:
> I think it's good to invent some smart way to make Web Services easier via
REBOL. Here's my first try at an XML dialect for Rebol. Watch out for line breaks. It's not very smart, just a translation of Rebol values into the XML equivalent. There's an example at the end, using the XML dialect to generate a .svg file and browsing it. You'll need the Adobe SVG viewer http://www.adobe.com/svg/ to make this run on your browser. Tags are simply copied. Single words are translated into tags. Paths are translated into tags and properties. Andrew Martin ICQ: 26227169 http://valley.150m.com/ -><- [ Rebol [ Name: 'XML Title: "XML" File: %XML.r Author: "Andrew Martin" eMail: [Al--Bri--xtra--co--nz] Date: 25/Apr/2002 ] make object! [ set 'XML function [Dialect [block!] ] [ String Values Rule Value TagProperties Tag Block ] [ String: make string! 10000 Values: make block! 10 parse Dialect Rule: [ any [ set Value tag! (append String Value) | set TagProperties path! ( TagProperties: at to-block get 'TagProperties 3 ) some [ set Value [ decimal! | string! | integer! | url! | email! | issue! | char! | date! | time! | logic! | money! | none! | pair! | tuple! ] ( insert TagProperties Value TagProperties: at TagProperties 3 ) ] (Value: none) opt [set Value block!] ( TagProperties: head TagProperties either block? Value [ repend String [ build-tag TagProperties XML Value to-tag join "/" first TagProperties ] ] [ append String join build-tag TagProperties " /" ] ) | set Tag word! set Value [string! | block!] ( repend String [ to-tag Tag either string? Value [Value] [XML Value] to-tag join "/" Tag ] ) | set Tag word! ( append String to-tag join Tag " /" ) ] end ] String ] ] File: %Test.svg write File probe XML [ <?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> svg/width/height 300 300 [ desc "Several rectangles" rect/x/y/width/height/style 80 53 189 52 { fill:rgb(39,44,231); stroke:rgb(0,0,128); stroke-width:1 } rect/x/y/width/height/style 0 0 189 152 { fill:olive; stroke:pink; stroke-width:5; fill-opacity:0.1 } g/id/fill "Group1" "red" [ rect/x/y/width/height 10 10 30 40 rect/x/y/width/height 30 30 30 40 ] ] ] browse File halt ]