diff --git a/HaXml.cabal b/HaXml.cabal
--- a/HaXml.cabal
+++ b/HaXml.cabal
@@ -1,5 +1,5 @@
 name:		HaXml
-version:	1.19.6
+version:	1.19.7
 license:	LGPL
 license-file:	COPYRIGHT
 author:		Malcolm Wallace <Malcolm.Wallace@cs.york.ac.uk>
@@ -52,7 +52,7 @@
         Text.XML.HaXml.Xtract.Lex,
         Text.XML.HaXml.Xtract.Parse
   hs-source-dirs: src
-  build-depends: base, haskell98, polyparse, filepath
+  build-depends: base, haskell98, polyparse==1.2, filepath
   if flag(splitBase)
     build-depends: base >= 3, pretty, random, containers
   else
@@ -62,7 +62,7 @@
   else
     build-depends: base < 2 || >= 3, bytestring
   extensions: CPP, ExistentialQuantification
-  cpp-options: -DVERSION=1.19.6
+  cpp-options: -DVERSION=1.19.7
   nhc98-options: -K10M
 
 Executable Canonicalise
diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
 SOFTWARE = HaXml
-VERSION  = 1.19.6
+VERSION  = 1.19.7
 
 #CPP      = cpp -traditional
 CPP     = cpphs --text --noline	# useful e.g. on MacOS X
diff --git a/docs/HaXml/Text-XML-HaXml-XmlContent.html b/docs/HaXml/Text-XML-HaXml-XmlContent.html
--- a/docs/HaXml/Text-XML-HaXml-XmlContent.html
+++ b/docs/HaXml/Text-XML-HaXml-XmlContent.html
@@ -145,6 +145,16 @@
 ></TR
 ><TR
 ><TD CLASS="decl"
+>module <A HREF="Text-XML-HaXml-TypeMapping.html"
+>Text.XML.HaXml.TypeMapping</A
+></TD
+></TR
+><TR
+><TD CLASS="s8"
+></TD
+></TR
+><TR
+><TD CLASS="decl"
 ><A HREF="#v%3AtoXml"
 >toXml</A
 > :: <A HREF="Text-XML-HaXml-XmlContent-Parser.html#t%3AXmlContent"
@@ -303,6 +313,16 @@
 ><TD CLASS="decl"
 >module <A HREF="Text-XML-HaXml-XmlContent-Parser.html"
 >Text.XML.HaXml.XmlContent.Parser</A
+></TD
+></TR
+><TR
+><TD CLASS="s15"
+></TD
+></TR
+><TR
+><TD CLASS="decl"
+>module <A HREF="Text-XML-HaXml-TypeMapping.html"
+>Text.XML.HaXml.TypeMapping</A
 ></TD
 ></TR
 ><TR
diff --git a/docs/HaXml/src/Text/XML/HaXml/Html/Parse.html b/docs/HaXml/src/Text/XML/HaXml/Html/Parse.html
--- a/docs/HaXml/src/Text/XML/HaXml/Html/Parse.html
+++ b/docs/HaXml/src/Text/XML/HaXml/Html/Parse.html
@@ -28,7 +28,7 @@
 <a name="line-21"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Types
 <a name="line-22"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Lex
 <a name="line-23"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Posn
-<a name="line-24"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>NoLeak<font color=Cyan>.</font>Plain
+<a name="line-24"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>Plain
 <a name="line-25"></a>
 <a name="line-26"></a><font color=Blue>--  #define DEBUG</font>
 <a name="line-27"></a> 
diff --git a/docs/HaXml/src/Text/XML/HaXml/Html/ParseLazy.html b/docs/HaXml/src/Text/XML/HaXml/Html/ParseLazy.html
--- a/docs/HaXml/src/Text/XML/HaXml/Html/ParseLazy.html
+++ b/docs/HaXml/src/Text/XML/HaXml/Html/ParseLazy.html
@@ -28,7 +28,7 @@
 <a name="line-21"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Types
 <a name="line-22"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Lex
 <a name="line-23"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Posn
-<a name="line-24"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>NoLeak<font color=Cyan>.</font>Lazy
+<a name="line-24"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>Lazy
 <a name="line-25"></a>
 <a name="line-26"></a><font color=Blue>--  #define DEBUG</font>
 <a name="line-27"></a> 
diff --git a/docs/HaXml/src/Text/XML/HaXml/Parse.html b/docs/HaXml/src/Text/XML/HaXml/Parse.html
--- a/docs/HaXml/src/Text/XML/HaXml/Parse.html
+++ b/docs/HaXml/src/Text/XML/HaXml/Parse.html
@@ -47,7 +47,7 @@
 <a name="line-40"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Types
 <a name="line-41"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Posn
 <a name="line-42"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Lex
-<a name="line-43"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>NoLeak<font color=Cyan>.</font>State
+<a name="line-43"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>State
 <a name="line-44"></a>
 <a name="line-45"></a><font color=Green><u>import</u></font> System<font color=Cyan>.</font>FilePath <font color=Cyan>(</font>combine<font color=Cyan>,</font> dropFileName<font color=Cyan>)</font>
 <a name="line-46"></a>
diff --git a/docs/HaXml/src/Text/XML/HaXml/ParseLazy.html b/docs/HaXml/src/Text/XML/HaXml/ParseLazy.html
--- a/docs/HaXml/src/Text/XML/HaXml/ParseLazy.html
+++ b/docs/HaXml/src/Text/XML/HaXml/ParseLazy.html
@@ -47,7 +47,7 @@
 <a name="line-40"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Types
 <a name="line-41"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Posn
 <a name="line-42"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Lex
-<a name="line-43"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>NoLeak<font color=Cyan>.</font>StateLazy
+<a name="line-43"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>StateLazy
 <a name="line-44"></a>
 <a name="line-45"></a><font color=Green><u>import</u></font> System<font color=Cyan>.</font>FilePath <font color=Cyan>(</font>combine<font color=Cyan>,</font> dropFileName<font color=Cyan>)</font>
 <a name="line-46"></a>
diff --git a/docs/HaXml/src/Text/XML/HaXml/SAX.html b/docs/HaXml/src/Text/XML/HaXml/SAX.html
--- a/docs/HaXml/src/Text/XML/HaXml/SAX.html
+++ b/docs/HaXml/src/Text/XML/HaXml/SAX.html
@@ -19,7 +19,7 @@
 <a name="line-12"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Types
 <a name="line-13"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Parse
 <a name="line-14"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Lex
-<a name="line-15"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>NoLeak<font color=Cyan>.</font>State
+<a name="line-15"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly<font color=Cyan>.</font>State
 <a name="line-16"></a>
 <a name="line-17"></a><a name="SaxElement"></a><font color=Green><u>data</u></font> SaxElement
 <a name="line-18"></a>	<font color=Red>=</font> SaxDocTypeDecl DocTypeDecl
diff --git a/docs/HaXml/src/Text/XML/HaXml/XmlContent.html b/docs/HaXml/src/Text/XML/HaXml/XmlContent.html
--- a/docs/HaXml/src/Text/XML/HaXml/XmlContent.html
+++ b/docs/HaXml/src/Text/XML/HaXml/XmlContent.html
@@ -23,164 +23,166 @@
 <a name="line-16"></a>  <font color=Cyan>(</font>
 <a name="line-17"></a>  <font color=Blue>-- * Re-export everything from Text.XML.HaXml.XmlContent.Parser.</font>
 <a name="line-18"></a>    <font color=Green><u>module</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>XmlContent<font color=Cyan>.</font>Parser
-<a name="line-19"></a>  <font color=Blue>-- * Contains instances of the XmlContent classes,</font>
-<a name="line-20"></a>  <font color=Blue>--   for the basic Haskell datatypes list and Maybe,</font>
-<a name="line-21"></a>  <font color=Blue>--   intended for use with DtdToHaskell-generated datatypes.</font>
-<a name="line-22"></a>  <font color=Blue>--   See the alternative instances in Text.XML.HaXml.XmlContent.Haskell</font>
-<a name="line-23"></a>  <font color=Blue>--   if your datatypes originate in Haskell instead.</font>
-<a name="line-24"></a><font color=Blue>--  , module Text.XML.HaXml.XmlContent</font>
-<a name="line-25"></a>
-<a name="line-26"></a>  <font color=Blue>-- * Whole-document conversion functions</font>
-<a name="line-27"></a>  <font color=Cyan>,</font> toXml<font color=Cyan>,</font> fromXml
-<a name="line-28"></a>  <font color=Cyan>,</font> readXml<font color=Cyan>,</font> showXml<font color=Cyan>,</font> fpsShowXml
-<a name="line-29"></a>  <font color=Cyan>,</font> fReadXml<font color=Cyan>,</font> fWriteXml<font color=Cyan>,</font> fpsWriteXml
-<a name="line-30"></a>  <font color=Cyan>,</font> hGetXml<font color=Cyan>,</font>  hPutXml<font color=Cyan>,</font> fpsHPutXml
-<a name="line-31"></a>  <font color=Cyan>)</font> <font color=Green><u>where</u></font>
-<a name="line-32"></a>
-<a name="line-33"></a><font color=Green><u>import</u></font> IO
-<a name="line-34"></a><font color=Green><u>import</u></font> <font color=Green><u>qualified</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>ByteStringPP <font color=Green><u>as</u></font> FPS <font color=Cyan>(</font>document<font color=Cyan>)</font>
-<a name="line-35"></a><font color=Green><u>import</u></font> <font color=Green><u>qualified</u></font> Data<font color=Cyan>.</font>ByteString<font color=Cyan>.</font>Lazy<font color=Cyan>.</font>Char8 <font color=Green><u>as</u></font> FPS
-<a name="line-36"></a>
-<a name="line-37"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>PrettyPrint<font color=Cyan>.</font>HughesPJ <font color=Cyan>(</font>render<font color=Cyan>)</font>
-<a name="line-38"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly
-<a name="line-39"></a>
-<a name="line-40"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Types
-<a name="line-41"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>TypeMapping
-<a name="line-42"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Posn     <font color=Cyan>(</font>Posn<font color=Cyan>,</font> posInNewCxt<font color=Cyan>)</font>
-<a name="line-43"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Pretty   <font color=Cyan>(</font>document<font color=Cyan>)</font>
-<a name="line-44"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Parse    <font color=Cyan>(</font>xmlParse<font color=Cyan>)</font>
-<a name="line-45"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>XmlContent<font color=Cyan>.</font>Parser
-<a name="line-46"></a>
+<a name="line-19"></a>  <font color=Cyan>,</font> <font color=Green><u>module</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>TypeMapping
+<a name="line-20"></a>  <font color=Blue>-- * Contains instances of the XmlContent classes,</font>
+<a name="line-21"></a>  <font color=Blue>--   for the basic Haskell datatypes list and Maybe,</font>
+<a name="line-22"></a>  <font color=Blue>--   intended for use with DtdToHaskell-generated datatypes.</font>
+<a name="line-23"></a>  <font color=Blue>--   See the alternative instances in Text.XML.HaXml.XmlContent.Haskell</font>
+<a name="line-24"></a>  <font color=Blue>--   if your datatypes originate in Haskell instead.</font>
+<a name="line-25"></a><font color=Blue>--  , module Text.XML.HaXml.XmlContent</font>
+<a name="line-26"></a>
+<a name="line-27"></a>  <font color=Blue>-- * Whole-document conversion functions</font>
+<a name="line-28"></a>  <font color=Cyan>,</font> toXml<font color=Cyan>,</font> fromXml
+<a name="line-29"></a>  <font color=Cyan>,</font> readXml<font color=Cyan>,</font> showXml<font color=Cyan>,</font> fpsShowXml
+<a name="line-30"></a>  <font color=Cyan>,</font> fReadXml<font color=Cyan>,</font> fWriteXml<font color=Cyan>,</font> fpsWriteXml
+<a name="line-31"></a>  <font color=Cyan>,</font> hGetXml<font color=Cyan>,</font>  hPutXml<font color=Cyan>,</font> fpsHPutXml
+<a name="line-32"></a>  <font color=Cyan>)</font> <font color=Green><u>where</u></font>
+<a name="line-33"></a>
+<a name="line-34"></a><font color=Green><u>import</u></font> IO
+<a name="line-35"></a><font color=Green><u>import</u></font> <font color=Green><u>qualified</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>ByteStringPP <font color=Green><u>as</u></font> FPS <font color=Cyan>(</font>document<font color=Cyan>)</font>
+<a name="line-36"></a><font color=Green><u>import</u></font> <font color=Green><u>qualified</u></font> Data<font color=Cyan>.</font>ByteString<font color=Cyan>.</font>Lazy<font color=Cyan>.</font>Char8 <font color=Green><u>as</u></font> FPS
+<a name="line-37"></a>
+<a name="line-38"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>PrettyPrint<font color=Cyan>.</font>HughesPJ <font color=Cyan>(</font>render<font color=Cyan>)</font>
+<a name="line-39"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>ParserCombinators<font color=Cyan>.</font>Poly
+<a name="line-40"></a>
+<a name="line-41"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Types
+<a name="line-42"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>TypeMapping
+<a name="line-43"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Posn     <font color=Cyan>(</font>Posn<font color=Cyan>,</font> posInNewCxt<font color=Cyan>)</font>
+<a name="line-44"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Pretty   <font color=Cyan>(</font>document<font color=Cyan>)</font>
+<a name="line-45"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>Parse    <font color=Cyan>(</font>xmlParse<font color=Cyan>)</font>
+<a name="line-46"></a><font color=Green><u>import</u></font> Text<font color=Cyan>.</font>XML<font color=Cyan>.</font>HaXml<font color=Cyan>.</font>XmlContent<font color=Cyan>.</font>Parser
 <a name="line-47"></a>
