VXML - validating XHTML library

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

Just out of interest, why DTD and not XSchema? I would have thought the latter were more complete in many respects. Paul At 00:15 13/09/2008, you wrote:
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 _______________________________________________ web-devel mailing list web-devel@haskell.org http://www.haskell.org/mailman/listinfo/web-devel

On Sat, Sep 13, 2008 at 01:05:04AM +0100, Paul Stanley wrote:
Just out of interest, why DTD and not XSchema? I would have thought the latter were more complete in many respects. I didn't kewn about it and I knew XHTML is defined by dtd which I was interested in.
Greetings Marc

Just out of interest, why DTD and not XSchema? I would have thought the latter were more complete in many respects. I didn't know about it and I knew XHTML is defined by dtd which I was interested in. The schema syntax is a little verbose but you get clarity in abundance. I'd be interested in more info on your XHTML validator project. I wonder if anyone's thought of creating a Haskell substitute for the Tomcat,(Oracle|MySQL) web data management system, well, at least the bits that deal with XSQL and XML apps. It's a mystery to me that very few have embraced the idea of a neat clean declarative tool for setting up websites. Paul
participants (2)
-
Marc Weber
-
P. R. Stanley