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

[REBOL] Re: XML Dialect

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" ] ] ] 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 ]