[web-devel] VXML - validating XHTML library

Marc Weber marco-oweber at gmx.de
Fri Sep 12 19:15:27 EDT 2008


Hi @ll.

Those of you reading the haskelcafe mailinglist already know that I've
been working on vxml. It's a library letting you write XHTML code
validating the result at compilation time against a given dtd.

How does it work?
Given a doctype like this :

          <!ELEMENT root (y*,z)*>
          <!ELEMENT y EMPTY>
          <!ELEMENT z EMPTY>

results in a set of state transformation rules. A new empty root tag
starts with the State1. From that on it's fed with either y or z (using
functional dependencies) resulting a new state 1 or 7. If you add an
subelement y the state changes to 7 which is not endable forcing you to
add another element. etc..

          State 1
            endable : True
            y -> St 7
            z -> St 1

          State2 :7
            endable : False
            y -> St 7
            z -> St 1

Use this on a xhtml dtd and you'll get about 500 different states and a
lot of instances. Luckily most elements are described this way:
(PCDATA|div|form|...)*
this means that the sate does not change after an element which should
enable you to use foldr functions or such without type hackery (? I have
to verify this)..

Validation errors are denoted this way:

  * wrong element (1):
    "No instance for (Consume State4 (Elem B_T) st')"

  * more elements expected (1):
    "No instance for (ElEndable Root_T State4)"

  * invalid attribute:
    "No instance for (AttrOk Root_T AAttr_A)"

  * duplicate attribute:
    "No instance for (Text.XML.Validated.Types.DuplicateAttribute A_T AAttr_A)"

  * missing required attributes:
    "No instance for (Text.XML.Validated.Types.RequiredAttributesMissing
                            Root_T (HCons (A RootAttr_A) HNil))"


Using ghc head you can rebind >>= and >> and use a do like notation:

  #if (__GLASGOW_HASKELL__ > 608)
  #include "vxmldos.h"
    tDo $ runHtmlDoc $ vdo
      head $ title $ text "text"
      body $ vdo
        script $ X.type "text/javascript" >> text "document.writeln('hi');"
        h2 $ text "That's a headline, hello and how do you do?"
        -- br e   eg a <br/> is not allowed here
        div $ vdo
          onclick "alert('clicked');"
          styleA "color:#F79"
          text "text within the div"
        div e
        return "That's nice, isn't it?"

  resulting in:
  returned value : "That's nice, isn't it?"
  xml : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html><head><title>text</title></head><body><script type="text/javascript">document.writeln('hi');</script><h2>That's a headline, hello and how do you do?</h2><div onclick="alert('clicked');" style="color:#F79">text within the div</div><div/></body></html>

where vxmldos.h includes some macros rebinding >>=, >>, return and lift

If you want to jump in, test and give some feedback you're welcome.
Grab the code from git://mawercer.de/vxml
If you feel there is some documentation missing just ask.

Sincerly
  Marc Weber


More information about the web-devel mailing list