[racket] HTML parser

From: J Cho (jgustavcho at gmail.com)
Date: Thu Dec 8 23:13:49 EST 2011

To HTML parser experts,

I am trying to transform a div tag in the following HTML document:

(define an-html
     "<html><head><title>My title</title></head><body>"
     "<p>Hello world</p><div id='_abc'>replace me</div><p><b>Testing</b>!</p>"

I want <div id='_abc'>replace me</div> to read  something like <div
id='_abc'>I am <span>replaced</span></div>.

I am trying (without much success) the following code:

(define (echo-or-change-element an-html-element)
  (match an-html-element
    [(struct h:div (attributes content))
     (begin (display "BINGO!\n")
            (display "\n")

            (h:make-div attributes
                       (list (x:xexpr->xml (x:string->xexpr

I am also having trouble with expression: (x:display-xml/content
(echo-content an-html))

Thanks in advance.


tldr - trouble writing out html elements and creating html from string

Posted on the users mailing list.