Re: (dsssl) Turning a string into a sequence of character nodes

Subject: Re: (dsssl) Turning a string into a sequence of character nodes
From: Norman Walsh <ndw@xxxxxxxxxx>
Date: Fri, 10 May 2002 17:27:52 -1000
/ Brandon Ibach <bibach@xxxxxxxxxxxxxx> was heard to say:
| (define (string->nodes s)
|   (let ((doc (string-append "&#60;literal>&#60;!DOCTYPE doc [ &#60;!ELEMENT "
|                             "doc - - (#PCDATA)> ]>&#60;doc>" s "&#60;/doc>")))
|     (children (node-property 'docelem (sgml-parse doc)))))

Thanks! I wound up with

(define (string->nodes s)
  ;; Escape XML characters...
  (let* ((achars (string-replace s "&#38;" "&#38;#38;#38;"))
	 (bchars (string-replace achars "&#60;" "&#38;#38;#60;"))
	 (cchars (string-replace bchars "&#62;" "&#38;#38;#62;")))
    (let ((doc (string-append "&#60;literal>&#60;!DOCTYPE doc [ &#60;!ELEMENT "
			      "doc - - (#PCDATA)> ]>&#60;doc>" cchars ";&#60;/doc>")))
      (children (node-property 'docelem (sgml-parse doc))))))

so that markup characters in the string wouldn't cause the parser to
barf. This will still fail, I think, if the string contains characters
not in the character set of the SGML declaration in effect, but I'm
not sure what to do about that.

                                        Be seeing you,
                                          norm

-- 
Norman Walsh <ndw@xxxxxxxxxx> | Klein bottle for rent; enquire within.
http://nwalsh.com/            | 

 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist

Current Thread