4  MysterX documents

Each time a MysterX browser navigates to a URL, it generates a new MysterX document. A document is an instance of the mx-document% class. The document currently displayed in the browser can be obtained by

(define doc (send browser current-document))

Let's look at some useful mx-document% methods. The method insert-html stuffs HTML at the beginning of the document. Here's code that puts a button in doc:

(send doc insert-html 
      "<BUTTON id=\"ok-button\">OK? OK!</BUTTON>")

This code works fine, but we can use the xml collection to avoid writing HTML directly:

(require (lib "xml.ss" "xml"))
(send doc insert-html 
      (xexpr->string (button ((id "ok-button")) "OK? OK!")))

The X-expression more clearly reveals the structure of the item we are inserting.

We use the ``id'' attribute to distinguish this button element from other elements. MysterX uses the ``id'' attribute for identifying elements. The append-html method is just like insert-html, except that it stuffs the HTML at the end of the document. The method replace-html replaces the existing HTML in the document with new HTML.