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

XML Dialect

 [1/7] 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 ]

 [2/7] from: al:bri:xtra at: 25-Apr-2002 21:17


Andrew wrote:
> Here's my first try at an XML dialect for Rebol.
And here's my second try. It does HTML as well, and is smaller. Plus it incorporates the SVG MIME correction from Adobe's FAQ. Comments and suggestions gratefully appreciated. Andrew Martin Rebolios ANZAC... 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 Properties Value Tag ] [ String: make string! 10000 Values: make block! 10 Properties: [ none [ set Value any-type! ( Tag: at Tag 3 if word? Value [Value: to-string Value] insert Tag Value Value: none ) ] ] parse Dialect [ any [ set Value tag! (append String Value) | set Tag [path! | word!] ( Tag: to-block get 'Tag Properties/1: -1 + length? Tag ) Properties opt [set Value [block! | string!]] ( Tag: head Tag repend String either none? Value [ [join build-tag Tag " /"] ] [ [ build-tag Tag either block? Value [XML Value] [Value] to-tag join "/" first Tag ] ] Properties/1: none ) ] end ] String ] ] File: %Test.svg write File XML [ <?xml version="1.0" 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 ] text/x/y/font-family/font-size/fill 20 15 "Verdana" 12 green "Hello from Rebol SVG dialect!" ] ] File: %Test.html write File XML [ html [ head [ title "Test" ] body [ h1 "Test" p/class "Initial" "Test paragraphs" p {Now is the time for all good men to come to the aid of the party.} hr embed/src/name/type/pluginspage "Test.svg" "Test" "image/svg+xml" http://www.adobe.com/svg/viewer/install/ ] ] ] browse File ]

 [3/7] from: cybarite:sympatico:ca at: 25-Apr-2002 0:27


Hi Andrew, I am interested in it and spent some time trying to get text to display. Didn't get finished so I will try your update. Here are some simple other graphics from other sources put in your format Advise if that is not how you envisioned specifying points and then how will I be able to take points that REBOL knows and reduce them in your dialect. circle/cx/cy/r/style 150 200 100 { fill: orange; stroke: red; stroke-width:10; fill-opacity:0.9; } ellipse/cx/cy/rx/ry/style 200 200 80 130 { fill: none; stroke: gold; stroke-width: 5; fill-opacity:0.9; } polygon/points/style { 350,75 379,161 469,161 397,215 423,301 350,250 277,301 303,215 231,161 321,161} { fill:red; stroke:blue; stroke-width:10; } polygon/points/style { 850,75 958,137.5 958,262.5 850,325 742,262.6 742,137.5} { fill:red; stroke:blue; stroke-width:10; } polyline/points/style { 10,375 50,375 50,325 250,325 250,375 350,375 350,250 450,250 450,375 550,375 550,175 650,175 650,375 750,375 750,100 850,100 850,375 950,375 950,25 1050,25 1050,375 1150,375} { fill: brown; stroke: black; stroke-width: 2; }

 [4/7] from: brett:codeconscious at: 25-Apr-2002 23:06


Hi Andrew,
> > Here's my first try at an XML dialect for Rebol. > > And here's my second try. It does HTML as well, and is smaller. Plus it > incorporates the SVG MIME correction from Adobe's FAQ. > > Comments and suggestions gratefully appreciated.
It is interesting. I was playing around with Topic Maps (confusing things they are too) some months back and I was using Gavin's great xml parser. The thing is I had come up with a dialect *very* similar to yours - actually identical in relation to using paths to encode attributes. I was looking for a nice way to encode xml as rebol values and to try to capture as much of the xml as possible. The difference between what I did and what you have done is that yours produces xml and mine reads it in! Nice fit :^) However, there is one other difference I actually always produce a block for the content of an element whereas your dialect is a bit smarter. Perhaps with a small change they can work together. Here's the result of my script when applied to your test.html (I've manually added new lines and indentation to make it easier to read). [ html [ head [ title ["Test"] ] body [ h1 [ "Test" ] p/class [ "Test paragraphs" ] "Initial" p [ {Now is the time for all good men to come to the aid of the party.} ] hr [ none ] embed/src/name/type/pluginspage [none] "Test.svg" "Test" "image/svg+xml" http://www.adobe.com/svg/viewer/install/ ] ] ] It doesn't produce anything for test.svg - haven't looked into why yet. See below for the script. Regards, Brett. [ REBOL [ Title: "XML dialect experiement" File: %xml-to-functions.r Author: "Brett Handley" Date: 29-Dec-2001 ] do %xml-parse.r xml-to-functions: make xml-parse/xml-parse-handler [ _spop: function [a-stack] [a-val] [ if 0 < length? a-stack [ a-val: last a-stack remove back tail a-stack a-val ] ] _spush: func [a-stack val] [ append/only a-stack val ] _stack: none start-document: func [ ] [ _stack: copy [] _script: copy [ ] ] xml-decl: func [ version-info [string! none!] encoding [string! none!] standalone [string! none!] ] [ ] document-type: func [ document-type [string!] public-id [string! none!] system-id [string! none!] internal-subset [string! none!] ] [ ] start-element: func [ ns-uri [string! none!] local-name [string! none!] q-name [string!] attr-list [block!] ] [ _spush _stack _script append _script reduce compose [ to-path head insert map :to-word extract attr-list 2 to-word local-name _script: copy [ ] (extract next attr-list 2) ] ] end-element: func [ ns-uri [string! none!] local-name [string! none!] q-name [string!] ] [ _script: _spop _stack ] characters: func [ characters [string! none!] ] [ if any [ none? characters all [characters not empty? trim copy characters] ] [ append/only _script characters ] ] pi: func [ pi-target [string! none!] pi [string! none!] ] [ ] comment: func [ comment [string! none!] ] [ ] end-document: func [] [ ] start-prefix-mapping: func [ ns-prefix-uri-pairs [block!] ] [ ] end-prefix-mapping: func [ ns-prefix-uri-pairs [block!] ] [ ] get-parse-result: does [ _script ] ] xml-parse/parser/handler: xml-to-functions r: parse-xml+ read %test.html probe r: parse-xml+ read %test.svg halt ]

 [5/7] from: al:bri:xtra at: 26-Apr-2002 6:41


Hi, Brett.
> do %xml-parse.r
Where can I find %xml-parse.r ? It would be really neat for both to work together. I'll look into it as well. Andrew Martin ICQ: 26227169 http://valley.150m.com/

 [6/7] from: brett:codeconscious at: 26-Apr-2002 6:31


> Where can I find %xml-parse.r ?
http://www3.sympatico.ca/gavin.mckenzie/ Brett.

 [7/7] from: al:bri:xtra at: 26-Apr-2002 6:29


Cybarite wrote:
> Advise if that is not how you envisioned specifying points and then how
will I be able to take points that REBOL knows and reduce them in your dialect. Currently the dialect doesn't know about the Rebol pair! datatype. I think that this ability belongs to a slightly higher level of dialect at the moment. Andrew Martin ICQ: 26227169 http://valley.150m.com/