-<a name="line-48"></a><font color=Blue>------------------------------------------------------------------------</font>
-<a name="line-49"></a>
-<a name="line-50"></a>        <font color=Blue>-- probably want to write DTD separately from value, and have</font>
-<a name="line-51"></a>        <font color=Blue>-- easy ways to combine DTD + value into a document, or write</font>
-<a name="line-52"></a>        <font color=Blue>-- them to separate files.</font>
-<a name="line-53"></a>
-<a name="line-54"></a><a name="fReadXml"></a><font color=Blue>-- | Read an XML document from a file and convert it to a fully-typed</font>
-<a name="line-55"></a><font color=Blue>--   Haskell value.</font>
-<a name="line-56"></a><font color=Blue>fReadXml</font>  <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> FilePath <font color=Red>-&gt;</font> IO a
-<a name="line-57"></a><font color=Blue>fReadXml</font> fp <font color=Red>=</font> <font color=Green><u>do</u></font>
-<a name="line-58"></a>    f <font color=Red>&lt;-</font> <font color=Cyan>(</font> <font color=Green><u>if</u></font> fp<font color=Cyan>==</font><font color=Magenta>"-"</font> <font color=Green><u>then</u></font> return stdin
-<a name="line-59"></a>           <font color=Green><u>else</u></font> openFile fp ReadMode <font color=Cyan>)</font>
-<a name="line-60"></a>    x <font color=Red>&lt;-</font> hGetContents f
-<a name="line-61"></a>    <font color=Green><u>let</u></font> <font color=Cyan>(</font>Document <font color=Green><u>_</u></font> <font color=Green><u>_</u></font> y <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font> xmlParse fp x
-<a name="line-62"></a>        y' <font color=Red>=</font> CElem y <font color=Cyan>(</font>posInNewCxt fp Nothing<font color=Cyan>)</font>
-<a name="line-63"></a>    either fail return <font color=Cyan>(</font>fst <font color=Cyan>(</font>runParser parseContents <font color=Red>[</font>y'<font color=Red>]</font><font color=Cyan>)</font><font color=Cyan>)</font>
-<a name="line-64"></a>
-<a name="line-65"></a><a name="fWriteXml"></a><font color=Blue>-- | Write a fully-typed Haskell value to the given file as an XML</font>
-<a name="line-66"></a><font color=Blue>--   document.</font>
-<a name="line-67"></a><font color=Blue>fWriteXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> FilePath <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> IO ()
-<a name="line-68"></a><font color=Blue>fWriteXml</font> fp x <font color=Red>=</font> <font color=Green><u>do</u></font>
-<a name="line-69"></a>    f <font color=Red>&lt;-</font> <font color=Cyan>(</font> <font color=Green><u>if</u></font> fp<font color=Cyan>==</font><font color=Magenta>"-"</font> <font color=Green><u>then</u></font> return stdout
-<a name="line-70"></a>           <font color=Green><u>else</u></font> openFile fp WriteMode <font color=Cyan>)</font>
-<a name="line-71"></a>    hPutXml f False x
-<a name="line-72"></a>    hClose f
-<a name="line-73"></a>
-<a name="line-74"></a><a name="fpsWriteXml"></a><font color=Blue>-- | Write any Haskell value to the given file as an XML document,</font>
-<a name="line-75"></a><font color=Blue>--   using the FastPackedString interface (output will not be prettified).</font>
-<a name="line-76"></a><font color=Blue>fpsWriteXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> FilePath <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> IO ()
-<a name="line-77"></a><font color=Blue>fpsWriteXml</font> fp x <font color=Red>=</font> <font color=Green><u>do</u></font>
-<a name="line-78"></a>    f <font color=Red>&lt;-</font> <font color=Cyan>(</font> <font color=Green><u>if</u></font> fp<font color=Cyan>==</font><font color=Magenta>"-"</font> <font color=Green><u>then</u></font> return stdout
-<a name="line-79"></a>           <font color=Green><u>else</u></font> openFile fp WriteMode <font color=Cyan>)</font>
-<a name="line-80"></a>    fpsHPutXml f False x
-<a name="line-81"></a>    hClose f
-<a name="line-82"></a>
-<a name="line-83"></a><a name="readXml"></a><font color=Blue>-- | Read a fully-typed XML document from a string.</font>
-<a name="line-84"></a><font color=Blue>readXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> String <font color=Red>-&gt;</font> Either String a
-<a name="line-85"></a><font color=Blue>readXml</font> s <font color=Red>=</font>
-<a name="line-86"></a>    <font color=Green><u>let</u></font> <font color=Cyan>(</font>Document <font color=Green><u>_</u></font> <font color=Green><u>_</u></font> y <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font> xmlParse <font color=Magenta>"string input"</font> s <font color=Green><u>in</u></font>
-<a name="line-87"></a>    fst <font color=Cyan>(</font>runParser parseContents
-<a name="line-88"></a>                   <font color=Red>[</font>CElem y <font color=Cyan>(</font>posInNewCxt <font color=Magenta>"string input"</font> Nothing<font color=Cyan>)</font><font color=Red>]</font><font color=Cyan>)</font>
-<a name="line-89"></a>
-<a name="line-90"></a><a name="showXml"></a><font color=Blue>-- | Convert a fully-typed XML document to a string (without DTD).</font>
-<a name="line-91"></a><font color=Blue>showXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> String
-<a name="line-92"></a><font color=Blue>showXml</font> dtd x <font color=Red>=</font>
-<a name="line-93"></a>    <font color=Green><u>case</u></font> toContents x <font color=Green><u>of</u></font>
-<a name="line-94"></a>      <font color=Red>[</font>CElem <font color=Green><u>_</u></font> <font color=Green><u>_</u></font><font color=Red>]</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>render <font color=Cyan>.</font> document <font color=Cyan>.</font> toXml dtd<font color=Cyan>)</font> x
-<a name="line-95"></a>      <font color=Green><u>_</u></font> <font color=Red>-&gt;</font> <font color=Magenta>""</font>
-<a name="line-96"></a>
-<a name="line-97"></a><a name="fpsShowXml"></a><font color=Blue>-- | Convert a fully-typed XML document to a ByteString (without DTD).</font>
-<a name="line-98"></a><font color=Blue>fpsShowXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> FPS<font color=Cyan>.</font>ByteString
-<a name="line-99"></a><font color=Blue>fpsShowXml</font> dtd x <font color=Red>=</font>
-<a name="line-100"></a>    <font color=Green><u>case</u></font> toContents x <font color=Green><u>of</u></font>
-<a name="line-101"></a>      <font color=Red>[</font>CElem <font color=Green><u>_</u></font> <font color=Green><u>_</u></font><font color=Red>]</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>FPS<font color=Cyan>.</font>document <font color=Cyan>.</font> toXml dtd<font color=Cyan>)</font> x
-<a name="line-102"></a>      <font color=Green><u>_</u></font> <font color=Red>-&gt;</font> FPS<font color=Cyan>.</font>empty
-<a name="line-103"></a>
+<a name="line-48"></a>
+<a name="line-49"></a><font color=Blue>------------------------------------------------------------------------</font>
+<a name="line-50"></a>
+<a name="line-51"></a>        <font color=Blue>-- probably want to write DTD separately from value, and have</font>
+<a name="line-52"></a>        <font color=Blue>-- easy ways to combine DTD + value into a document, or write</font>
+<a name="line-53"></a>        <font color=Blue>-- them to separate files.</font>
+<a name="line-54"></a>
+<a name="line-55"></a><a name="fReadXml"></a><font color=Blue>-- | Read an XML document from a file and convert it to a fully-typed</font>
+<a name="line-56"></a><font color=Blue>--   Haskell value.</font>
+<a name="line-57"></a><font color=Blue>fReadXml</font>  <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> FilePath <font color=Red>-&gt;</font> IO a
+<a name="line-58"></a><font color=Blue>fReadXml</font> fp <font color=Red>=</font> <font color=Green><u>do</u></font>
+<a name="line-59"></a>    f <font color=Red>&lt;-</font> <font color=Cyan>(</font> <font color=Green><u>if</u></font> fp<font color=Cyan>==</font><font color=Magenta>"-"</font> <font color=Green><u>then</u></font> return stdin
+<a name="line-60"></a>           <font color=Green><u>else</u></font> openFile fp ReadMode <font color=Cyan>)</font>
+<a name="line-61"></a>    x <font color=Red>&lt;-</font> hGetContents f
+<a name="line-62"></a>    <font color=Green><u>let</u></font> <font color=Cyan>(</font>Document <font color=Green><u>_</u></font> <font color=Green><u>_</u></font> y <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font> xmlParse fp x
+<a name="line-63"></a>        y' <font color=Red>=</font> CElem y <font color=Cyan>(</font>posInNewCxt fp Nothing<font color=Cyan>)</font>
+<a name="line-64"></a>    either fail return <font color=Cyan>(</font>fst <font color=Cyan>(</font>runParser parseContents <font color=Red>[</font>y'<font color=Red>]</font><font color=Cyan>)</font><font color=Cyan>)</font>
+<a name="line-65"></a>
+<a name="line-66"></a><a name="fWriteXml"></a><font color=Blue>-- | Write a fully-typed Haskell value to the given file as an XML</font>
+<a name="line-67"></a><font color=Blue>--   document.</font>
+<a name="line-68"></a><font color=Blue>fWriteXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> FilePath <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> IO ()
+<a name="line-69"></a><font color=Blue>fWriteXml</font> fp x <font color=Red>=</font> <font color=Green><u>do</u></font>
+<a name="line-70"></a>    f <font color=Red>&lt;-</font> <font color=Cyan>(</font> <font color=Green><u>if</u></font> fp<font color=Cyan>==</font><font color=Magenta>"-"</font> <font color=Green><u>then</u></font> return stdout
+<a name="line-71"></a>           <font color=Green><u>else</u></font> openFile fp WriteMode <font color=Cyan>)</font>
+<a name="line-72"></a>    hPutXml f False x
+<a name="line-73"></a>    hClose f
+<a name="line-74"></a>
+<a name="line-75"></a><a name="fpsWriteXml"></a><font color=Blue>-- | Write any Haskell value to the given file as an XML document,</font>
+<a name="line-76"></a><font color=Blue>--   using the FastPackedString interface (output will not be prettified).</font>
+<a name="line-77"></a><font color=Blue>fpsWriteXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> FilePath <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> IO ()
+<a name="line-78"></a><font color=Blue>fpsWriteXml</font> fp x <font color=Red>=</font> <font color=Green><u>do</u></font>
+<a name="line-79"></a>    f <font color=Red>&lt;-</font> <font color=Cyan>(</font> <font color=Green><u>if</u></font> fp<font color=Cyan>==</font><font color=Magenta>"-"</font> <font color=Green><u>then</u></font> return stdout
+<a name="line-80"></a>           <font color=Green><u>else</u></font> openFile fp WriteMode <font color=Cyan>)</font>
+<a name="line-81"></a>    fpsHPutXml f False x
+<a name="line-82"></a>    hClose f
+<a name="line-83"></a>
+<a name="line-84"></a><a name="readXml"></a><font color=Blue>-- | Read a fully-typed XML document from a string.</font>
+<a name="line-85"></a><font color=Blue>readXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> String <font color=Red>-&gt;</font> Either String a
+<a name="line-86"></a><font color=Blue>readXml</font> s <font color=Red>=</font>
+<a name="line-87"></a>    <font color=Green><u>let</u></font> <font color=Cyan>(</font>Document <font color=Green><u>_</u></font> <font color=Green><u>_</u></font> y <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font> xmlParse <font color=Magenta>"string input"</font> s <font color=Green><u>in</u></font>
+<a name="line-88"></a>    fst <font color=Cyan>(</font>runParser parseContents
+<a name="line-89"></a>                   <font color=Red>[</font>CElem y <font color=Cyan>(</font>posInNewCxt <font color=Magenta>"string input"</font> Nothing<font color=Cyan>)</font><font color=Red>]</font><font color=Cyan>)</font>
+<a name="line-90"></a>
+<a name="line-91"></a><a name="showXml"></a><font color=Blue>-- | Convert a fully-typed XML document to a string (without DTD).</font>
+<a name="line-92"></a><font color=Blue>showXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> String
+<a name="line-93"></a><font color=Blue>showXml</font> dtd x <font color=Red>=</font>
+<a name="line-94"></a>    <font color=Green><u>case</u></font> toContents x <font color=Green><u>of</u></font>
+<a name="line-95"></a>      <font color=Red>[</font>CElem <font color=Green><u>_</u></font> <font color=Green><u>_</u></font><font color=Red>]</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>render <font color=Cyan>.</font> document <font color=Cyan>.</font> toXml dtd<font color=Cyan>)</font> x
+<a name="line-96"></a>      <font color=Green><u>_</u></font> <font color=Red>-&gt;</font> <font color=Magenta>""</font>
+<a name="line-97"></a>
+<a name="line-98"></a><a name="fpsShowXml"></a><font color=Blue>-- | Convert a fully-typed XML document to a ByteString (without DTD).</font>
+<a name="line-99"></a><font color=Blue>fpsShowXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> FPS<font color=Cyan>.</font>ByteString
+<a name="line-100"></a><font color=Blue>fpsShowXml</font> dtd x <font color=Red>=</font>
+<a name="line-101"></a>    <font color=Green><u>case</u></font> toContents x <font color=Green><u>of</u></font>
+<a name="line-102"></a>      <font color=Red>[</font>CElem <font color=Green><u>_</u></font> <font color=Green><u>_</u></font><font color=Red>]</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>FPS<font color=Cyan>.</font>document <font color=Cyan>.</font> toXml dtd<font color=Cyan>)</font> x
+<a name="line-103"></a>      <font color=Green><u>_</u></font> <font color=Red>-&gt;</font> FPS<font color=Cyan>.</font>empty
 <a name="line-104"></a>
-<a name="line-105"></a><a name="toXml"></a><font color=Blue>-- | Convert a fully-typed XML document to a string (with or without DTD).</font>
-<a name="line-106"></a><font color=Blue>toXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> Document ()
-<a name="line-107"></a><font color=Blue>toXml</font> dtd value <font color=Red>=</font>
-<a name="line-108"></a>    <font color=Green><u>let</u></font> ht <font color=Red>=</font> toHType value <font color=Green><u>in</u></font>
-<a name="line-109"></a>    Document <font color=Cyan>(</font>Prolog <font color=Cyan>(</font>Just <font color=Cyan>(</font>XMLDecl <font color=Magenta>"1.0"</font> Nothing Nothing<font color=Cyan>)</font><font color=Cyan>)</font>
-<a name="line-110"></a>                     [] <font color=Cyan>(</font><font color=Green><u>if</u></font> dtd <font color=Green><u>then</u></font> Just <font color=Cyan>(</font>toDTD ht<font color=Cyan>)</font> <font color=Green><u>else</u></font> Nothing<font color=Cyan>)</font> []<font color=Cyan>)</font>
-<a name="line-111"></a>             emptyST
-<a name="line-112"></a>             <font color=Cyan>(</font> <font color=Green><u>case</u></font> toContents value <font color=Green><u>of</u></font>
-<a name="line-113"></a>                 []             <font color=Red>-&gt;</font> Elem <font color=Magenta>"empty"</font> [] []
-<a name="line-114"></a>                 <font color=Red>[</font>CElem e ()<font color=Red>]</font>   <font color=Red>-&gt;</font> e
-<a name="line-115"></a>                 <font color=Cyan>(</font>CElem e ()<font color=Red><b>:</b></font><font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> error <font color=Magenta>"too many XML elements in document"</font> <font color=Cyan>)</font>
-<a name="line-116"></a>             []
-<a name="line-117"></a>
-<a name="line-118"></a><a name="fromXml"></a><font color=Blue>-- | Read a Haskell value from an XML document, ignoring the DTD and</font>
-<a name="line-119"></a><font color=Blue>--   using the Haskell result type to determine how to parse it.</font>
-<a name="line-120"></a><font color=Blue>fromXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Document Posn <font color=Red>-&gt;</font> Either String a
-<a name="line-121"></a><font color=Blue>fromXml</font> <font color=Cyan>(</font>Document <font color=Green><u>_</u></font> <font color=Green><u>_</u></font> e<font color=Red>@</font><font color=Cyan>(</font>Elem n <font color=Green><u>_</u></font> cs<font color=Cyan>)</font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font>
-<a name="line-122"></a>  fst <font color=Cyan>(</font>runParser parseContents <font color=Red>[</font>CElem e <font color=Cyan>(</font>posInNewCxt <font color=Magenta>"document"</font> Nothing<font color=Cyan>)</font><font color=Red>]</font><font color=Cyan>)</font>
-<a name="line-123"></a>
+<a name="line-105"></a>
+<a name="line-106"></a><a name="toXml"></a><font color=Blue>-- | Convert a fully-typed XML document to a string (with or without DTD).</font>
+<a name="line-107"></a><font color=Blue>toXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> Document ()
+<a name="line-108"></a><font color=Blue>toXml</font> dtd value <font color=Red>=</font>
+<a name="line-109"></a>    <font color=Green><u>let</u></font> ht <font color=Red>=</font> toHType value <font color=Green><u>in</u></font>
+<a name="line-110"></a>    Document <font color=Cyan>(</font>Prolog <font color=Cyan>(</font>Just <font color=Cyan>(</font>XMLDecl <font color=Magenta>"1.0"</font> Nothing Nothing<font color=Cyan>)</font><font color=Cyan>)</font>
+<a name="line-111"></a>                     [] <font color=Cyan>(</font><font color=Green><u>if</u></font> dtd <font color=Green><u>then</u></font> Just <font color=Cyan>(</font>toDTD ht<font color=Cyan>)</font> <font color=Green><u>else</u></font> Nothing<font color=Cyan>)</font> []<font color=Cyan>)</font>
+<a name="line-112"></a>             emptyST
+<a name="line-113"></a>             <font color=Cyan>(</font> <font color=Green><u>case</u></font> toContents value <font color=Green><u>of</u></font>
+<a name="line-114"></a>                 []             <font color=Red>-&gt;</font> Elem <font color=Magenta>"empty"</font> [] []
+<a name="line-115"></a>                 <font color=Red>[</font>CElem e ()<font color=Red>]</font>   <font color=Red>-&gt;</font> e
+<a name="line-116"></a>                 <font color=Cyan>(</font>CElem e ()<font color=Red><b>:</b></font><font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> error <font color=Magenta>"too many XML elements in document"</font> <font color=Cyan>)</font>
+<a name="line-117"></a>             []
+<a name="line-118"></a>
+<a name="line-119"></a><a name="fromXml"></a><font color=Blue>-- | Read a Haskell value from an XML document, ignoring the DTD and</font>
+<a name="line-120"></a><font color=Blue>--   using the Haskell result type to determine how to parse it.</font>
+<a name="line-121"></a><font color=Blue>fromXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Document Posn <font color=Red>-&gt;</font> Either String a
+<a name="line-122"></a><font color=Blue>fromXml</font> <font color=Cyan>(</font>Document <font color=Green><u>_</u></font> <font color=Green><u>_</u></font> e<font color=Red>@</font><font color=Cyan>(</font>Elem n <font color=Green><u>_</u></font> cs<font color=Cyan>)</font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font>
+<a name="line-123"></a>  fst <font color=Cyan>(</font>runParser parseContents <font color=Red>[</font>CElem e <font color=Cyan>(</font>posInNewCxt <font color=Magenta>"document"</font> Nothing<font color=Cyan>)</font><font color=Red>]</font><font color=Cyan>)</font>
 <a name="line-124"></a>
-<a name="line-125"></a><a name="hGetXml"></a><font color=Blue>-- | Read a fully-typed XML document from a file handle.</font>
-<a name="line-126"></a><font color=Blue>hGetXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Handle <font color=Red>-&gt;</font> IO a
-<a name="line-127"></a><font color=Blue>hGetXml</font> h <font color=Red>=</font> <font color=Green><u>do</u></font>
-<a name="line-128"></a>    x <font color=Red>&lt;-</font> hGetContents h
-<a name="line-129"></a>    <font color=Green><u>let</u></font> <font color=Cyan>(</font>Document <font color=Green><u>_</u></font> <font color=Green><u>_</u></font> y <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font> xmlParse <font color=Magenta>"file handle"</font> x
-<a name="line-130"></a>    either fail return
-<a name="line-131"></a>           <font color=Cyan>(</font>fst <font color=Cyan>(</font>runParser parseContents
-<a name="line-132"></a>                           <font color=Red>[</font>CElem y <font color=Cyan>(</font>posInNewCxt <font color=Magenta>"file handle"</font> Nothing<font color=Cyan>)</font><font color=Red>]</font><font color=Cyan>)</font><font color=Cyan>)</font>
-<a name="line-133"></a>
-<a name="line-134"></a><a name="hPutXml"></a><font color=Blue>-- | Write a fully-typed XML document to a file handle.</font>
-<a name="line-135"></a><font color=Blue>hPutXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Handle <font color=Red>-&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> IO ()
-<a name="line-136"></a><font color=Blue>hPutXml</font> h dtd x <font color=Red>=</font> <font color=Green><u>do</u></font>
-<a name="line-137"></a>    <font color=Cyan>(</font>hPutStrLn h <font color=Cyan>.</font> render <font color=Cyan>.</font> document <font color=Cyan>.</font> toXml dtd<font color=Cyan>)</font> x
-<a name="line-138"></a>
-<a name="line-139"></a><a name="fpsHPutXml"></a><font color=Blue>-- | Write a fully-typed XML document to a file handle, using the</font>
-<a name="line-140"></a><font color=Blue>--   FastPackedString interface (output will not be prettified).</font>
-<a name="line-141"></a><font color=Blue>fpsHPutXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Handle <font color=Red>-&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> IO ()
-<a name="line-142"></a><font color=Blue>fpsHPutXml</font> h dtd x <font color=Red>=</font> <font color=Green><u>do</u></font>
-<a name="line-143"></a>    <font color=Cyan>(</font>FPS<font color=Cyan>.</font>hPut h <font color=Cyan>.</font> FPS<font color=Cyan>.</font>document <font color=Cyan>.</font> toXml dtd<font color=Cyan>)</font> x
-<a name="line-144"></a>
+<a name="line-125"></a>
+<a name="line-126"></a><a name="hGetXml"></a><font color=Blue>-- | Read a fully-typed XML document from a file handle.</font>
+<a name="line-127"></a><font color=Blue>hGetXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Handle <font color=Red>-&gt;</font> IO a
+<a name="line-128"></a><font color=Blue>hGetXml</font> h <font color=Red>=</font> <font color=Green><u>do</u></font>
+<a name="line-129"></a>    x <font color=Red>&lt;-</font> hGetContents h
+<a name="line-130"></a>    <font color=Green><u>let</u></font> <font color=Cyan>(</font>Document <font color=Green><u>_</u></font> <font color=Green><u>_</u></font> y <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font> xmlParse <font color=Magenta>"file handle"</font> x
+<a name="line-131"></a>    either fail return
+<a name="line-132"></a>           <font color=Cyan>(</font>fst <font color=Cyan>(</font>runParser parseContents
+<a name="line-133"></a>                           <font color=Red>[</font>CElem y <font color=Cyan>(</font>posInNewCxt <font color=Magenta>"file handle"</font> Nothing<font color=Cyan>)</font><font color=Red>]</font><font color=Cyan>)</font><font color=Cyan>)</font>
+<a name="line-134"></a>
+<a name="line-135"></a><a name="hPutXml"></a><font color=Blue>-- | Write a fully-typed XML document to a file handle.</font>
+<a name="line-136"></a><font color=Blue>hPutXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Handle <font color=Red>-&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> IO ()
+<a name="line-137"></a><font color=Blue>hPutXml</font> h dtd x <font color=Red>=</font> <font color=Green><u>do</u></font>
+<a name="line-138"></a>    <font color=Cyan>(</font>hPutStrLn h <font color=Cyan>.</font> render <font color=Cyan>.</font> document <font color=Cyan>.</font> toXml dtd<font color=Cyan>)</font> x
+<a name="line-139"></a>
+<a name="line-140"></a><a name="fpsHPutXml"></a><font color=Blue>-- | Write a fully-typed XML document to a file handle, using the</font>
+<a name="line-141"></a><font color=Blue>--   FastPackedString interface (output will not be prettified).</font>
+<a name="line-142"></a><font color=Blue>fpsHPutXml</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> Handle <font color=Red>-&gt;</font> Bool <font color=Red>-&gt;</font> a <font color=Red>-&gt;</font> IO ()
+<a name="line-143"></a><font color=Blue>fpsHPutXml</font> h dtd x <font color=Red>=</font> <font color=Green><u>do</u></font>
+<a name="line-144"></a>    <font color=Cyan>(</font>FPS<font color=Cyan>.</font>hPut h <font color=Cyan>.</font> FPS<font color=Cyan>.</font>document <font color=Cyan>.</font> toXml dtd<font color=Cyan>)</font> x
 <a name="line-145"></a>
-<a name="line-146"></a><font color=Blue>------------------------------------------------------------------------</font>
-<a name="line-147"></a><font color=Blue>-- Instances for all the standard basic datatypes.</font>
-<a name="line-148"></a><font color=Blue>-- DtdToHaskell uses only a small number of standard datatypes.</font>
-<a name="line-149"></a><font color=Blue>------------------------------------------------------------------------</font>
-<a name="line-150"></a>
-<a name="line-151"></a><font color=Green><u>instance</u></font> XmlContent Char <font color=Green><u>where</u></font>
-<a name="line-152"></a>    <font color=Blue>-- NOT in a string</font>
-<a name="line-153"></a>    toContents c  <font color=Red>=</font> error <font color=Magenta>"Text.XML.HaXml.XmlContent.toContents used on a Haskell Char"</font>
-<a name="line-154"></a>    parseContents <font color=Red>=</font> fail <font color=Magenta>"Text.XML.HaXml.XmlContent.parseContents used on a Haskell Char "</font>
-<a name="line-155"></a>    <font color=Blue>-- Only defined for Char and no other types:</font>
-<a name="line-156"></a>    xToChar   <font color=Red>=</font> id
-<a name="line-157"></a>    xFromChar <font color=Red>=</font> id
-<a name="line-158"></a>
-<a name="line-159"></a><font color=Green><u>instance</u></font> XmlContent a <font color=Red>=&gt;</font> XmlContent <font color=Red>[</font>a<font color=Red>]</font> <font color=Green><u>where</u></font>
-<a name="line-160"></a>    toContents xs  <font color=Red>=</font> <font color=Green><u>case</u></font> toHType x <font color=Green><u>of</u></font>
-<a name="line-161"></a>                       <font color=Cyan>(</font>Prim <font color=Magenta>"Char"</font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font>
-<a name="line-162"></a>                            <font color=Red>[</font>CString True <font color=Cyan>(</font>map xToChar xs<font color=Cyan>)</font> ()<font color=Red>]</font>
-<a name="line-163"></a>                       <font color=Green><u>_</u></font> <font color=Red>-&gt;</font> concatMap toContents xs
-<a name="line-164"></a>                   <font color=Green><u>where</u></font>   <font color=Cyan>(</font>x<font color=Red><b>:</b></font><font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font> xs
-<a name="line-165"></a>    parseContents <font color=Red>=</font> <font color=Green><u>let</u></font> <font color=Cyan>(</font>Right <font color=Cyan>(</font>x<font color=Red><b>:</b></font><font color=Green><u>_</u></font><font color=Cyan>)</font><font color=Cyan>,</font><font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font> runParser p [] <font color=Blue>-- for type of x only</font>
-<a name="line-166"></a>                        p <font color=Red>=</font> <font color=Green><u>case</u></font> toHType x <font color=Green><u>of</u></font>
-<a name="line-167"></a>                              <font color=Cyan>(</font>Prim <font color=Magenta>"Char"</font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> fmap <font color=Cyan>(</font>map xFromChar<font color=Cyan>)</font> <font color=Cyan>$</font> text
-<a name="line-168"></a>                              <font color=Green><u>_</u></font> <font color=Red>-&gt;</font> many parseContents
-<a name="line-169"></a>                    <font color=Green><u>in</u></font> p
-<a name="line-170"></a>        <font color=Blue>-- comments, PIs, etc, are skipped in the individual element parser.</font>
-<a name="line-171"></a>
-<a name="line-172"></a><font color=Green><u>instance</u></font> <font color=Cyan>(</font>XmlContent a<font color=Cyan>)</font> <font color=Red>=&gt;</font> XmlContent <font color=Cyan>(</font>Maybe a<font color=Cyan>)</font> <font color=Green><u>where</u></font>
-<a name="line-173"></a>    toContents m  <font color=Red>=</font> maybe [] toContents m
-<a name="line-174"></a>    parseContents <font color=Red>=</font> optional parseContents
-<a name="line-175"></a>
-<a name="line-176"></a><font color=Blue>------------------------------------------------------------------------</font>
+<a name="line-146"></a>
+<a name="line-147"></a><font color=Blue>------------------------------------------------------------------------</font>
+<a name="line-148"></a><font color=Blue>-- Instances for all the standard basic datatypes.</font>
+<a name="line-149"></a><font color=Blue>-- DtdToHaskell uses only a small number of standard datatypes.</font>
+<a name="line-150"></a><font color=Blue>------------------------------------------------------------------------</font>
+<a name="line-151"></a>
+<a name="line-152"></a><font color=Green><u>instance</u></font> XmlContent Char <font color=Green><u>where</u></font>
+<a name="line-153"></a>    <font color=Blue>-- NOT in a string</font>
+<a name="line-154"></a>    toContents c  <font color=Red>=</font> error <font color=Magenta>"Text.XML.HaXml.XmlContent.toContents used on a Haskell Char"</font>
+<a name="line-155"></a>    parseContents <font color=Red>=</font> fail <font color=Magenta>"Text.XML.HaXml.XmlContent.parseContents used on a Haskell Char "</font>
+<a name="line-156"></a>    <font color=Blue>-- Only defined for Char and no other types:</font>
+<a name="line-157"></a>    xToChar   <font color=Red>=</font> id
+<a name="line-158"></a>    xFromChar <font color=Red>=</font> id
+<a name="line-159"></a>
+<a name="line-160"></a><font color=Green><u>instance</u></font> XmlContent a <font color=Red>=&gt;</font> XmlContent <font color=Red>[</font>a<font color=Red>]</font> <font color=Green><u>where</u></font>
+<a name="line-161"></a>    toContents xs  <font color=Red>=</font> <font color=Green><u>case</u></font> toHType x <font color=Green><u>of</u></font>
+<a name="line-162"></a>                       <font color=Cyan>(</font>Prim <font color=Magenta>"Char"</font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font>
+<a name="line-163"></a>                            <font color=Red>[</font>CString True <font color=Cyan>(</font>map xToChar xs<font color=Cyan>)</font> ()<font color=Red>]</font>
+<a name="line-164"></a>                       <font color=Green><u>_</u></font> <font color=Red>-&gt;</font> concatMap toContents xs
+<a name="line-165"></a>                   <font color=Green><u>where</u></font>   <font color=Cyan>(</font>x<font color=Red><b>:</b></font><font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>=</font> xs
+<a name="line-166"></a>    parseContents <font color=Red>=</font> <font color=Green><u>let</u></font> result <font color=Red>=</font> runParser p [] <font color=Blue>-- for type of result only</font>
+<a name="line-167"></a>                        p <font color=Red>=</font> <font color=Green><u>case</u></font> <font color=Cyan>(</font>toHType <font color=Cyan>.</font> head <font color=Cyan>.</font> <font color=Cyan>(</font><font color=Red>\</font> <font color=Cyan>(</font>Right x<font color=Cyan>)</font><font color=Red>-&gt;</font>x<font color=Cyan>)</font> <font color=Cyan>.</font> fst<font color=Cyan>)</font>
+<a name="line-168"></a>                                 result <font color=Green><u>of</u></font>
+<a name="line-169"></a>                              <font color=Cyan>(</font>Prim <font color=Magenta>"Char"</font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> fmap <font color=Cyan>(</font>map xFromChar<font color=Cyan>)</font> <font color=Cyan>$</font> text
+<a name="line-170"></a>                              <font color=Green><u>_</u></font> <font color=Red>-&gt;</font> many parseContents
+<a name="line-171"></a>                    <font color=Green><u>in</u></font> p
+<a name="line-172"></a>        <font color=Blue>-- comments, PIs, etc, are skipped in the individual element parser.</font>
+<a name="line-173"></a>
+<a name="line-174"></a><font color=Green><u>instance</u></font> <font color=Cyan>(</font>XmlContent a<font color=Cyan>)</font> <font color=Red>=&gt;</font> XmlContent <font color=Cyan>(</font>Maybe a<font color=Cyan>)</font> <font color=Green><u>where</u></font>
+<a name="line-175"></a>    toContents m  <font color=Red>=</font> maybe [] toContents m
+<a name="line-176"></a>    parseContents <font color=Red>=</font> optional parseContents
+<a name="line-177"></a>
+<a name="line-178"></a><font color=Blue>------------------------------------------------------------------------</font>
 </pre>
 </body>
 </html>
diff --git a/docs/HaXml/src/Text/XML/HaXml/XmlContent/Haskell.html b/docs/HaXml/src/Text/XML/HaXml/XmlContent/Haskell.html
--- a/docs/HaXml/src/Text/XML/HaXml/XmlContent/Haskell.html
+++ b/docs/HaXml/src/Text/XML/HaXml/XmlContent/Haskell.html
@@ -198,65 +198,61 @@
 <a name="line-191"></a>    parseContents <font color=Red>=</font> P <font color=Cyan>(</font><font color=Red>\</font>x <font color=Red>-&gt;</font>
 <a name="line-192"></a>        <font color=Green><u>case</u></font> x <font color=Green><u>of</u></font>
 <a name="line-193"></a>            <font color=Cyan>(</font>CString <font color=Green><u>_</u></font> s <font color=Green><u>_</u></font><font color=Red><b>:</b></font>cs<font color=Cyan>)</font>
-<a name="line-194"></a>                   <font color=Red>-&gt;</font> <font color=Cyan>(</font>Right <font color=Cyan>(</font>map xFromChar s<font color=Cyan>)</font><font color=Cyan>,</font> cs<font color=Cyan>)</font>
+<a name="line-194"></a>                   <font color=Red>-&gt;</font> Success cs <font color=Cyan>(</font>map xFromChar s<font color=Cyan>)</font>
 <a name="line-195"></a>            <font color=Cyan>(</font>CElem <font color=Cyan>(</font>Elem <font color=Magenta>"string"</font> [] <font color=Red>[</font>CString <font color=Green><u>_</u></font> s <font color=Green><u>_</u></font><font color=Red>]</font><font color=Cyan>)</font> <font color=Green><u>_</u></font><font color=Red><b>:</b></font>cs<font color=Cyan>)</font>
-<a name="line-196"></a>                   <font color=Red>-&gt;</font> <font color=Cyan>(</font>Right <font color=Cyan>(</font>map xFromChar s<font color=Cyan>)</font><font color=Cyan>,</font> cs<font color=Cyan>)</font>
+<a name="line-196"></a>                   <font color=Red>-&gt;</font> Success cs <font color=Cyan>(</font>map xFromChar s<font color=Cyan>)</font>
 <a name="line-197"></a>            <font color=Cyan>(</font>CElem <font color=Cyan>(</font>Elem e [] xs<font color=Cyan>)</font> <font color=Green><u>_</u></font><font color=Red><b>:</b></font>cs<font color=Cyan>)</font> <font color=Red>|</font> <font color=Magenta>"list"</font> <font color=Cyan>`isPrefixOf`</font> e
 <a name="line-198"></a>                   <font color=Red>-&gt;</font> scanElements xs
 <a name="line-199"></a>                   <font color=Green><u>where</u></font>
 <a name="line-200"></a>                  <font color=Blue>-- scanElements :: [Content] -&gt; (Either String [a],[Content])</font>
-<a name="line-201"></a>                     scanElements [] <font color=Red>=</font> <font color=Cyan>(</font>Right []<font color=Cyan>,</font> cs<font color=Cyan>)</font>
+<a name="line-201"></a>                     scanElements [] <font color=Red>=</font> Success cs []
 <a name="line-202"></a>                     scanElements es <font color=Red>=</font>
 <a name="line-203"></a>                        <font color=Green><u>case</u></font> runParser parseContents es <font color=Green><u>of</u></font>
-<a name="line-204"></a>                            <font color=Cyan>(</font>Left msg<font color=Cyan>,</font> es'<font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False<font color=Cyan>,</font>msg<font color=Cyan>)</font><font color=Cyan>,</font> es'<font color=Cyan>)</font>
+<a name="line-204"></a>                            <font color=Cyan>(</font>Left msg<font color=Cyan>,</font> es'<font color=Cyan>)</font> <font color=Red>-&gt;</font> Failure es' msg
 <a name="line-205"></a>                            <font color=Cyan>(</font>Right y<font color=Cyan>,</font> es'<font color=Cyan>)</font> <font color=Red>-&gt;</font>
 <a name="line-206"></a>                                <font color=Green><u>case</u></font> scanElements es' <font color=Green><u>of</u></font>
-<a name="line-207"></a>                                    <font color=Cyan>(</font>Left msg<font color=Cyan>,</font> ds<font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left msg<font color=Cyan>,</font> ds<font color=Cyan>)</font>
-<a name="line-208"></a>                                    <font color=Cyan>(</font>Right ys<font color=Cyan>,</font> ds<font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Right <font color=Cyan>(</font>y<font color=Red><b>:</b></font>ys<font color=Cyan>)</font><font color=Cyan>,</font> ds<font color=Cyan>)</font>
+<a name="line-207"></a>                                    Failure ds msg <font color=Red>-&gt;</font> Failure ds msg
+<a name="line-208"></a>                                    Success ds ys  <font color=Red>-&gt;</font> Success ds <font color=Cyan>(</font>y<font color=Red><b>:</b></font>ys<font color=Cyan>)</font>
 <a name="line-209"></a>            <font color=Cyan>(</font>CElem <font color=Cyan>(</font>Elem e <font color=Green><u>_</u></font> <font color=Green><u>_</u></font><font color=Cyan>)</font> pos<font color=Red><b>:</b></font> cs<font color=Cyan>)</font>
-<a name="line-210"></a>                   <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False
-<a name="line-211"></a>                            <font color=Cyan>,</font><font color=Magenta>"Expected a &lt;list-...&gt;, but found a &lt;"</font><font color=Cyan>++</font>e<font color=Cyan>++</font><font color=Magenta>"&gt; at\n"</font>
-<a name="line-212"></a>                            <font color=Cyan>++</font> show pos<font color=Cyan>)</font><font color=Cyan>,</font> cs<font color=Cyan>)</font>
-<a name="line-213"></a>            <font color=Cyan>(</font>CRef r pos<font color=Red><b>:</b></font> cs<font color=Cyan>)</font>
-<a name="line-214"></a>                   <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False
-<a name="line-215"></a>                            <font color=Cyan>,</font><font color=Magenta>"Expected a &lt;list-...&gt;, but found a ref "</font>
-<a name="line-216"></a>                            <font color=Cyan>++</font>verbatim r<font color=Cyan>++</font><font color=Magenta>" at\n"</font><font color=Cyan>++</font> show pos<font color=Cyan>)</font><font color=Cyan>,</font> cs<font color=Cyan>)</font>
-<a name="line-217"></a>            <font color=Cyan>(</font><font color=Green><u>_</u></font><font color=Red><b>:</b></font>cs<font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font><font color=Cyan>(</font><font color=Red>\</font> <font color=Cyan>(</font>P p<font color=Cyan>)</font><font color=Red>-&gt;</font> p<font color=Cyan>)</font> parseContents<font color=Cyan>)</font> cs  <font color=Blue>-- skip comments etc.</font>
-<a name="line-218"></a>            []     <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False
-<a name="line-219"></a>                            <font color=Cyan>,</font><font color=Magenta>"Ran out of input XML whilst secondary parsing"</font><font color=Cyan>)</font>
-<a name="line-220"></a>                      <font color=Cyan>,</font> []<font color=Cyan>)</font>
-<a name="line-221"></a>        <font color=Cyan>)</font>
+<a name="line-210"></a>                   <font color=Red>-&gt;</font> Failure cs <font color=Cyan>(</font><font color=Magenta>"Expected a &lt;list-...&gt;, but found a &lt;"</font><font color=Cyan>++</font>e
+<a name="line-211"></a>                                  <font color=Cyan>++</font><font color=Magenta>"&gt; at\n"</font><font color=Cyan>++</font>show pos<font color=Cyan>)</font>
+<a name="line-212"></a>            <font color=Cyan>(</font>CRef r pos<font color=Red><b>:</b></font> cs<font color=Cyan>)</font>
+<a name="line-213"></a>                   <font color=Red>-&gt;</font> Failure cs <font color=Cyan>(</font><font color=Magenta>"Expected a &lt;list-...&gt;, but found a ref "</font>
+<a name="line-214"></a>                                  <font color=Cyan>++</font>verbatim r<font color=Cyan>++</font><font color=Magenta>" at\n"</font><font color=Cyan>++</font> show pos<font color=Cyan>)</font>
+<a name="line-215"></a>            <font color=Cyan>(</font><font color=Green><u>_</u></font><font color=Red><b>:</b></font>cs<font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font><font color=Cyan>(</font><font color=Red>\</font> <font color=Cyan>(</font>P p<font color=Cyan>)</font><font color=Red>-&gt;</font> p<font color=Cyan>)</font> parseContents<font color=Cyan>)</font> cs  <font color=Blue>-- skip comments etc.</font>
+<a name="line-216"></a>            []     <font color=Red>-&gt;</font> Failure [] <font color=Magenta>"Ran out of input XML whilst secondary parsing"</font>
+<a name="line-217"></a>        <font color=Cyan>)</font>
+<a name="line-218"></a>
+<a name="line-219"></a><font color=Green><u>instance</u></font> XmlContent () <font color=Green><u>where</u></font>
+<a name="line-220"></a>    toContents ()  <font color=Red>=</font> <font color=Red>[</font>CElem <font color=Cyan>(</font>Elem <font color=Magenta>"unit"</font> [] []<font color=Cyan>)</font> ()<font color=Red>]</font>
+<a name="line-221"></a>    parseContents <font color=Red>=</font> <font color=Green><u>do</u></font> <font color=Cyan>{</font> element <font color=Red>[</font><font color=Magenta>"unit"</font><font color=Red>]</font><font color=Cyan>;</font> return () <font color=Cyan>}</font>
 <a name="line-222"></a>
-<a name="line-223"></a><font color=Green><u>instance</u></font> XmlContent () <font color=Green><u>where</u></font>
-<a name="line-224"></a>    toContents ()  <font color=Red>=</font> <font color=Red>[</font>CElem <font color=Cyan>(</font>Elem <font color=Magenta>"unit"</font> [] []<font color=Cyan>)</font> ()<font color=Red>]</font>
-<a name="line-225"></a>    parseContents <font color=Red>=</font> <font color=Green><u>do</u></font> <font color=Cyan>{</font> element <font color=Red>[</font><font color=Magenta>"unit"</font><font color=Red>]</font><font color=Cyan>;</font> return () <font color=Cyan>}</font>
-<a name="line-226"></a>
-<a name="line-227"></a>
-<a name="line-228"></a><font color=Green><u>instance</u></font> <font color=Cyan>(</font>XmlContent a<font color=Cyan>)</font> <font color=Red>=&gt;</font> XmlContent <font color=Cyan>(</font>Maybe a<font color=Cyan>)</font> <font color=Green><u>where</u></font>
-<a name="line-229"></a>    toContents m   <font color=Red>=</font> <font color=Red>[</font>mkElem m <font color=Cyan>(</font>maybe [] toContents m<font color=Cyan>)</font><font color=Red>]</font>
-<a name="line-230"></a>    parseContents <font color=Red>=</font> <font color=Green><u>do</u></font>
-<a name="line-231"></a>        <font color=Cyan>{</font> e <font color=Red>&lt;-</font> elementWith <font color=Cyan>(</font>flip isPrefixOf<font color=Cyan>)</font> <font color=Red>[</font><font color=Magenta>"maybe"</font><font color=Red>]</font>
-<a name="line-232"></a>        <font color=Cyan>;</font> <font color=Green><u>case</u></font> e <font color=Green><u>of</u></font> <font color=Cyan>(</font>Elem <font color=Green><u>_</u></font> [] []<font color=Cyan>)</font> <font color=Red>-&gt;</font> return Nothing
-<a name="line-233"></a>                    <font color=Cyan>(</font>Elem <font color=Green><u>_</u></font> [] <font color=Green><u>_</u></font><font color=Cyan>)</font>  <font color=Red>-&gt;</font> fmap Just <font color=Cyan>(</font>interior e parseContents<font color=Cyan>)</font>
-<a name="line-234"></a>        <font color=Cyan>}</font>
-<a name="line-235"></a>
-<a name="line-236"></a><font color=Green><u>instance</u></font> <font color=Cyan>(</font>XmlContent a<font color=Cyan>,</font> XmlContent b<font color=Cyan>)</font> <font color=Red>=&gt;</font> XmlContent <font color=Cyan>(</font>Either a b<font color=Cyan>)</font> <font color=Green><u>where</u></font>
-<a name="line-237"></a>    toContents v<font color=Red>@</font><font color=Cyan>(</font>Left aa<font color=Cyan>)</font> <font color=Red>=</font>
-<a name="line-238"></a>        <font color=Red>[</font>mkElemC <font color=Cyan>(</font>showConstr <font color=Magenta>0</font> <font color=Cyan>(</font>toHType v<font color=Cyan>)</font><font color=Cyan>)</font> <font color=Cyan>(</font>toContents aa<font color=Cyan>)</font><font color=Red>]</font>
-<a name="line-239"></a>    toContents v<font color=Red>@</font><font color=Cyan>(</font>Right ab<font color=Cyan>)</font> <font color=Red>=</font>
-<a name="line-240"></a>        <font color=Red>[</font>mkElemC <font color=Cyan>(</font>showConstr <font color=Magenta>1</font> <font color=Cyan>(</font>toHType v<font color=Cyan>)</font><font color=Cyan>)</font> <font color=Cyan>(</font>toContents ab<font color=Cyan>)</font><font color=Red>]</font>
-<a name="line-241"></a>    parseContents <font color=Red>=</font>
-<a name="line-242"></a>        <font color=Cyan>(</font>inElementWith <font color=Cyan>(</font>flip isPrefixOf<font color=Cyan>)</font> <font color=Magenta>"Left"</font>  <font color=Cyan>$</font> fmap Left  parseContents<font color=Cyan>)</font>
-<a name="line-243"></a>          <font color=Cyan>`onFail`</font>
-<a name="line-244"></a>        <font color=Cyan>(</font>inElementWith <font color=Cyan>(</font>flip isPrefixOf<font color=Cyan>)</font> <font color=Magenta>"Right"</font> <font color=Cyan>$</font> fmap Right parseContents<font color=Cyan>)</font>
-<a name="line-245"></a>
-<a name="line-246"></a><font color=Blue>--    do{ e@(Elem t [] _) &lt;- element ["Left","Right"]</font>
-<a name="line-247"></a><font color=Blue>--      ; case t of</font>
-<a name="line-248"></a><font color=Blue>--          _ | "Left"  `isPrefixOf` t -&gt; fmap Left  (interior e parseContents)</font>
-<a name="line-249"></a><font color=Blue>--            | "Right" `isPrefixOf` t -&gt; fmap Right (interior e parseContents)</font>
-<a name="line-250"></a><font color=Blue>--      }</font>
-<a name="line-251"></a>
-<a name="line-252"></a><font color=Blue>------------------------------------------------------------------------</font>
+<a name="line-223"></a>
+<a name="line-224"></a><font color=Green><u>instance</u></font> <font color=Cyan>(</font>XmlContent a<font color=Cyan>)</font> <font color=Red>=&gt;</font> XmlContent <font color=Cyan>(</font>Maybe a<font color=Cyan>)</font> <font color=Green><u>where</u></font>
+<a name="line-225"></a>    toContents m   <font color=Red>=</font> <font color=Red>[</font>mkElem m <font color=Cyan>(</font>maybe [] toContents m<font color=Cyan>)</font><font color=Red>]</font>
+<a name="line-226"></a>    parseContents <font color=Red>=</font> <font color=Green><u>do</u></font>
+<a name="line-227"></a>        <font color=Cyan>{</font> e <font color=Red>&lt;-</font> elementWith <font color=Cyan>(</font>flip isPrefixOf<font color=Cyan>)</font> <font color=Red>[</font><font color=Magenta>"maybe"</font><font color=Red>]</font>
+<a name="line-228"></a>        <font color=Cyan>;</font> <font color=Green><u>case</u></font> e <font color=Green><u>of</u></font> <font color=Cyan>(</font>Elem <font color=Green><u>_</u></font> [] []<font color=Cyan>)</font> <font color=Red>-&gt;</font> return Nothing
+<a name="line-229"></a>                    <font color=Cyan>(</font>Elem <font color=Green><u>_</u></font> [] <font color=Green><u>_</u></font><font color=Cyan>)</font>  <font color=Red>-&gt;</font> fmap Just <font color=Cyan>(</font>interior e parseContents<font color=Cyan>)</font>
+<a name="line-230"></a>        <font color=Cyan>}</font>
+<a name="line-231"></a>
+<a name="line-232"></a><font color=Green><u>instance</u></font> <font color=Cyan>(</font>XmlContent a<font color=Cyan>,</font> XmlContent b<font color=Cyan>)</font> <font color=Red>=&gt;</font> XmlContent <font color=Cyan>(</font>Either a b<font color=Cyan>)</font> <font color=Green><u>where</u></font>
+<a name="line-233"></a>    toContents v<font color=Red>@</font><font color=Cyan>(</font>Left aa<font color=Cyan>)</font> <font color=Red>=</font>
+<a name="line-234"></a>        <font color=Red>[</font>mkElemC <font color=Cyan>(</font>showConstr <font color=Magenta>0</font> <font color=Cyan>(</font>toHType v<font color=Cyan>)</font><font color=Cyan>)</font> <font color=Cyan>(</font>toContents aa<font color=Cyan>)</font><font color=Red>]</font>
+<a name="line-235"></a>    toContents v<font color=Red>@</font><font color=Cyan>(</font>Right ab<font color=Cyan>)</font> <font color=Red>=</font>
+<a name="line-236"></a>        <font color=Red>[</font>mkElemC <font color=Cyan>(</font>showConstr <font color=Magenta>1</font> <font color=Cyan>(</font>toHType v<font color=Cyan>)</font><font color=Cyan>)</font> <font color=Cyan>(</font>toContents ab<font color=Cyan>)</font><font color=Red>]</font>
+<a name="line-237"></a>    parseContents <font color=Red>=</font>
+<a name="line-238"></a>        <font color=Cyan>(</font>inElementWith <font color=Cyan>(</font>flip isPrefixOf<font color=Cyan>)</font> <font color=Magenta>"Left"</font>  <font color=Cyan>$</font> fmap Left  parseContents<font color=Cyan>)</font>
+<a name="line-239"></a>          <font color=Cyan>`onFail`</font>
+<a name="line-240"></a>        <font color=Cyan>(</font>inElementWith <font color=Cyan>(</font>flip isPrefixOf<font color=Cyan>)</font> <font color=Magenta>"Right"</font> <font color=Cyan>$</font> fmap Right parseContents<font color=Cyan>)</font>
+<a name="line-241"></a>
+<a name="line-242"></a><font color=Blue>--    do{ e@(Elem t [] _) &lt;- element ["Left","Right"]</font>
+<a name="line-243"></a><font color=Blue>--      ; case t of</font>
+<a name="line-244"></a><font color=Blue>--          _ | "Left"  `isPrefixOf` t -&gt; fmap Left  (interior e parseContents)</font>
+<a name="line-245"></a><font color=Blue>--            | "Right" `isPrefixOf` t -&gt; fmap Right (interior e parseContents)</font>
+<a name="line-246"></a><font color=Blue>--      }</font>
+<a name="line-247"></a>
+<a name="line-248"></a><font color=Blue>------------------------------------------------------------------------</font>
 </pre>
 </body>
 </html>
diff --git a/docs/HaXml/src/Text/XML/HaXml/XmlContent/Parser.html b/docs/HaXml/src/Text/XML/HaXml/XmlContent/Parser.html
--- a/docs/HaXml/src/Text/XML/HaXml/XmlContent/Parser.html
+++ b/docs/HaXml/src/Text/XML/HaXml/XmlContent/Parser.html
@@ -248,7 +248,7 @@
 <a name="line-241"></a><font color=Blue>choice</font> cons <font color=Cyan>(</font>P other<font color=Cyan>)</font> <font color=Red>=</font>
 <a name="line-242"></a>    P <font color=Cyan>(</font><font color=Red>\</font>cs<font color=Red>-&gt;</font> <font color=Green><u>case</u></font> runParser parseContents cs <font color=Green><u>of</u></font>
 <a name="line-243"></a>                 <font color=Cyan>(</font>Left <font color=Green><u>_</u></font><font color=Cyan>,</font> <font color=Green><u>_</u></font><font color=Cyan>)</font>  <font color=Red>-&gt;</font> other cs
-<a name="line-244"></a>                 <font color=Cyan>(</font>Right x<font color=Cyan>,</font> cs'<font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Right <font color=Cyan>(</font>cons x<font color=Cyan>)</font><font color=Cyan>,</font> cs'<font color=Cyan>)</font><font color=Cyan>)</font>
+<a name="line-244"></a>                 <font color=Cyan>(</font>Right x<font color=Cyan>,</font> cs'<font color=Cyan>)</font> <font color=Red>-&gt;</font> Success cs' <font color=Cyan>(</font>cons x<font color=Cyan>)</font> <font color=Cyan>)</font>
 <a name="line-245"></a>
 <a name="line-246"></a><font color=Blue>--choice cons other = fmap cons parseContents `onFail` other</font>
 <a name="line-247"></a>
@@ -257,8 +257,8 @@
 <a name="line-250"></a><font color=Blue>--   care of that for us.</font>
 <a name="line-251"></a><font color=Blue>definite</font> <font color=Red>::</font> XmlContent a <font color=Red>=&gt;</font> XMLParser a <font color=Red>-&gt;</font> String <font color=Red>-&gt;</font> String <font color=Red>-&gt;</font> XMLParser a
 <a name="line-252"></a><font color=Blue>definite</font> p inner tag <font color=Red>=</font> P <font color=Cyan>(</font><font color=Red>\</font>cs<font color=Red>-&gt;</font> <font color=Green><u>case</u></font> runParser p cs <font color=Green><u>of</u></font>
-<a name="line-253"></a>                                   <font color=Cyan>(</font>Left <font color=Green><u>_</u></font><font color=Cyan>,</font> cs'<font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False<font color=Cyan>,</font>msg'<font color=Cyan>)</font><font color=Cyan>,</font> cs'<font color=Cyan>)</font>
-<a name="line-254"></a>                                   <font color=Cyan>(</font>Right x<font color=Cyan>,</font> cs'<font color=Cyan>)</font>  <font color=Red>-&gt;</font> <font color=Cyan>(</font>Right x<font color=Cyan>,</font>   cs'<font color=Cyan>)</font><font color=Cyan>)</font>
+<a name="line-253"></a>                                   <font color=Cyan>(</font>Left <font color=Green><u>_</u></font><font color=Cyan>,</font> cs'<font color=Cyan>)</font>   <font color=Red>-&gt;</font> Failure cs' msg'
+<a name="line-254"></a>                                   <font color=Cyan>(</font>Right x<font color=Cyan>,</font> cs'<font color=Cyan>)</font>  <font color=Red>-&gt;</font> Success cs' x <font color=Cyan>)</font>
 <a name="line-255"></a>  <font color=Green><u>where</u></font> msg' <font color=Red>=</font> <font color=Magenta>"content error: expected "</font><font color=Cyan>++</font>inner<font color=Cyan>++</font><font color=Magenta>" inside &lt;"</font><font color=Cyan>++</font>tag
 <a name="line-256"></a>               <font color=Cyan>++</font><font color=Magenta>"&gt; element\n"</font>
 <a name="line-257"></a>
@@ -690,7 +690,7 @@
 <a name="line-683"></a><font color=Green><u>instance</u></font> XmlContent ANYContent <font color=Green><u>where</u></font>
 <a name="line-684"></a>    toContents <font color=Cyan>(</font>ANYContent a<font color=Cyan>)</font>  <font color=Red>=</font> toContents a
 <a name="line-685"></a>    toContents <font color=Cyan>(</font>UnConverted s<font color=Cyan>)</font> <font color=Red>=</font> map <font color=Cyan>(</font>fmap <font color=Cyan>(</font>const ()<font color=Cyan>)</font><font color=Cyan>)</font> s
-<a name="line-686"></a>    parseContents <font color=Red>=</font> P <font color=Cyan>(</font><font color=Red>\</font>cs <font color=Red>-&gt;</font> <font color=Cyan>(</font>Right <font color=Cyan>(</font>UnConverted cs<font color=Cyan>)</font><font color=Cyan>,</font> []<font color=Cyan>)</font><font color=Cyan>)</font>
+<a name="line-686"></a>    parseContents <font color=Red>=</font> P <font color=Cyan>(</font><font color=Red>\</font>cs <font color=Red>-&gt;</font> Success [] <font color=Cyan>(</font>UnConverted cs<font color=Cyan>)</font><font color=Cyan>)</font>
 <a name="line-687"></a>
 <a name="line-688"></a><font color=Blue>------------------------------------------------------------------------</font>
 <a name="line-689"></a><font color=Blue>--</font>
diff --git a/docs/HaXml/src/Text/XML/HaXml/Xtract/Parse.html b/docs/HaXml/src/Text/XML/HaXml/Xtract/Parse.html
--- a/docs/HaXml/src/Text/XML/HaXml/Xtract/Parse.html
+++ b/docs/HaXml/src/Text/XML/HaXml/Xtract/Parse.html
@@ -63,19 +63,19 @@
 <a name="line-56"></a>
 <a name="line-57"></a><a name="string"></a><font color=Blue>string</font> <font color=Red>::</font> XParser String
 <a name="line-58"></a><font color=Blue>string</font> <font color=Red>=</font> P <font color=Cyan>(</font><font color=Red>\</font>inp <font color=Red>-&gt;</font> <font color=Green><u>case</u></font> inp <font color=Green><u>of</u></font>
-<a name="line-59"></a>                <font color=Cyan>(</font>Left err<font color=Red><b>:</b></font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False<font color=Cyan>,</font>err<font color=Cyan>)</font><font color=Cyan>,</font> inp<font color=Cyan>)</font>
-<a name="line-60"></a>                <font color=Cyan>(</font>Right <font color=Cyan>(</font>p<font color=Cyan>,</font>TokString n<font color=Cyan>)</font><font color=Red><b>:</b></font>ts<font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Right n<font color=Cyan>,</font> ts<font color=Cyan>)</font>
-<a name="line-61"></a>                ts <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False<font color=Cyan>,</font><font color=Magenta>"expected a string"</font><font color=Cyan>)</font><font color=Cyan>,</font> ts<font color=Cyan>)</font> <font color=Cyan>)</font>
+<a name="line-59"></a>                <font color=Cyan>(</font>Left err<font color=Red><b>:</b></font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> Failure inp err
+<a name="line-60"></a>                <font color=Cyan>(</font>Right <font color=Cyan>(</font>p<font color=Cyan>,</font>TokString n<font color=Cyan>)</font><font color=Red><b>:</b></font>ts<font color=Cyan>)</font> <font color=Red>-&gt;</font> Success ts n
+<a name="line-61"></a>                ts <font color=Red>-&gt;</font> Failure ts <font color=Magenta>"expected a string"</font> <font color=Cyan>)</font>
 <a name="line-62"></a><a name="number"></a><font color=Blue>number</font> <font color=Red>::</font> XParser Integer
 <a name="line-63"></a><font color=Blue>number</font> <font color=Red>=</font> P <font color=Cyan>(</font><font color=Red>\</font>inp <font color=Red>-&gt;</font> <font color=Green><u>case</u></font> inp <font color=Green><u>of</u></font>
-<a name="line-64"></a>                <font color=Cyan>(</font>Left err<font color=Red><b>:</b></font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False<font color=Cyan>,</font>err<font color=Cyan>)</font><font color=Cyan>,</font> inp<font color=Cyan>)</font>
-<a name="line-65"></a>                <font color=Cyan>(</font>Right <font color=Cyan>(</font>p<font color=Cyan>,</font>TokNum n<font color=Cyan>)</font><font color=Red><b>:</b></font>ts<font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Right n<font color=Cyan>,</font> ts<font color=Cyan>)</font>
-<a name="line-66"></a>                ts <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False<font color=Cyan>,</font><font color=Magenta>"expected a number"</font><font color=Cyan>)</font><font color=Cyan>,</font> ts<font color=Cyan>)</font> <font color=Cyan>)</font>
+<a name="line-64"></a>                <font color=Cyan>(</font>Left err<font color=Red><b>:</b></font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> Failure inp err
+<a name="line-65"></a>                <font color=Cyan>(</font>Right <font color=Cyan>(</font>p<font color=Cyan>,</font>TokNum n<font color=Cyan>)</font><font color=Red><b>:</b></font>ts<font color=Cyan>)</font> <font color=Red>-&gt;</font> Success ts n
+<a name="line-66"></a>                ts <font color=Red>-&gt;</font> Failure ts <font color=Magenta>"expected a number"</font> <font color=Cyan>)</font>
 <a name="line-67"></a><a name="symbol"></a><font color=Blue>symbol</font> <font color=Red>::</font> String <font color=Red>-&gt;</font> XParser ()
 <a name="line-68"></a><font color=Blue>symbol</font> s <font color=Red>=</font> P <font color=Cyan>(</font><font color=Red>\</font>inp <font color=Red>-&gt;</font> <font color=Green><u>case</u></font> inp <font color=Green><u>of</u></font>
-<a name="line-69"></a>                <font color=Cyan>(</font>Left err<font color=Red><b>:</b></font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False<font color=Cyan>,</font>err<font color=Cyan>)</font><font color=Cyan>,</font> inp<font color=Cyan>)</font>
-<a name="line-70"></a>                <font color=Cyan>(</font>Right <font color=Cyan>(</font>p<font color=Cyan>,</font> Symbol n<font color=Cyan>)</font><font color=Red><b>:</b></font>ts<font color=Cyan>)</font> <font color=Red>|</font> n<font color=Cyan>==</font>s <font color=Red>-&gt;</font> <font color=Cyan>(</font>Right ()<font color=Cyan>,</font> ts<font color=Cyan>)</font>
-<a name="line-71"></a>                ts <font color=Red>-&gt;</font> <font color=Cyan>(</font>Left <font color=Cyan>(</font>False<font color=Cyan>,</font><font color=Magenta>"expected symbol "</font><font color=Cyan>++</font>s<font color=Cyan>)</font><font color=Cyan>,</font> ts<font color=Cyan>)</font> <font color=Cyan>)</font>
+<a name="line-69"></a>                <font color=Cyan>(</font>Left err<font color=Red><b>:</b></font> <font color=Green><u>_</u></font><font color=Cyan>)</font> <font color=Red>-&gt;</font> Failure inp err
+<a name="line-70"></a>                <font color=Cyan>(</font>Right <font color=Cyan>(</font>p<font color=Cyan>,</font> Symbol n<font color=Cyan>)</font><font color=Red><b>:</b></font>ts<font color=Cyan>)</font> <font color=Red>|</font> n<font color=Cyan>==</font>s <font color=Red>-&gt;</font> Success ts ()
+<a name="line-71"></a>                ts <font color=Red>-&gt;</font> Failure ts <font color=Cyan>(</font><font color=Magenta>"expected symbol "</font><font color=Cyan>++</font>s<font color=Cyan>)</font> <font color=Cyan>)</font>
 <a name="line-72"></a>
 <a name="line-73"></a><a name="quote"></a><font color=Blue>quote</font> <font color=Red>=</font> oneOf <font color=Red>[</font> symbol <font color=Magenta>"'"</font><font color=Cyan>,</font>  symbol <font color=Magenta>"\""</font> <font color=Red>]</font>
 <a name="line-74"></a>
diff --git a/docs/changelog.html b/docs/changelog.html
--- a/docs/changelog.html
+++ b/docs/changelog.html
@@ -29,7 +29,9 @@
      specifications.
 <li> Version 1.19.6 fixes some tag-name bugs when converting datatypes
      generated by DtdToHaskell back into an XML file value.
-</ul>
+<li> Version 1.19.7 requires package polyparse-1.2 (earlier versions
+     require polyparse-1.1).
+ </ul>
 
 <h3>Changes in 1.18</h3>
 <p>
diff --git a/docs/index.html b/docs/index.html
--- a/docs/index.html
+++ b/docs/index.html
@@ -132,11 +132,11 @@
 <center><h3><a name="download">Downloads</a></h3></center>
 <p>
 <b>Development versions:</b><br>
-HaXml-1.19.6, release date 2009.02.04<br>
+HaXml-1.19.7, release date 2009.03.05<br>
 From <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/HaXml">Hackage</a><br>
 By HTTP:
-<a href="http://www.cs.york.ac.uk/fp/HaXml-devel/HaXml-1.19.6.tar.gz">.tar.gz</a>,
-<a href="http://www.cs.york.ac.uk/fp/HaXml-devel/HaXml-1.19.6.zip">.zip</a>.
+<a href="http://www.cs.york.ac.uk/fp/HaXml-devel/HaXml-1.19.7.tar.gz">.tar.gz</a>,
+<a href="http://www.cs.york.ac.uk/fp/HaXml-devel/HaXml-1.19.7.zip">.zip</a>.
 <br>
 By FTP: 
 <a href="ftp://ftp.cs.york.ac.uk/pub/haskell/HaXml/">
@@ -203,6 +203,8 @@
 <center><h3><a name="news">Recent news</a></h3></center>
 
 <p>
+Version 1.19.7 requires package polyparse-1.2 (previous versions require
+polyparse-1.1).<br>
 Version 1.19.6 has some bugfixes to XmlContent, to ensure that types
 created via DtdToHaskell get converted back to XML correctly.<br>
 Version 1.19.5 has some bugfixes to DtdToHaskell, to cope with especially
diff --git a/src/Makefile b/src/Makefile
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,5 +1,5 @@
 SOFTWARE = HaXml
-VERSION = 1.19.6
+VERSION = 1.19.7
 
 LIBSRCS = \
 	Text/XML/HaXml.hs Text/XML/HaXml/Combinators.hs Text/XML/HaXml/Lex.hs \
diff --git a/src/Text/XML/HaXml/Html/Parse.hs b/src/Text/XML/HaXml/Html/Parse.hs
--- a/src/Text/XML/HaXml/Html/Parse.hs
+++ b/src/Text/XML/HaXml/Html/Parse.hs
@@ -21,7 +21,7 @@
 import Text.XML.HaXml.Types
 import Text.XML.HaXml.Lex
 import Text.XML.HaXml.Posn
-import Text.ParserCombinators.Poly.NoLeak.Plain
+import Text.ParserCombinators.Poly.Plain
 
 --  #define DEBUG
  
diff --git a/src/Text/XML/HaXml/Html/ParseLazy.hs b/src/Text/XML/HaXml/Html/ParseLazy.hs
--- a/src/Text/XML/HaXml/Html/ParseLazy.hs
+++ b/src/Text/XML/HaXml/Html/ParseLazy.hs
@@ -21,7 +21,7 @@
 import Text.XML.HaXml.Types
 import Text.XML.HaXml.Lex
 import Text.XML.HaXml.Posn
-import Text.ParserCombinators.Poly.NoLeak.Lazy
+import Text.ParserCombinators.Poly.Lazy
 
 --  #define DEBUG
  
diff --git a/src/Text/XML/HaXml/Parse.hs b/src/Text/XML/HaXml/Parse.hs
--- a/src/Text/XML/HaXml/Parse.hs
+++ b/src/Text/XML/HaXml/Parse.hs
@@ -40,7 +40,7 @@
 import Text.XML.HaXml.Types
 import Text.XML.HaXml.Posn
 import Text.XML.HaXml.Lex
-import Text.ParserCombinators.Poly.NoLeak.State
+import Text.ParserCombinators.Poly.State
 
 import System.FilePath (combine, dropFileName)
 
diff --git a/src/Text/XML/HaXml/ParseLazy.hs b/src/Text/XML/HaXml/ParseLazy.hs
--- a/src/Text/XML/HaXml/ParseLazy.hs
+++ b/src/Text/XML/HaXml/ParseLazy.hs
@@ -40,7 +40,7 @@
 import Text.XML.HaXml.Types
 import Text.XML.HaXml.Posn
 import Text.XML.HaXml.Lex
-import Text.ParserCombinators.Poly.NoLeak.StateLazy
+import Text.ParserCombinators.Poly.StateLazy
 
 import System.FilePath (combine, dropFileName)
 
diff --git a/src/Text/XML/HaXml/SAX.hs b/src/Text/XML/HaXml/SAX.hs
--- a/src/Text/XML/HaXml/SAX.hs
+++ b/src/Text/XML/HaXml/SAX.hs
@@ -12,7 +12,7 @@
 import Text.XML.HaXml.Types
 import Text.XML.HaXml.Parse
 import Text.XML.HaXml.Lex
-import Text.ParserCombinators.Poly.NoLeak.State
+import Text.ParserCombinators.Poly.State
 
 data SaxElement
 	= SaxDocTypeDecl DocTypeDecl
diff --git a/src/Text/XML/HaXml/XmlContent.hs b/src/Text/XML/HaXml/XmlContent.hs
--- a/src/Text/XML/HaXml/XmlContent.hs
+++ b/src/Text/XML/HaXml/XmlContent.hs
@@ -16,6 +16,7 @@
   (
   -- * Re-export everything from Text.XML.HaXml.XmlContent.Parser.
     module Text.XML.HaXml.XmlContent.Parser
+  , module Text.XML.HaXml.TypeMapping
   -- * Contains instances of the XmlContent classes,
   --   for the basic Haskell datatypes list and Maybe,
   --   intended for use with DtdToHaskell-generated datatypes.
@@ -162,8 +163,9 @@
                             [CString True (map xToChar xs) ()]
                        _ -> concatMap toContents xs
                    where   (x:_) = xs
-    parseContents = let (Right (x:_),_) = runParser p [] -- for type of x only
-                        p = case toHType x of
+    parseContents = let result = runParser p [] -- for type of result only
+                        p = case (toHType . head . (\ (Right x)->x) . fst)
+                                 result of
                               (Prim "Char" _) -> fmap (map xFromChar) $ text
                               _ -> many parseContents
                     in p
diff --git a/src/Text/XML/HaXml/XmlContent/Haskell.hs b/src/Text/XML/HaXml/XmlContent/Haskell.hs
--- a/src/Text/XML/HaXml/XmlContent/Haskell.hs
+++ b/src/Text/XML/HaXml/XmlContent/Haskell.hs
@@ -191,33 +191,29 @@
     parseContents = P (\x ->
         case x of
             (CString _ s _:cs)
-                   -> (Right (map xFromChar s), cs)
+                   -> Success cs (map xFromChar s)
             (CElem (Elem "string" [] [CString _ s _]) _:cs)
-                   -> (Right (map xFromChar s), cs)
+                   -> Success cs (map xFromChar s)
             (CElem (Elem e [] xs) _:cs) | "list" `isPrefixOf` e
                    -> scanElements xs
                    where
                   -- scanElements :: [Content] -> (Either String [a],[Content])
-                     scanElements [] = (Right [], cs)
+                     scanElements [] = Success cs []
                      scanElements es =
                         case runParser parseContents es of
-                            (Left msg, es') -> (Left (False,msg), es')
+                            (Left msg, es') -> Failure es' msg
                             (Right y, es') ->
                                 case scanElements es' of
-                                    (Left msg, ds) -> (Left msg, ds)
-                                    (Right ys, ds) -> (Right (y:ys), ds)
+                                    Failure ds msg -> Failure ds msg
+                                    Success ds ys  -> Success ds (y:ys)
             (CElem (Elem e _ _) pos: cs)
-                   -> (Left (False
-                            ,"Expected a <list-...>, but found a <"++e++"> at\n"
-                            ++ show pos), cs)
+                   -> Failure cs ("Expected a <list-...>, but found a <"++e
+                                  ++"> at\n"++show pos)
             (CRef r pos: cs)
-                   -> (Left (False
-                            ,"Expected a <list-...>, but found a ref "
-                            ++verbatim r++" at\n"++ show pos), cs)
+                   -> Failure cs ("Expected a <list-...>, but found a ref "
+                                  ++verbatim r++" at\n"++ show pos)
             (_:cs) -> ((\ (P p)-> p) parseContents) cs  -- skip comments etc.
-            []     -> (Left (False
-                            ,"Ran out of input XML whilst secondary parsing")
-                      , [])
+            []     -> Failure [] "Ran out of input XML whilst secondary parsing"
         )
 
 instance XmlContent () where
diff --git a/src/Text/XML/HaXml/XmlContent/Parser.hs b/src/Text/XML/HaXml/XmlContent/Parser.hs
--- a/src/Text/XML/HaXml/XmlContent/Parser.hs
+++ b/src/Text/XML/HaXml/XmlContent/Parser.hs
@@ -241,7 +241,7 @@
 choice cons (P other) =
     P (\cs-> case runParser parseContents cs of
                  (Left _, _)  -> other cs
-                 (Right x, cs') -> (Right (cons x), cs'))
+                 (Right x, cs') -> Success cs' (cons x) )
 
 --choice cons other = fmap cons parseContents `onFail` other
 
@@ -250,8 +250,8 @@
 --   care of that for us.
 definite :: XmlContent a => XMLParser a -> String -> String -> XMLParser a
 definite p inner tag = P (\cs-> case runParser p cs of
-                                   (Left _, cs') -> (Left (False,msg'), cs')
-                                   (Right x, cs')  -> (Right x,   cs'))
+                                   (Left _, cs')   -> Failure cs' msg'
+                                   (Right x, cs')  -> Success cs' x )
   where msg' = "content error: expected "++inner++" inside <"++tag
                ++"> element\n"
 
@@ -683,7 +683,7 @@
 instance XmlContent ANYContent where
     toContents (ANYContent a)  = toContents a
     toContents (UnConverted s) = map (fmap (const ())) s
-    parseContents = P (\cs -> (Right (UnConverted cs), []))
+    parseContents = P (\cs -> Success [] (UnConverted cs))
 
 ------------------------------------------------------------------------
 --
diff --git a/src/Text/XML/HaXml/Xtract/Parse.hs b/src/Text/XML/HaXml/Xtract/Parse.hs
--- a/src/Text/XML/HaXml/Xtract/Parse.hs
+++ b/src/Text/XML/HaXml/Xtract/Parse.hs
@@ -56,19 +56,19 @@
 
 string :: XParser String
 string = P (\inp -> case inp of
-                (Left err: _) -> (Left (False,err), inp)
-                (Right (p,TokString n):ts) -> (Right n, ts)
-                ts -> (Left (False,"expected a string"), ts) )
+                (Left err: _) -> Failure inp err
+                (Right (p,TokString n):ts) -> Success ts n
+                ts -> Failure ts "expected a string" )
 number :: XParser Integer
 number = P (\inp -> case inp of
-                (Left err: _) -> (Left (False,err), inp)
-                (Right (p,TokNum n):ts) -> (Right n, ts)
-                ts -> (Left (False,"expected a number"), ts) )
+                (Left err: _) -> Failure inp err
+                (Right (p,TokNum n):ts) -> Success ts n
+                ts -> Failure ts "expected a number" )
 symbol :: String -> XParser ()
 symbol s = P (\inp -> case inp of
-                (Left err: _) -> (Left (False,err), inp)
-                (Right (p, Symbol n):ts) | n==s -> (Right (), ts)
-                ts -> (Left (False,"expected symbol "++s), ts) )
+                (Left err: _) -> Failure inp err
+                (Right (p, Symbol n):ts) | n==s -> Success ts ()
+                ts -> Failure ts ("expected symbol "++s) )
 
 quote = oneOf [ symbol "'",  symbol "\"" ]
 
