diff --git a/examples/arrows/AGentleIntroductionToHXT/PicklerExample/Baseball.hs b/examples/arrows/AGentleIntroductionToHXT/PicklerExample/Baseball.hs
--- a/examples/arrows/AGentleIntroductionToHXT/PicklerExample/Baseball.hs
+++ b/examples/arrows/AGentleIntroductionToHXT/PicklerExample/Baseball.hs
@@ -11,7 +11,7 @@
 
 import           Data.Map (Map, fromList, toList)
 
-import Text.XML.HXT.Arrow
+import Text.XML.HXT.Core
 
 -- Example data taken from:
 -- http://www.ibiblio.org/xml/books/bible/examples/05/5-1.xml
@@ -115,15 +115,15 @@
 main	:: IO ()
 main
     = do
-      runX ( xunpickleDocument xpSeason [ (a_validate,v_0)
-					, (a_trace, v_1)
-					, (a_remove_whitespace,v_1)
-					, (a_preserve_comment, v_0)
+      runX ( xunpickleDocument xpSeason [ withValidate no
+					, withTrace 1
+					, withRemoveWS yes
+					, withPreserveComment no
 					] "simple2.xml"
 	     >>>
 	     processSeason
 	     >>>
-	     xpickleDocument xpSeason [ (a_indent, v_1)
+	     xpickleDocument xpSeason [ withIndent yes
 				      ] "new-simple2.xml"
 	   )
       return ()
diff --git a/examples/arrows/AGentleIntroductionToHXT/SimpleExamples.hs b/examples/arrows/AGentleIntroductionToHXT/SimpleExamples.hs
--- a/examples/arrows/AGentleIntroductionToHXT/SimpleExamples.hs
+++ b/examples/arrows/AGentleIntroductionToHXT/SimpleExamples.hs
@@ -1,14 +1,13 @@
 {- |
-   $Id: SimpleExamples.hs,v 1.3 2006/11/17 17:16:24 hxml Exp $
-  
-  The examples from the HXT tutorial at haskell.org "http://www.haskell.org/haskellwiki/HXT"
+   The examples from the HXT tutorial at haskell.org "http://www.haskell.org/haskellwiki/HXT"
 -}
 
 module Main
 where
 
-import Text.XML.HXT.Arrow		-- import HXT stuff
-import Text.XML.HXT.XPath
+import Text.XML.HXT.Core		-- basic HXT stuff
+import Text.XML.HXT.XPath               -- additional XPath functions
+import Text.XML.HXT.Curl                -- Curl HTTP handler
 
 import Data.List			-- auxiliary functions
 import Data.Maybe
@@ -35,45 +34,54 @@
 	 then exitWith (ExitFailure (-1))
 	 else exitWith ExitSuccess
 
-application	:: Attributes -> String -> String -> String -> IOSArrow b Int
-application al fct src dst
-    = readDocument al src
+application	:: SysConfigList -> String -> String -> String -> IOSArrow b Int
+application config fct src dst
+    = configSysVars config                            -- set all global config options
       >>>
+      readDocument [] src
+      >>>
       processChildren (processRootElement fct `when` isElem)
       >>>
-      writeDocument ( (a_indent, v_1)
-		      : (a_output_encoding, isoLatin1)
-		      : al
-		    ) dst
+      writeDocument [ withIndent yes,
+		      withOutputEncoding isoLatin1
+		    ]
+		    dst
       >>>
       getErrStatus
 
 -- | the dummy for the boring stuff of option evaluation,
 -- usually done with 'System.Console.GetOpt'
 
-cmdlineOpts 	:: [String] -> IO (Attributes, String, String, String)
+cmdlineOpts 	:: [String] -> IO (SysConfigList, String, String, String)
 cmdlineOpts argv
-    = return ([(a_validate, v_0),(a_parse_html, v_1)], argv!!0, argv!!1, argv!!2)
+    = return ( [ withValidate no
+	       , withParseHTML yes
+	       , withCurl []
+	       ]
+	     , argv!!0
+	     , argv!!1
+	     , argv!!2
+	     )
 
 
 -- | the processing examples
 
 examples	:: [ (String, IOSArrow XmlTree XmlTree) ]
 examples
-    = [ ( "selectAllText",	selectAllText	)
-      , ( "selectAllTextAndAltValues",	selectAllTextAndAltValues	)
+    = [ ( "selectAllText",			selectAllText	)
+      , ( "selectAllTextAndAltValues",		selectAllTextAndAltValues	)
       , ( "selectAllTextAndRealAltValues",	selectAllTextAndRealAltValues	)
-      , ( "addRefIcon",		addRefIcon	)
-      , ( "helloWorld",		helloWorld	)
-      , ( "helloWorld2",	helloWorld2	)
-      , ( "imageTable",		imageTable	)
-      , ( "imageTable0",	imageTable0	)
-      , ( "imageTable1",	imageTable1	)
-      , ( "imageTable2",	imageTable2	)
-      , ( "imageTable3",	imageTable3	)
-      , ( "toAbsHRefs",		toAbsHRefs	)
-      , ( "toAbsRefs",		toAbsRefs	)
-      , ( "toAbsRefs1",		toAbsRefs1	)
+      , ( "addRefIcon",				addRefIcon	)
+      , ( "helloWorld",				helloWorld	)
+      , ( "helloWorld2",			helloWorld2	)
+      , ( "imageTable",				imageTable	)
+      , ( "imageTable0",			imageTable0	)
+      , ( "imageTable1",			imageTable1	)
+      , ( "imageTable2",			imageTable2	)
+      , ( "imageTable3",			imageTable3	)
+      , ( "toAbsHRefs",				toAbsHRefs	)
+      , ( "toAbsRefs",				toAbsRefs	)
+      , ( "toAbsRefs1",				toAbsRefs1	)
       ]
 
 processRootElement	:: String -> IOSArrow XmlTree XmlTree
diff --git a/examples/arrows/HelloWorld/HelloWorld.hs b/examples/arrows/HelloWorld/HelloWorld.hs
--- a/examples/arrows/HelloWorld/HelloWorld.hs
+++ b/examples/arrows/HelloWorld/HelloWorld.hs
@@ -1,17 +1,17 @@
 module Main
 where
 
-import Text.XML.HXT.Arrow
+import Text.XML.HXT.Core
 import System.Exit
 
 main	:: IO()
 main
     = do
-      [rc] <- runX ( readDocument [ (a_trace, "1")
-				  , (a_validate, v_0)
+      [rc] <- runX ( readDocument [ withTrace 1
+				  , withValidate no
 				  ] "hello.xml"
 		     >>>
-		     writeDocument [ (a_output_encoding, isoLatin1)
+		     writeDocument [ withOutputEncoding utf8
 				   ] "-"
 		     >>>
 		     getErrStatus
diff --git a/examples/arrows/HelloWorld/Mini.hs b/examples/arrows/HelloWorld/Mini.hs
--- a/examples/arrows/HelloWorld/Mini.hs
+++ b/examples/arrows/HelloWorld/Mini.hs
@@ -1,13 +1,15 @@
 module Main
 where
 
-import Text.XML.HXT.Arrow
+import Text.XML.HXT.Core
 
 main	:: IO()
 main
-    = runX ( readDocument [ (a_validate, v_0) ] "hello.xml"
+    = runX ( configSysVars [ withTrace 1 ]
 	     >>>
-	     writeDocument [ ] "bye.xml"
+	     readDocument    [ withValidate no ] "hello.xml"
+	     >>>
+	     writeDocument   [ ] "bye.xml"
 	   )
       >> return ()
 
diff --git a/examples/arrows/RegexXMLSchema/Makefile b/examples/arrows/RegexXMLSchema/Makefile
deleted file mode 100644
--- a/examples/arrows/RegexXMLSchema/Makefile
+++ /dev/null
@@ -1,128 +0,0 @@
-# $Id: Makefile,v 1.9 2006/11/11 15:36:03 hxml Exp $
-
-HXT_HOME	= ../../..
-PKGFLAGS	= 
-GHCFLAGS	= -Wall -O2
-GHC		= ghc $(GHCFLAGS) $(PKGFLAGS)
-
-DIST		= $(HXT_HOME)/dist/examples/arrows
-DIST_DIR	= $(DIST)/RegexXMLSchema
-
-CNT		= 3
-
-ropts		= +RTS -s -RTS 
-
-prog		= ./REtest
-prog2		= ./Lines
-prog3		= ./RElines
-prog4		= ./Words
-prog5		= ./REwords
-prog0		= ./Copy
-
-progs		= $(prog) $(prog0) $(prog2) $(prog3) $(prog4) $(prog5)
-
-all		: $(progs)
-
-$(prog)		: $(prog).hs
-		$(GHC) --make -o $@ $<
-
-local		:
-		$(GHC) --make -o $(prog) -fglasgow-exts -ignore-package hxt -i../../../src $(prog).hs
-
-$(prog2)	: $(prog)
-		ln -f $(prog) $(prog2)
-
-$(prog3)	: $(prog)
-		ln -f $(prog) $(prog3)
-
-$(prog4)	: $(prog)
-		ln -f $(prog) $(prog4)
-
-$(prog5)	: $(prog)
-		ln -f $(prog) $(prog5)
-
-$(prog0)	: $(prog)
-		ln -f $(prog) $(prog0)
-
-# generate and read documents containing a binary tree
-# with 2^i leaf nodes containing the numbers 1 to 2^i
-# for i up to at least 22 (8M XML elements) output works fine
-# for i up to 19 (1M XML elements) input works without swapping
-# with i=20 swapping starts, but the program it still terminates
-# the size of the XML file for i=20 is about 36Mb
-# these tests have run on a box with 1Gb memory
-
-tests		= 18
-
-test		: $(prog)
-		$(MAKE) genfiles   tests="$(tests)"
-		$(MAKE) copy       tests="$(tests)"
-		$(MAKE) lines      tests="$(tests)"
-		$(MAKE) relines    tests="$(tests)"
-		$(MAKE) words      tests="$(tests)"
-		$(MAKE) rewords    tests="$(tests)"
-
-perftest	: $(prog)
-		$(MAKE) test tests="2 3 10 11 12 13 14 15 16 17 18 19 20"
-
-genfiles	:
-		@for i in $(tests) ; \
-		do \
-		echo time $(prog) $(ropts) $$i ; \
-		time $(prog) $(ropts) $$i ; \
-		ls -l tree-*$$i.xml ; \
-		echo ; \
-		done
-
-copy	:
-		@for i in $(tests) ; \
-		do \
-		echo time $(prog0) $(ropts) $$i ; \
-		time $(prog0) $(ropts) $$i ; \
-		ls -l tree-*$$i.xml.copy ; \
-		echo ; \
-		done
-
-lines	:
-		@for i in $(tests) ; \
-		do \
-		echo time $(prog2) $(ropts) $$i ; \
-		time $(prog2) $(ropts) $$i ; \
-		ls -l tree-*$$i.xml.lines ; \
-		echo ; \
-		done
-
-relines	:
-		@for i in $(tests) ; \
-		do \
-		echo time $(prog3) $(ropts) $$i ; \
-		time $(prog3) $(ropts) $$i ; \
-		ls -l tree-*$$i.xml.relines ; \
-		echo ; \
-		done
-
-words	:
-		@for i in $(tests) ; \
-		do \
-		echo time $(prog4) $(ropts) $$i ; \
-		time $(prog4) $(ropts) $$i ; \
-		ls -l tree-*$$i.xml.words ; \
-		echo ; \
-		done
-
-rewords	:
-		@for i in $(tests) ; \
-		do \
-		echo time $(prog5) $$i ; \
-		time $(prog5) $(ropts) $$i ; \
-		ls -l tree-*$$i.xml.rewords ; \
-		echo ; \
-		done
-
-dist		:
-		[ -d $(DIST_DIR) ] || mkdir -p $(DIST_DIR)
-		cp Makefile REtest.hs $(DIST_DIR)
-
-clean		:
-		rm -f $(progs) *.o *.hi *.xml *.xml.*
-
diff --git a/examples/arrows/RegexXMLSchema/REtest.hs b/examples/arrows/RegexXMLSchema/REtest.hs
deleted file mode 100644
--- a/examples/arrows/RegexXMLSchema/REtest.hs
+++ /dev/null
@@ -1,170 +0,0 @@
-{-# LANGUAGE BangPatterns#-}
-
--- ----------------------------------------
-
-module Main(main)
-where
-
-import Text.XML.HXT.Arrow
-import Text.XML.HXT.RelaxNG.XmlSchema.RegexMatch
-
-import Text.XML.HXT.DOM.Unicode
-    ( unicodeToXmlEntity
-    )
-
-import Control.Monad.State.Strict hiding (when)
-
-import Data.Maybe
-
-import System.IO			-- import the IO and commandline option stuff
-import System.Environment
-
--- ----------------------------------------
-
-main	:: IO ()
-main
-    = do
-      p  <- getProgName
-      al <- getArgs
-      let i = if null al
-	      then 4
-	      else (read . head $ al)::Int
-      main' p i
-    where
-    main' p' = fromMaybe main1 . lookup (pn p') $ mpt
-    mpt = [ ("REtest",	   main1)
-	  , ("Copy",       main2 "copy"    (:[]))
-	  , ("Lines",      main2 "lines"   lines)
-	  , ("RElines",    main2 "relines" relines)
-	  , ("Words",      main2 "words"   words)
-	  , ("REwords",    main2 "rewords" rewords)
-	  ]
-
--- ----------------------------------------
-
--- generate a document containing a binary tree of 2^i leafs (= 2^(i-1) XML elements)
-
-main1	:: Int -> IO ()
-main1 i
-    = runX (genDoc i (fn i))
-      >> return ()
-
--- ----------------------------------------
-
--- read a document containing a binary tree of 2^i leafs
-
-main2	:: String -> (String -> [String]) -> Int -> IO ()
-main2 ext lines' i
-    = do
-      hPutStrLn stderr "start processing"
-      h  <- openBinaryFile (fn i) ReadMode
-      c  <- hGetContents h
-      let ls = lines' c
-      o  <- openBinaryFile (fn i ++ "." ++ ext) WriteMode
-      mapM_ (hPutStrLn o) ls
-      hClose o
-      hClose h
-      hPutStrLn stderr "end  processing"
-
-relines		:: String -> [String]
-relines		= tokenize "[^\n\r]*"
-
-rewords		:: String -> [String]
-rewords		= tokenize "[^ \t\n\r]+"
-
--- ----------------------------------------
-
-pn	:: String -> String
-pn	= reverse . takeWhile (/= '/') . reverse
-
-fn	:: Int -> String
-fn	= ("tree-" ++) . (++ ".xml") . reverse . take 4 . reverse . ((replicate 4 '0') ++ ) . show
-
--- ----------------------------------------
-
-genDoc		:: Int -> String -> IOSArrow b XmlTree
-genDoc d out    = constA (mkBTree d)
-		  >>>
-		  xpickleVal xpickle
-		  >>>
-		  indentDoc
-		  >>>
-		  putDoc out
-
--- ----------------------------------------
-
-type Counter a	= State Int a
-
-incr	:: Counter Int
-incr	= do
-	  modify (+1)
-	  get
-
--- ----------------------------------------
-
-data BTree	= Leaf Int
-		| Fork BTree BTree
-		  deriving (Show)
-
-instance XmlPickler BTree where
-    xpickle = xpAlt tag ps
-	where
-	tag (Leaf _	) = 0
-	tag (Fork _ _	) = 1
-	ps = [ xpWrap ( Leaf, \ (Leaf i) -> i)
-	       ( xpElem "leaf" $ xpAttr "value" $ xpickle )
-
-	     , xpWrap ( uncurry Fork, \ (Fork l r) -> (l, r))
-	       ( xpElem "fork" $ xpPair xpickle xpickle )
-	       ]
-
--- ----------------------------------------
-
-mkBTree		:: Int -> BTree
-mkBTree	depth	= evalState (mkT depth) 0
-
-mkT	:: Int -> Counter BTree
-mkT 0	= do
-	  i <- incr
-	  return (Leaf i)
-mkT n	= do
-	  l <- mkT (n-1)
-	  r <- mkT (n-1)
-	  return (Fork l r)
-
--- ----------------------------------------
-
--- output is done with low level ops to write the
--- document i a lazy manner
--- adding an xml pi and encoding is done "by hand"
--- latin1 decoding is the identity, so please generate the
--- docs with latin1 encoding. Here ist done even with ASCCI
--- every none ASCII char is represented by a char ref (&nnn;)
-
-putDoc	:: String -> IOStateArrow s XmlTree XmlTree
-putDoc dst
-    = addXmlPi
-      >>>
-      addXmlPiEncoding isoLatin1
-      >>>
-      xshow getChildren
-      >>>
-      arr unicodeToXmlEntity
-      >>>
-      arrIO (\ s -> hPutDocument (\h -> hPutStrLn h s))
-      >>>
-      none
-      where
-      isStdout	= null dst || dst == "-"
-
-      hPutDocument	:: (Handle -> IO()) -> IO()
-      hPutDocument action
-	  | isStdout
-	      = action stdout
-	  | otherwise
-	      = do
-		handle <- openBinaryFile dst WriteMode
-		action handle
-		hClose handle
-
--- ----------------------------------------
diff --git a/examples/arrows/absurls/AbsURIs.hs b/examples/arrows/absurls/AbsURIs.hs
--- a/examples/arrows/absurls/AbsURIs.hs
+++ b/examples/arrows/absurls/AbsURIs.hs
@@ -9,9 +9,8 @@
    Maintainer : uwe@fh-wedel.de
    Stability  : experimental
    Portability: portable
-   Version    : $Id: AbsURIs.hs,v 1.1 2005/05/12 16:41:38 hxml Exp $
 
-AbsURIs - Conversion references into absolute URIs in HTML pages
+   AbsURIs - Conversion references into absolute URIs in HTML pages
 
 The commandline interface
 -}
@@ -21,9 +20,9 @@
 module Main
 where
 
-import Text.XML.HXT.Arrow		-- import all stuff for parsing, validating, and transforming XML
+import Text.XML.HXT.Core                -- import all stuff for parsing, validating, and transforming XML
 
-import System.IO			-- import the IO and commandline option stuff
+import System.IO                        -- import the IO and commandline option stuff
 import System.Environment
 import System.Console.GetOpt
 import System.Exit
@@ -38,16 +37,16 @@
 main :: IO ()
 main
     = do
-      argv <- getArgs					-- get the commandline arguments
-      (al, src) <- cmdlineOpts argv			-- and evaluate them, return a key-value list
-      [rc]  <- runX (parser al src)			-- run the parser arrow
-      exitProg (rc >= c_err)				-- set return code and terminate
+      argv <- getArgs                                   -- get the commandline arguments
+      (al, src) <- cmdlineOpts argv                     -- and evaluate them, return a key-value list
+      [rc]  <- runX (parser al src)                     -- run the parser arrow
+      exitProg (rc >= c_err)                            -- set return code and terminate
 
 -- ------------------------------------------------------------
 
-exitProg	:: Bool -> IO a
-exitProg True	= exitWith (ExitFailure (-1))
-exitProg False	= exitWith ExitSuccess
+exitProg        :: Bool -> IO a
+exitProg True   = exitWith (ExitFailure (-1))
+exitProg False  = exitWith ExitSuccess
 
 -- ------------------------------------------------------------
 
@@ -57,10 +56,12 @@
 -- get wellformed document, validates document, propagates and check namespaces
 -- and controls output
 
-parser	:: Attributes -> String -> IOSArrow b Int
-parser al src
-    = readDocument ([(a_parse_html, v_1)] ++ al) src
+parser  :: SysConfigList -> String -> IOSArrow b Int
+parser config src
+    = configSysVars config                            -- set all global config options
       >>>
+      readDocument [withParseHTML yes] src              -- use HTML parser
+      >>>
       traceMsg 1 "start processing"
       >>>
       processDocument
@@ -71,7 +72,7 @@
       >>>
       traceTree
       >>>
-      writeDocument al "-" `whenNot` hasAttr "no-output"
+      ( writeDocument [] $< getSysAttr "output-file" )
       >>>
       getErrStatus
 
@@ -80,51 +81,55 @@
 -- the options definition part
 -- see doc for System.Console.GetOpt
 
-progName	:: String
-progName	= "AbsURIs"
+progName        :: String
+progName        = "AbsURIs"
     
-options 	:: [OptDescr (String, String)]
+options         :: [OptDescr SysConfig]
 options
     = generalOptions
       ++
-      selectOptions [a_trace, a_proxy, a_use_curl, a_issue_warnings, a_do_not_issue_warnings, a_do_not_use_curl, a_options_curl, a_encoding] inputOptions
+      inputOptions
       ++
+      [ Option "f" ["output-file"] (ReqArg  (withSysAttr "output-file") "FILE")
+               "output file for resulting document (default: stdout)"
+      ]
+      ++
       outputOptions
       ++
       showOptions
 
-usage		:: [String] -> IO a
+usage           :: [String] -> IO a
 usage errl
     | null errl
-	= do
-	  hPutStrLn stdout use
-	  exitProg False
+        = do
+          hPutStrLn stdout use
+          exitProg False
     | otherwise
-	= do
-	  hPutStrLn stderr (concat errl ++ "\n" ++ use)
-	  exitProg True
+        = do
+          hPutStrLn stderr (concat errl ++ "\n" ++ use)
+          exitProg True
     where
     header = progName ++ " - Convert all references in an HTML document into absolute URIs\n\n" ++
              "Usage: " ++ progName ++ " [OPTION...] [URI or FILE]"
     use    = usageInfo header options
 
-cmdlineOpts 	:: [String] -> IO (Attributes, String)
+cmdlineOpts     :: [String] -> IO (SysConfigList, String)
 cmdlineOpts argv
     = case (getOpt Permute options argv) of
-      (ol,n,[])
-	  -> do
-	     sa <- src n
-	     help (lookup a_help ol) sa
-	     return (ol, sa)
+      (scfg,n,[])
+          -> do
+             sa <- src n
+             help (getConfigAttr a_help scfg) sa
+             return (scfg, sa)
       (_,_,errs)
-	  -> usage errs
+          -> usage errs
     where
-    src []	= return []
-    src [uri]	= return uri
-    src _	= usage ["only one input uri or file allowed\n"]
+    src []      = return []
+    src [uri]   = return uri
+    src _       = usage ["only one input uri or file allowed\n"]
 
-    help (Just _) _	= usage []
-    help Nothing []	= usage ["no input uri or file given\n"]
-    help Nothing _	= return ()
+    help "1" _  = usage []
+    help _ []   = usage ["no input uri or file given\n"]
+    help _ _    = return ()
 
 -- ------------------------------------------------------------
diff --git a/examples/arrows/absurls/ProcessDocument.hs b/examples/arrows/absurls/ProcessDocument.hs
--- a/examples/arrows/absurls/ProcessDocument.hs
+++ b/examples/arrows/absurls/ProcessDocument.hs
@@ -9,11 +9,10 @@
    Maintainer : uwe@fh-wedel.de
    Stability  : experimental
    Portability: portable
-   Version    : $Id: ProcessDocument.hs,v 1.2 2005/05/15 17:01:04 hxml Exp $
 
-AbsURIs - Conversion references into absolute URIs in HTML pages
+   AbsURIs - Conversion references into absolute URIs in HTML pages
 
-The REAL processing functions
+   The REAL processing functions
 -}
 
 -- ------------------------------------------------------------
@@ -22,7 +21,7 @@
     ( processDocument )
 where
 
-import Text.XML.HXT.Arrow		-- import all stuff for parsing, validating, and transforming XML
+import Text.XML.HXT.Core		-- import all stuff for parsing, validating, and transforming XML
 
 import Data.Maybe
 
diff --git a/examples/arrows/dtd2hxt/DTDtoHXT.hs b/examples/arrows/dtd2hxt/DTDtoHXT.hs
--- a/examples/arrows/dtd2hxt/DTDtoHXT.hs
+++ b/examples/arrows/dtd2hxt/DTDtoHXT.hs
@@ -4,22 +4,20 @@
 --
 -- Author : Uwe Schmidt
 --
--- Version : $Id: DTDtoHXT.hs,v 1.3 2005/04/14 12:52:50 hxml Exp $
---
 -- this program may be used as example main program for the
 -- Haskell XML Toolbox
 
 module Main
 where
 
-import Text.XML.HXT.Arrow		-- import all stuff for parsing, validating, and transforming XML
+import Text.XML.HXT.Core                -- import all stuff for parsing, validating, and transforming XML
+import Text.XML.HXT.Curl
 
-import System.IO			-- import the IO and commandline option stuff
+import System.IO                        -- import the IO and commandline option stuff
 import System.Environment
 import System.Console.GetOpt
 import System.Exit
 
-import Data.Maybe
 import Data.Char
 import Data.List
 
@@ -31,43 +29,43 @@
 main :: IO ()
 main
     = do
-      argv <- getArgs					-- get the commandline arguments
-      (al, src) <- cmdlineOpts argv				-- and evaluate them, return a key-value list
+      argv <- getArgs                                   -- get the commandline arguments
+      (al, src) <- cmdlineOpts argv                             -- and evaluate them, return a key-value list
       [rc] <- runX (dtd2hxt al src)
       exitProg (rc >= c_err)
 
 -- ------------------------------------------------------------
 
-exitProg	:: Bool -> IO a
-exitProg True	= exitWith (ExitFailure (-1))
-exitProg False	= exitWith ExitSuccess
+exitProg        :: Bool -> IO a
+exitProg True   = exitWith (ExitFailure (-1))
+exitProg False  = exitWith ExitSuccess
 
 -- ------------------------------------------------------------
 --
 -- options
 
-uppercaseInitials, namespaceAware, prefixUnderline	:: String
+uppercaseInitials, namespaceAware, prefixUnderline      :: String
 
-uppercaseInitials	= "uppercase-initials"
-namespaceAware		= "namespace-aware"
-prefixUnderline		= "prefix-underline"
+uppercaseInitials       = "uppercase-initials"
+namespaceAware          = "namespace-aware"
+prefixUnderline         = "prefix-underline"
 
 -- name prefixes
 
 tagPrefix, attPrefix, nsPrefix, isPrefix, mkPrefix, hasPrefix, getPrefix
  , mkAttPrefix, mkSAttPrefix
- , nsDefault	:: String
+ , nsDefault    :: String
 
-tagPrefix	= "tag"
-attPrefix	= "attr"
-nsPrefix	= "ns"
-isPrefix	= "is"
-mkPrefix	= "e"
-hasPrefix	= "has"
-getPrefix	= "get"
-mkAttPrefix	= "a"
-mkSAttPrefix	= "sa"
-nsDefault	= "default"
+tagPrefix       = "tag"
+attPrefix       = "attr"
+nsPrefix        = "ns"
+isPrefix        = "is"
+mkPrefix        = "e"
+hasPrefix       = "has"
+getPrefix       = "get"
+mkAttPrefix     = "a"
+mkSAttPrefix    = "sa"
+nsDefault       = "default"
 
 -- ------------------------------------------------------------
 
@@ -78,10 +76,14 @@
 -- (this would remove the DTD),
 -- and controls output
 
-dtd2hxt	:: Attributes -> String -> IOSArrow b Int
-dtd2hxt al src
-    = readDocument ((a_canonicalize, v_0) : al) src
+dtd2hxt :: SysConfigList -> String -> IOSArrow b Int
+dtd2hxt config src
+    = configSysVars config                            -- set all global config options
       >>>
+      readDocument [withCanonicalize no
+                   ,withCurl []
+                   ] src
+      >>>
       traceMsg 1 "start processing DTD"
       >>>
       processChildren (isDTD `guards` genHXT)
@@ -92,195 +94,195 @@
       >>>
       traceTree
       >>>
-      writeDocument ((a_output_xml, v_0) : al) (fromMaybe "" (lookup a_output_file al))
+      ( writeDocument [withOutputPLAIN] $< getSysAttr "output-file" )
       >>>
       getErrStatus
     where
     genHXT
-	= catA $ map (>>> mkText) $
-	  [ getModuleName				-- the module header
-	    >>>
-	    arr genModHead
+        = catA $ map (>>> mkText) $
+          [ getModuleName                               -- the module header
+            >>>
+            arr genModHead
 
-	  , constA $ comm "namespace declarations"
+          , constA $ comm "namespace declarations"
 
-	  , getNSAttr					-- namespace constants
-	    >>>						-- declared as "xmlns" or "xmlns:<ns>" attribute with #FIXED values
-	    arr2 genNSCode
+          , getNSAttr                                   -- namespace constants
+            >>>                                         -- declared as "xmlns" or "xmlns:<ns>" attribute with #FIXED values
+            arr2 genNSCode
 
-	  , constA $ comm "element arrows"
+          , constA $ comm "element arrows"
 
-	  , getElems >>. sort				-- element processing
-	    >>>
-	    arr genElemCode
+          , getElems >>. sort                           -- element processing
+            >>>
+            arr genElemCode
 
-          , getAttrs >>. ( sort . nub )			-- attribute processing
+          , getAttrs >>. ( sort . nub )                 -- attribute processing
             >>>
-	    arr genAttrCode
+            arr genAttrCode
 
-          , getModuleName				-- module footer
+          , getModuleName                               -- module footer
             >>> arr genModFoot
-	  ]
+          ]
 
     -- auxiliary arrows --------------------------------------------------
 
-    getModuleName	:: (ArrowXml a, ArrowDTD a) => a XmlTree String
+    getModuleName       :: (ArrowXml a, ArrowDTD a) => a XmlTree String
     getModuleName
-	= isDTDDoctype
-	  >>>
-	  getDTDAttrValue a_name
-	  >>>
-	  arr moduleName
+        = isDTDDoctype
+          >>>
+          getDTDAttrValue a_name
+          >>>
+          arr moduleName
 
     -- filter namespace attributes ----------------------------------------
 
-    getNSAttr	::  (ArrowXml a, ArrowDTD a) => a XmlTree (String, String)
+    getNSAttr   ::  (ArrowXml a, ArrowDTD a) => a XmlTree (String, String)
     getNSAttr
-	= deep isDTDAttlist
-	  >>>
-	  ( ( getDTDAttrValue a_value >>> isA (\ s -> s == "xmlns" || "xmlns:" `isPrefixOf` s)
-	    )
-	    `guards`
-	    ( ( getDTDAttrValue a_kind >>> isA (== k_fixed)
-	      )
-	      `guards`
-	      ( ( getDTDAttrValue a_value >>> arr (drop 6) )				-- remove "xmlns:" prefix
-		&&&
-		getDTDAttrValue a_default
-	      )
-	    )
-	  )
+        = deep isDTDAttlist
+          >>>
+          ( ( getDTDAttrValue a_value >>> isA (\ s -> s == "xmlns" || "xmlns:" `isPrefixOf` s)
+            )
+            `guards`
+            ( ( getDTDAttrValue a_kind >>> isA (== k_fixed)
+              )
+              `guards`
+              ( ( getDTDAttrValue a_value >>> arr (drop 6) )                            -- remove "xmlns:" prefix
+                &&&
+                getDTDAttrValue a_default
+              )
+            )
+          )
 
-    getElems	::  (ArrowXml a, ArrowDTD a) => a XmlTree String
+    getElems    ::  (ArrowXml a, ArrowDTD a) => a XmlTree String
     getElems
-	= deep isDTDElement
-	  >>>
-	  getDTDAttrValue a_name
+        = deep isDTDElement
+          >>>
+          getDTDAttrValue a_name
 
-    getAttrs	::  (ArrowXml a, ArrowDTD a) => a XmlTree String
+    getAttrs    ::  (ArrowXml a, ArrowDTD a) => a XmlTree String
     getAttrs
-	= deep isDTDAttlist
-	  >>>
-	  getDTDAttrValue a_value
+        = deep isDTDAttlist
+          >>>
+          getDTDAttrValue a_value
 
     -- code generation ------------------------------------------------------------
 
-    genModHead	:: String -> String
+    genModHead  :: String -> String
     genModHead rootElem
-	= code [ sepl
-	       , "--"
-	       , "-- don't edit this module"
-	       , "-- generated with " ++ progName
-	       , "-- simple access function for Haskell XML Toolbox"
-	       , "-- generated from DTD of document: " ++ show src
-	       , ""
-	       , "module " ++ rootElem ++ " ( module " ++ rootElem ++ " )"
-	       , "where"
-	       , ""
-	       , "import           Text.XML.HXT.Arrow (XmlTree, ArrowXml, (>>>))"
-	       , "import qualified Text.XML.HXT.Arrow as X (attr, eelem, getAttrValue, hasAttr, hasName, isElem, sattr)"
-	       ]
+        = code [ sepl
+               , "--"
+               , "-- don't edit this module"
+               , "-- generated with " ++ progName
+               , "-- simple access function for Haskell XML Toolbox"
+               , "-- generated from DTD of document: " ++ show src
+               , ""
+               , "module " ++ rootElem ++ " ( module " ++ rootElem ++ " )"
+               , "where"
+               , ""
+               , "import           Text.XML.HXT.Core      (XmlTree, ArrowXml, (>>>))"
+               , "import qualified Text.XML.HXT.Core as X (attr, eelem, getAttrValue, hasAttr, hasName, isElem, sattr)"
+               ]
 
-    genNSCode	:: String -> String -> String
+    genNSCode   :: String -> String -> String
     genNSCode prefix ns
-	= code [ ns' ++ "\t:: String"
-	       , ns' ++ "\t=  " ++ show ns
-	       ]
-	where
-	ns' = nsPrefix ++ nn (if null prefix then nsDefault else prefix)
+        = code [ ns' ++ "\t:: String"
+               , ns' ++ "\t=  " ++ show ns
+               ]
+        where
+        ns' = nsPrefix ++ nn (if null prefix then nsDefault else prefix)
 
-    genElemCode	:: String -> String
-    genElemCode	n
-	= code [ comm ("arrows for element " ++ show n)
-	       , tagN ++ "\t:: String"
-	       , tagN ++ "\t=  " ++ show n
-	       , ""
-	       , isN  ++ "\t:: ArrowXml a => a XmlTree XmlTree"
-	       , isN  ++ "\t=  X.isElem >>> X.hasName " ++ tagN
-	       , ""
-	       , mkN  ++ "\t:: ArrowXml a => a n XmlTree"
-	       , mkN  ++ "\t=  X.eelem " ++ tagN
-	       ]
-	where
-	tagN	= tagPrefix ++ nn n
-	isN	= isPrefix  ++ nn n
-	mkN	= mkPrefix  ++ nn n
+    genElemCode :: String -> String
+    genElemCode n
+        = code [ comm ("arrows for element " ++ show n)
+               , tagN ++ "\t:: String"
+               , tagN ++ "\t=  " ++ show n
+               , ""
+               , isN  ++ "\t:: ArrowXml a => a XmlTree XmlTree"
+               , isN  ++ "\t=  X.isElem >>> X.hasName " ++ tagN
+               , ""
+               , mkN  ++ "\t:: ArrowXml a => a n XmlTree"
+               , mkN  ++ "\t=  X.eelem " ++ tagN
+               ]
+        where
+        tagN    = tagPrefix ++ nn n
+        isN     = isPrefix  ++ nn n
+        mkN     = mkPrefix  ++ nn n
 
-    genAttrCode	:: String -> String
-    genAttrCode	n
-	= code [ comm ("arrows for attribute " ++ show n)
-	       , attN ++ "\t:: String"
-	       , attN ++ "\t=  " ++ show n
-	       , ""
-	       , hasN ++ "\t:: ArrowXml a => a XmlTree XmlTree"
-	       , hasN ++ "\t=  X.hasAttr " ++ attN
-	       , ""
-	       , getN ++ "\t:: ArrowXml a => a XmlTree String"
-	       , getN ++ "\t=  X.getAttrValue " ++ attN
-	       , ""
-	       , mkN  ++ "\t:: ArrowXml a => a n XmlTree -> a n XmlTree"
-	       , mkN  ++ "\t=  X.attr " ++ attN
-	       , ""
-	       , mksN ++ "\t:: ArrowXml a => String -> a n XmlTree"
-	       , mksN ++ "\t=  X.sattr " ++ attN
-	       ]
-	where
-	attN	= attPrefix ++ nn n
-	hasN	= hasPrefix  ++ nn n
-	getN	= getPrefix  ++ nn n ++ nn "value"
-	mkN	= mkAttPrefix ++ nn n
-	mksN	= mkSAttPrefix ++ nn n
+    genAttrCode :: String -> String
+    genAttrCode n
+        = code [ comm ("arrows for attribute " ++ show n)
+               , attN ++ "\t:: String"
+               , attN ++ "\t=  " ++ show n
+               , ""
+               , hasN ++ "\t:: ArrowXml a => a XmlTree XmlTree"
+               , hasN ++ "\t=  X.hasAttr " ++ attN
+               , ""
+               , getN ++ "\t:: ArrowXml a => a XmlTree String"
+               , getN ++ "\t=  X.getAttrValue " ++ attN
+               , ""
+               , mkN  ++ "\t:: ArrowXml a => a n XmlTree -> a n XmlTree"
+               , mkN  ++ "\t=  X.attr " ++ attN
+               , ""
+               , mksN ++ "\t:: ArrowXml a => String -> a n XmlTree"
+               , mksN ++ "\t=  X.sattr " ++ attN
+               ]
+        where
+        attN    = attPrefix ++ nn n
+        hasN    = hasPrefix  ++ nn n
+        getN    = getPrefix  ++ nn n ++ nn "value"
+        mkN     = mkAttPrefix ++ nn n
+        mksN    = mkSAttPrefix ++ nn n
 
-    genModFoot	:: String -> String
+    genModFoot  :: String -> String
     genModFoot rootElem
-	= comm ( "end of module " ++ rootElem)
+        = comm ( "end of module " ++ rootElem)
 
     -- string manipulation --------------------------------------------------
 
-    code	:: [String] -> String
-    code	= concatMap (++ "\n")
+    code        :: [String] -> String
+    code        = concatMap (++ "\n")
 
-    comm	:: String -> String
-    comm cm	=  code [ "", sepl, "--", "-- " ++ cm, ""]
+    comm        :: String -> String
+    comm cm     =  code [ "", sepl, "--", "-- " ++ cm, ""]
 
-    sepl	:: String
-    sepl	= "-- ----------------------------------------"
+    sepl        :: String
+    sepl        = "-- ----------------------------------------"
 
-    moduleName	:: String -> String
+    moduleName  :: String -> String
     moduleName rootElem
-	= modname . fromMaybe rootElem . lookup a_output_file $ al
+        = modname . (\ x -> if null x then rootElem else x) . getConfigAttr "output_file" $ config
 
     modname
-	= (\ x -> toUpper (head x) : tail x)
-	  . reverse
-	  . (\ n -> if '.' `elem` n				-- remove extension
-		    then drop 1 . dropWhile (/= '.') $ n
-		    else n
-	    )
-	  . takeWhile (/= '/')					-- remove dir path
-	  . reverse
+        = (\ x -> toUpper (head x) : tail x)
+          . reverse
+          . (\ n -> if '.' `elem` n                             -- remove extension
+                    then drop 1 . dropWhile (/= '.') $ n
+                    else n
+            )
+          . takeWhile (/= '/')                                  -- remove dir path
+          . reverse
 
-    nn		:: String -> String
+    nn          :: String -> String
     nn
-	= trInitial . concatMap nc				-- normalize names
+        = trInitial . concatMap nc                              -- normalize names
 
-    nc		:: Char -> String
+    nc          :: Char -> String
     nc c
-	| c `elem` ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ "_"	= [c]
-	| c == ':' || c == '-'					= "_" 
-	| otherwise							= ("_" ++) . show . fromEnum $ c
+        | c `elem` ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ "_"        = [c]
+        | c == ':' || c == '-'                                  = "_" 
+        | otherwise                                                     = ("_" ++) . show . fromEnum $ c
 
-    trInitial	:: String -> String
+    trInitial   :: String -> String
     trInitial str
-	| null str	= str
-	| underLn	= '_' : str
-	| upperCs	= toUpper (head str) : tail str
-	| otherwise	= str
+        | null str      = str
+        | underLn       = '_' : str
+        | upperCs       = toUpper (head str) : tail str
+        | otherwise     = str
 
-    upperCs, underLn {-, nsAware -}	:: Bool
-    upperCs	= isJust . lookup uppercaseInitials	$ al
-    underLn	= isJust . lookup prefixUnderline	$ al
-    {- nsAware 	= isJust . lookup namespaceAware	$ al -}
+    upperCs, underLn {-, nsAware -}     :: Bool
+    upperCs     = (== "1") . getConfigAttr uppercaseInitials    $ config
+    underLn     = (== "1") . getConfigAttr prefixUnderline      $ config
+    _nsAware    = (== "1") . getConfigAttr namespaceAware       $ config
 
 -- ------------------------------------------------------------
 --
@@ -288,64 +290,62 @@
 --
 -- see doc for System.Console.GetOpt
 
-progName	:: String
-progName	= "DTDtoHXT"
+progName        :: String
+progName        = "DTDtoHXT"
     
-options 	:: [OptDescr (String, String)]
+options         :: [OptDescr SysConfig]
 options
     = selectOptions [ a_help
-		    ] generalOptions
+                    ] generalOptions
       ++
       selectOptions [ a_trace
-		    , a_proxy
-		    , a_use_curl
-		    , a_options_curl
-		    , a_encoding
-		    , a_validate
-		    , a_check_namespaces
-		    ] inputOptions
+                    , a_proxy
+                    , a_encoding
+                    , a_validate
+                    , a_check_namespaces
+                    ] inputOptions
       ++
-      selectOptions [ a_output_file
-		    ] outputOptions
+      selectOptions [ "output-file"
+                    ] outputOptions
       ++
-      [ Option "u"	[prefixUnderline]	(NoArg	(prefixUnderline,   v_1))	"separate tag and attribute names with a '_'"
-      , Option "U"	[uppercaseInitials]	(NoArg	(uppercaseInitials, v_1))	"transform the first char of tag and attribute names to uppercase"
-      -- , Option "N"	[namespaceAware]	(NoArg	(namespaceAware,    v_1))	"filter are namespace aware, if namespace attributes occur in the DTD"
+      [ Option "u"      [prefixUnderline]       (NoArg $ withSysAttr prefixUnderline "1")       "separate tag and attribute names with a '_'"
+      , Option "U"      [uppercaseInitials]     (NoArg $ withSysAttr uppercaseInitials "1")     "transform the first char of tag and attribute names to uppercase"
+      , Option "N"      [namespaceAware]        (NoArg $ withSysAttr namespaceAware "1")        "filter are namespace aware, if namespace attributes occur in the DTD"
       ]
       ++
       showOptions
 
-usage		:: [String] -> IO a
+usage           :: [String] -> IO a
 usage errl
     | null errl
-	= do
-	  hPutStrLn stdout use
-	  exitProg False
+        = do
+          hPutStrLn stdout use
+          exitProg False
     | otherwise
-	= do
-	  hPutStrLn stderr (concat errl ++ "\n" ++ use)
-	  exitProg True
+        = do
+          hPutStrLn stderr (concat errl ++ "\n" ++ use)
+          exitProg True
     where
     header = "DTDtoHXml - Generation of access function for the Haskell XML Toolbox from a DTD\n" ++
              "Usage: " ++ progName ++ " [OPTION...] [URI or FILE]"
     use    = usageInfo header options
 
-cmdlineOpts 	:: [String] -> IO (Attributes, String)
+cmdlineOpts     :: [String] -> IO (SysConfigList, String)
 cmdlineOpts argv
     = case (getOpt Permute options argv) of
       (ol,n,[]  )
-	  -> do
-	     sa <- src n
-	     help (lookup a_help ol)
-	     return (ol, sa)
+          -> do
+             sa <- src n
+             help (getConfigAttr a_help ol)
+             return (ol, sa)
       (_,_,errs)
-	  -> usage errs
+          -> usage errs
     where
-    src [uri]	= return uri
-    src []	= usage ["input file/uri missing"]
-    src _	= usage ["only one input url or file allowed\n"]
+    src [uri]   = return uri
+    src []      = usage ["input file/uri missing"]
+    src _       = usage ["only one input url or file allowed\n"]
 
-    help Nothing	= return ()
-    help (Just _)	= usage []
+    help "1"    = usage []
+    help _      = return ()
 
 -- ------------------------------------------------------------
diff --git a/examples/arrows/hparser/HXmlParser.hs b/examples/arrows/hparser/HXmlParser.hs
--- a/examples/arrows/hparser/HXmlParser.hs
+++ b/examples/arrows/hparser/HXmlParser.hs
@@ -10,7 +10,7 @@
    Stability  : experimental
    Portability: portable
 
-   HXmlParser - Validating XML Parser of the Haskell XML Toolbox
+   HXmlParser - Minimal Validating XML Parser of the Haskell XML Toolbox, no HTTP supported
 
    XML well-formed checker and validator.
 
@@ -28,15 +28,13 @@
 module Main
 where
 
-import Text.XML.HXT.Arrow		-- import all stuff for parsing, validating, and transforming XML
+import Text.XML.HXT.Core                -- import all stuff for parsing, validating, and transforming XML
 
-import System.IO			-- import the IO and commandline option stuff
+import System.IO                        -- import the IO and commandline option stuff
 import System.Environment
 import System.Console.GetOpt
 import System.Exit
 
-import Data.Maybe
-
 -- ------------------------------------------------------------
 
 -- |
@@ -45,16 +43,16 @@
 main :: IO ()
 main
     = do
-      argv <- getArgs					-- get the commandline arguments
-      (al, src) <- cmdlineOpts argv			-- and evaluate them, return a key-value list
-      [rc]  <- runX (parser al src)			-- run the parser arrow
-      exitProg (rc >= c_err)				-- set return code and terminate
+      argv <- getArgs                                   -- get the commandline arguments
+      (al, src) <- cmdlineOpts argv                     -- and evaluate them, return a key-value list
+      [rc]  <- runX (parser al src)                     -- run the parser arrow
+      exitProg (rc >= c_err)                            -- set return code and terminate
 
 -- ------------------------------------------------------------
 
-exitProg	:: Bool -> IO a
-exitProg True	= exitWith (ExitFailure (-1))
-exitProg False	= exitWith ExitSuccess
+exitProg        :: Bool -> IO a
+exitProg True   = exitWith (ExitFailure (-1))
+exitProg False  = exitWith ExitSuccess
 
 -- ------------------------------------------------------------
 
@@ -64,98 +62,109 @@
 -- get wellformed document, validates document, propagates and check namespaces
 -- and controls output
 
-parser	:: Attributes -> String -> IOSArrow b Int
-parser al src
-    = readDocument al src
+parser  :: SysConfigList -> String -> IOSArrow b Int
+parser config src
+    = configSysVars config                            -- set all global config options, the output file and the
+      >>>                                               -- other user options are stored as key-value pairs in the stystem state
+      readDocument [] src                               -- no more special read options needed
       >>>
       ( ( traceMsg 1 "start processing document"
-	  >>>
-	  processDocument al
-	  >>>
-	  traceMsg 1 "document processing finished"
-	)
-	`when`
-	documentStatusOk
+          >>>
+          ( processDocument $< getSysAttr "action" )    -- ask for the action stored in the key-value list of user defined values 
+          >>>
+          traceMsg 1 "document processing finished"
+        )
+        `when`
+        documentStatusOk
       )
       >>>
       traceSource
       >>>
       traceTree
       >>>
-      writeDocument al (fromMaybe "-" . lookup a_output_file $ al) `whenNot` hasAttr "no-output"
+      ( (writeDocument [] $< getSysAttr "output-file")  -- ask for the output file stored in the system configuration
+        `whenNot`
+        ( getSysAttr "no-output" >>> isA (== "1") )     -- ask for the no-output attr value in the system key-value list
+      )
       >>>
       getErrStatus
 
--- simple example of a processing arrow
+-- simple example of a processing arrow, selected by a command line option
 
-processDocument	:: Attributes -> IOSArrow XmlTree XmlTree
-processDocument al
-    | extractText
-	= traceMsg 1 "selecting plain text"
-	  >>>
-	  processChildren (deep isText)
-    | otherwise
-	= this
-    where
-    extractText	= optionIsSet "show-text" $ al
+processDocument :: String -> IOSArrow XmlTree XmlTree
+processDocument "only-text"
+    = traceMsg 1 "selecting plain text"
+      >>>
+      processChildren (deep isText)
 
+processDocument "indent"
+    = traceMsg 1 "indent document"
+      >>>
+      indentDoc
+
+processDocument _action
+    = traceMsg 1 "default action: do nothing"
+      >>>
+      this
+
 -- ------------------------------------------------------------
 --
 -- the options definition part
 -- see doc for System.Console.GetOpt
 
-progName	:: String
-progName	= "HXmlParser"
+progName        :: String
+progName        = "HXmlParser"
     
-options 	:: [OptDescr (String, String)]
+options         :: [OptDescr SysConfig]
 options
     = generalOptions
       ++
       inputOptions
       ++
-      relaxOptions
-      ++
       outputOptions
       ++
-      [ Option "q"	["no-output"]		(NoArg  ("no-output", "1"))		"no output of resulting document"
-      , Option "x"	["show-text"]		(NoArg	("show-text", "1"))		"output only the raw text, remove all markup"
-      ]
-      ++
       showOptions
+      ++
+      [ Option "f"      ["output-file"] (ReqArg  (withSysAttr "output-file") "FILE") "output file for resulting document (default: stdout)"
+      , Option "q"      ["no-output"]   (NoArg $  withSysAttr "no-output"      "1")   "no output of resulting document"
+      , Option "x"      ["action"]      (ReqArg  (withSysAttr "action")   "ACTION")   "actions are: only-text, indent, no-op"
+      ]
+      -- the last 2 option values will be stored by withAttr in the system key-value list
+      -- and can be read by getSysAttr key
 
-usage		:: [String] -> IO a
+usage           :: [String] -> IO a
 usage errl
     | null errl
-	= do
-	  hPutStrLn stdout use
-	  exitProg False
+        = do
+          hPutStrLn stdout use
+          exitProg False
     | otherwise
-	= do
-	  hPutStrLn stderr (concat errl ++ "\n" ++ use)
-	  exitProg True
+        = do
+          hPutStrLn stderr (concat errl ++ "\n" ++ use)
+          exitProg True
     where
     header = "HXmlParser - Validating XML Parser of the Haskell XML Toolbox with Arrow Interface\n" ++
-             "XML well-formed checker, DTD validator, Relax NG validator.\n\n" ++
+             "XML well-formed checker, DTD validator, HTML parser.\n\n" ++
              "Usage: " ++ progName ++ " [OPTION...] [URI or FILE]"
     use    = usageInfo header options
 
-cmdlineOpts 	:: [String] -> IO (Attributes, String)
+cmdlineOpts     :: [String] -> IO (SysConfigList, String)
 cmdlineOpts argv
     = case (getOpt Permute options argv) of
-      (ol,n,[])
-	  -> do
-	     sa <- src n
-	     help (lookup a_help ol) sa
-	     return (ol, sa)
+      (scfg,n,[])
+          -> do
+             sa <- src n
+             help (getConfigAttr a_help scfg) sa
+             return (scfg, sa)
       (_,_,errs)
-	  -> usage errs
+          -> usage errs
     where
-    src []	= return []
-    src [uri]	= return uri
-    src _	= usage ["only one input uri or file allowed\n"]
+    src []      = return []
+    src [uri]   = return uri
+    src _       = usage ["only one input uri or file allowed\n"]
 
-    help (Just _) _	= usage []
-    help Nothing []	= usage ["no input uri or file given\n"]
-    help Nothing _	= return ()
+    help "1" _  = usage []
+    help _ []   = usage ["no input uri or file given\n"]
+    help _ _    = return ()
 
 -- ------------------------------------------------------------
diff --git a/examples/arrows/hparser/Makefile b/examples/arrows/hparser/Makefile
--- a/examples/arrows/hparser/Makefile
+++ b/examples/arrows/hparser/Makefile
@@ -29,7 +29,7 @@
 		@echo "===> first see all command line options"
 		$(prog) --help
 		@echo
-		$(MAKE) test0 test1 test2 test3 test4 test5
+		$(MAKE) test0 test1 test2 test3 test4
 
 EX1		= ./example1.xml
 EXi		= ./invalid.xml
@@ -74,7 +74,7 @@
 		$(prog) --show-tree --output-encoding=ISO-8859-1 $(EX1)
 		@echo
 		@sleep 2 ; echo ; echo "===> once again, but without any markup" ; echo ; sleep 2
-		$(prog) --show-text --output-encoding=ISO-8859-1 $(EX1)
+		$(prog) --action=only-text --output-encoding=ISO-8859-1 $(EX1)
 		@echo
 
 test2		:
@@ -84,14 +84,14 @@
 		@sleep 2 ; echo ; echo "===> parser will validate this document and try to indent the output" ; echo ; sleep 2
 		$(prog) --indent $(EX2)
 		@sleep 2 ; echo ; echo "===> once again, but remove all markup" ; echo ; sleep 2
-		$(prog) --show-text --remove-whitespace $(EX2)
+		$(prog) --action=only-text --remove-whitespace $(EX2)
 		@sleep 2 ; echo ; echo "===> once again with hdom tree output" ; echo ; sleep 2
 		$(prog) --show-tree --remove-whitespace $(EX2)
 
 test3		:
 		@echo "===> namespace processing examples" ; echo ; sleep 2
 		@echo "===> namespace propagation test" ; echo ; sleep 2
-		$(prog) --verbose --check-namespaces  --indent --output-encoding=ISO-8859-1 $(EX3)
+		$(prog) --verbose --check-namespaces  --indent --output-encoding=UTF-8 $(EX3)
 		@echo
 		@echo ; sleep 2 ; echo "===> namespace propagation test: tree output with attached namespaces" ; echo ; sleep 2
 		$(prog) --verbose --check-namespaces  --remove-whitespace --show-tree --output-encoding=ISO-8859-1 $(EX3)
@@ -107,51 +107,12 @@
 		cat $(EX4)
 		@sleep 2 ; echo ; echo "===> parser accepts this document and tries to build a document tree" ; echo ; sleep 2
 		$(prog) --indent --preserve-comment --parse-html $(EX4)
-		@sleep 2 ; echo ; echo "===> same with lazy parser with tagsoup" ; echo ; sleep 2
-		$(prog) -H -T -r --indent $(EX4)
-		@echo
 		@echo "===> the source of another lousy html document containing empty elements" ; echo ; sleep 2
 		cat $(EX4a)
 		@sleep 2 ; echo ; echo "===> parser accepts this document and tries to format this as a HTML document without any dangarous empty elements" ; echo ; sleep 2
 		$(prog) --indent --preserve-comment --parse-html --output-html --no-empty-elements $(EX4a)
 		@echo
 
-
-test5		:
-		@echo "===> Validate a valid xml file with respect to a valid Relax NG schema" ; echo ; sleep 1
-		@echo "the XML document ./valid1.xml"
-		@cat ./valid1.xml
-		@echo "the Relax NG schema ./valid1.rng"
-		@cat  ./valid1.rng
-		@echo
-		$(prog) --relax-schema ./valid1.rng ./valid1.xml
-		@echo
-		@echo "===> Validate an  invalid xml file with respect to a valid Relax NG schema" ; echo ; sleep 1
-		@echo "the invalid XML document ./invalid1.xml"
-		@cat ./valid1.xml
-		$(prog) --relax-schema ./valid1.rng ./invalid1.xml || true
-		@echo
-		@echo "===> Incorrect Relax NG schema" ; echo ; sleep 1
-		$(prog) --relax-schema ./invalid2.rng ./valid1.xml || true
-		@echo
-		@echo "===> Incorrect Relax NG schema with two errors" ; echo ; sleep 1
-		$(prog) --relax-schema ./invalid3.rng ./valid1.xml || true
-		@echo
-
-test6		:
-		@echo "===> tagsoup parsing examples" ; echo ; sleep 2
-		@echo "===> lousy HTML document" ; echo ; sleep 2
-		$(prog) --tagsoup --parse-html lousy.html
-		@echo "===> www.w3c.org homepage (valid XHTML)" ; echo ; sleep 2
-		$(prog) --tagsoup http://www.w3c.org/
-		@echo "===> same again with removed whitespace and tree output" ; echo ; sleep 2
-		$(prog) --tagsoup --remove-whitespace --show-tree http://www.w3c.org/
-		@echo "===> same procedure with www.haskell.org homepage (rather valid HTML)" ; echo ; sleep 2
-		$(prog) --tagsoup --parse-html http://www.haskell.org/
-		@echo "===> same again with removed whitespace and tree output" ; echo ; sleep 2
-		$(prog) --tagsoup --parse-html --remove-whitespace --show-tree http://www.haskell.org/
-		@echo
-
 dist		:
 		[ -d $(DIST_DIR) ] || mkdir -p $(DIST_DIR)
 		cp $(EX) Makefile $(prog).hs $(DIST_DIR)
@@ -159,4 +120,4 @@
 clean		:
 		rm -f $(prog) *.o *.hi
 
-.PHONY		: all test test0 test1 test2 test3 test4 test5 test6 dist clean prof local force
+.PHONY		: all test test0 test1 test2 test3 test4 dist clean prof local force
diff --git a/examples/arrows/hrelaxng/.ghci b/examples/arrows/hrelaxng/.ghci
deleted file mode 100644
--- a/examples/arrows/hrelaxng/.ghci
+++ /dev/null
@@ -1,3 +0,0 @@
-:set -i../../../src
-:set -Wall -fglasgow-exts
-:load HRelaxNG
diff --git a/examples/arrows/hrelaxng/HRelaxNG.hs b/examples/arrows/hrelaxng/HRelaxNG.hs
deleted file mode 100644
--- a/examples/arrows/hrelaxng/HRelaxNG.hs
+++ /dev/null
@@ -1,170 +0,0 @@
--- |
--- HRelaxNG - Relax NG Validator of the Haskell XML Toolbox.
--- RELAX NG is a simpler schema language for XML.
---
--- Author : Torben Kuseler
---
--- Version : $Id: HRelaxNG.hs,v 1.2 2005/09/30 14:41:44 hxml Exp $
---
--- This program may be used as example main program for the
--- Relax NG Validator.
---
-
-module Main
-where
-
-import System.IO
-import System.Environment
-import System.Console.GetOpt
-import System.Exit
-
-import Text.XML.HXT.Arrow 
-import Text.XML.HXT.RelaxNG
-
--- ------------------------------------------------------------
-
-
-main :: IO ()
-main
-  = do
-    argv <- getArgs                       -- get the commandline arguments
-    (al, xml, schema) <- cmdlineOpts argv -- and evaluate them, return a key-value list
-    [rc]  <- runX (relax al xml schema)   -- run the Relax NG validator 
-    exitProg (rc >= c_err)                -- set return code and terminate
-
-{-
-relax :: Attributes -> String -> String -> IOSArrow b Int
-relax al xml schema
-    = readDocument al schema
-      >>>
-      createSimpleForm
-      >>>
-      ( getErrors		-- compute errors in schema
-        `orElse`
-        validateXMLDoc [] xml	-- compute errors in document
-        `orElse`
-        root [] [txt "valid"]	-- or document is valid
-      )
-      >>>
-      writeDocument [(a_show_tree, "1")] "-"
-      >>>
-      getErrStatus
--}
-
-relax :: Attributes -> String -> String -> IOSArrow b Int
-relax al xml schema
-    = readDocument ( [ (a_check_namespaces, v_1)
-		     , (a_validate, v_0)
-		     ] ++ al
-		   ) xml
-      >>>
-      traceState
-      >>>
-      validateDocumentWithRelaxSchema al schema
-      >>>
-      traceState
-      >>>
-      writeDocument al "-"
-      >>>
-      getErrStatus
-
-
-exitProg        :: Bool -> IO a
-exitProg True   = exitWith (ExitFailure (-1))
-exitProg False  = exitWith ExitSuccess
-
-
-
--- ------------------------------------------------------------
---
--- the options definition part
--- see doc for System.Console.GetOpt
-
-progName    :: String
-progName    = "HRelaxNGValidator"
-
-options     :: [OptDescr (String, String)]
-options
-    = generalOptions
-      ++
-      inputOptions
-      ++
-      outputOptions
-      ++
-      relaxOptions
-
-usage :: [String] -> IO a
-usage errl
-    | null errl
-        = do
-          hPutStrLn stdout use
-          exitProg False
-    | otherwise
-        = do
-          hPutStrLn stderr (concat errl ++ "\n" ++ use)
-          exitProg True
-    where
-    header = "HRelaxNGValidator - Relax NG schema validator of the " ++
-             "Haskell XML Toolbox with Arrow Interface\n\n" ++
-             "Usage: " ++ progName ++ " [OPTION...] (XML file URI/FILE) (Relax NG Schema URI/FILE)"
-    use    = usageInfo header options
-
-cmdlineOpts :: [String] -> IO (Attributes, String, String)
-cmdlineOpts argv
-    = case (getOpt Permute options argv) of
-      (ol,n,[])
-        -> do
-           (xml, schema) <- src n
-           help (lookup a_help ol)
-           return (ol, xml, schema)
-      (_,_,errs)
-        -> usage errs
-    where
-    src [xml, schema] = return (xml, schema)
-    src []  = usage ["XML file and Relax NG schema input file/url missing"]
-    src [_] = usage ["Relax NG schema input file/url missing"]
-    src _   = usage ["too many arguments"]
-
-    help (Just _) = usage []
-    help Nothing = return ()
-
-
--- ------------------------------------------------------------
--- test environment
---
-{-
-xmlFile :: String
-xmlFile = "testCases/213/1.v.xml"
-
-schema :: [String]
-schema = ["testCases/213/c.rng"]
-
-testValidator :: Attributes -> String -> String -> IOSArrow b Int
-testValidator al src xmlFile
-    = readDocument al src
-      >>> propagateNamespaces
-      >>> simplificationStep1
-      >>> simplificationStep2 [] []
-      >>> simplificationStep3
-      >>> simplificationStep4
-      >>> simplificationStep5
-      >>> simplificationStep6
-      >>> simplificationStep7
-      >>> simplificationStep8
-      >>> cleanUp
-      >>> resetStates
---       >>> perform (getErrors >>> writeDocument [(a_show_tree, "1")] "-")
---       >>> perform (fromLA xmlTreeToPatternString >>> arrIO (\s -> hPutStrLn stdout (s ++ "\n\n")))
---       >>> perform (fromLA xmlTreeToPatternFormatedString >>> arrIO (\s -> hPutStrLn stdout (s ++ "\n\n")))
---       >>> perform (fromLA xmlTreeToPatternStringTree >>> arrIO (hPutStrLn stdout))
-      >>>
-      ( getErrors
-        `orElse`
-        (validateXMLDoc [] xmlFile)
-        `orElse`
-        (root [] [(constA $ mkXTextTree "valid")])
-      )
---       >>> writeDocument [(a_show_tree, "1")] "-"
---       >>> writeDocument [(a_show_haskell, "1")] "-"      
-      >>> getErrStatus
--}
diff --git a/examples/arrows/hrelaxng/Makefile b/examples/arrows/hrelaxng/Makefile
deleted file mode 100644
--- a/examples/arrows/hrelaxng/Makefile
+++ /dev/null
@@ -1,77 +0,0 @@
-# $Id: Makefile,v 1.2 2005/09/30 14:41:44 hxml Exp $
-
-HXT_HOME	= ../../..
-PKGFLAGS	= 
-GHCFLAGS	= -Wall -O2
-GHC		= ghc $(GHCFLAGS) $(PKGFLAGS)
-
-DIST		= $(HXT_HOME)/dist/examples/arrows
-DIST_DIR	= $(DIST)/hrelaxng
-
-prog		= ./HRelaxNG
-
-all		: $(prog)
-
-prof		:
-		ghc --make -o $(prog) -Wall -prof -auto-all -O -fglasgow-exts -ignore-package hxt -ignore-package HTTP -i../../../src $(prog).hs
-
-local		:
-		ghc --make -o $(prog) $(GHCFLAGS) -fglasgow-exts -ignore-package hxt -i../../../src $(prog).hs
-
-$(prog)		: $(prog).hs
-		$(GHC) --make -o $@ $<
-
-force		:
-		$(GHC) --make -o $(prog) $(prog).hs
-
-test		: $(prog)
-		@echo "===> Relax NG examples" ; echo ; sleep 1
-		@$(MAKE) example1 example1a example2 example3 example5
-
-example1	:
-		@echo "===> Validate a valid Relax NG schema with respect to a valid xml file" ; echo ; sleep 1
-		$(prog) ./valid1.xml ./valid1.rng
-		@echo
-
-example1a	:
-		@echo "a valid document"
-		$(prog) ./valid2.xml ./valid2.rng || true
-		@echo
-
-example1b	:
-		@echo "===> 1. invalid document\n"
-		$(prog) ./inv2.xml ./valid2.rng || true
-		@echo "\n===> 2. invalid document\n"
-		$(prog) ./inv3.xml ./valid2.rng || true
-		@echo
-
-example2	:
-		@echo "===> Validate a valid Relax NG schema with respect to a invalid xml file" ; echo ; sleep 1
-		$(prog) ./invalid1.xml ./valid1.rng || true
-		@echo
-
-example3	:
-		@echo "===> Incorrect Relax NG schema" ; echo ; sleep 1
-		$(prog) ./valid1.xml ./invalid2.rng || true
-		@echo
-
-example4	:
-		@echo "===> Same example with \"--output-pattern-transformations\" option " ; echo ; sleep 1
-		$(prog) --output-pattern-transformations  ./valid1.xml ./invalid2.rng || true
-		@echo
-
-example5	:
-		@echo "===> Incorrect Relax NG schema with two errors" ; echo ; sleep 1
-		$(prog) ./valid1.xml ./invalid3.rng || true
-		@echo
-
-EX		= $(wildcard *valid*.xml *valid*.rng)
-
-dist		:
-		[ -d $(DIST_DIR) ] || mkdir -p $(DIST_DIR)
-		cp $(EX) Makefile $(prog).hs $(DIST_DIR)
-
-clean		:
-		rm -f $(prog) *.o *.hi
-
-# eof ------------------------------------------------------------
diff --git a/examples/arrows/hrelaxng/invalid1.xml b/examples/arrows/hrelaxng/invalid1.xml
deleted file mode 100644
--- a/examples/arrows/hrelaxng/invalid1.xml
+++ /dev/null
@@ -1,1 +0,0 @@
-<bar/>
diff --git a/examples/arrows/hrelaxng/invalid2.rng b/examples/arrows/hrelaxng/invalid2.rng
deleted file mode 100644
--- a/examples/arrows/hrelaxng/invalid2.rng
+++ /dev/null
@@ -1,13 +0,0 @@
-<grammar xmlns:html="http://www.w3.org/TR/REC-html40" 
-         xmlns="http://relaxng.org/ns/structure/1.0" >
-  <start>
-    <element name="foo">
-      <zeroOrMore>
-        <group>
-          <attribute name="bar"/>
-          <attribute name="baz"/>
-        </group>
-      </zeroOrMore>
-    </element>
-  </start>
-</grammar>
diff --git a/examples/arrows/hrelaxng/invalid3.rng b/examples/arrows/hrelaxng/invalid3.rng
deleted file mode 100644
--- a/examples/arrows/hrelaxng/invalid3.rng
+++ /dev/null
@@ -1,19 +0,0 @@
-<grammar xmlns:html="http://www.w3.org/TR/REC-html40" 
-         xmlns="http://relaxng.org/ns/structure/1.0" >
-  <start>
-    <element name="foo">
-      <zeroOrMore>
-        <group>
-          <attribute name="bar"/>
-          <attribute name="baz"/>
-        </group>
-      </zeroOrMore>
-    </element>
-    <element name="bar">
-      <group>
-        <data type="token"/>
-        <data type="token"/>
-      </group>
-    </element>
-  </start>
-</grammar>
diff --git a/examples/arrows/hrelaxng/valid1.rng b/examples/arrows/hrelaxng/valid1.rng
deleted file mode 100644
--- a/examples/arrows/hrelaxng/valid1.rng
+++ /dev/null
@@ -1,7 +0,0 @@
-<grammar xmlns="http://relaxng.org/ns/structure/1.0">
-  <start>
-    <element name="foo">
-      <empty/>
-    </element>
-  </start>
-</grammar>
diff --git a/examples/arrows/hrelaxng/valid1.xml b/examples/arrows/hrelaxng/valid1.xml
deleted file mode 100644
--- a/examples/arrows/hrelaxng/valid1.xml
+++ /dev/null
@@ -1,1 +0,0 @@
-<foo/>
diff --git a/examples/arrows/hrelaxng/valid2.rng b/examples/arrows/hrelaxng/valid2.rng
deleted file mode 100644
--- a/examples/arrows/hrelaxng/valid2.rng
+++ /dev/null
@@ -1,27 +0,0 @@
-<grammar
-  xmlns="http://relaxng.org/ns/structure/1.0"
-  datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
-  <start>
-    <ref name="foo"/>
-  </start>
-  
-  <define name="foo">
-    <element name="foo">
-
-      <attribute name="string2-4">
-	<data type="string">
-	  <param name="minLength">2</param>
-	  <param name="maxLength">4</param>
-	</data>
-      </attribute>
-
-      <attribute name="id">
-	<data type="ID">
-	  <param name="length">4</param>
-	</data>
-      </attribute>
-      
-    </element>
-  </define>
-
-</grammar>
diff --git a/examples/arrows/hrelaxng/valid2.xml b/examples/arrows/hrelaxng/valid2.xml
deleted file mode 100644
--- a/examples/arrows/hrelaxng/valid2.xml
+++ /dev/null
@@ -1,1 +0,0 @@
-<foo string2-4="xxx" id="iooo"/>
diff --git a/examples/arrows/performance/GenDoc.hs b/examples/arrows/performance/GenDoc.hs
--- a/examples/arrows/performance/GenDoc.hs
+++ b/examples/arrows/performance/GenDoc.hs
@@ -5,9 +5,10 @@
 module Main
 where
 
-import Text.XML.HXT.Arrow
+import Text.XML.HXT.Core
+import Text.XML.HXT.TagSoup
 
-import Text.XML.HXT.DOM.Unicode
+import Data.String.Unicode
     ( unicodeToXmlEntity
     )
 
@@ -154,13 +155,13 @@
 
 readDoc	:: String -> IOSArrow b XmlTree
 readDoc src
-    = readDocument [ (a_tagsoup, v_1)
-		   , (a_parse_xml, v_1)
-		   , (a_remove_whitespace, v_1)
-		   , (a_encoding, isoLatin1)
-		   , (a_issue_warnings, v_0)
-		   , (a_trace, v_1)
-		   , (a_strict_input, v_0)
+    = readDocument [ withTagSoup
+		   , withParseHTML no
+		   , withRemoveWS yes
+		   , withInputEncoding isoLatin1
+		   , withWarnings no
+		   , withTrace 1
+		   , withStrictInput no
 		   ] src
       >>>
       processChildren (isElem `guards` this)
diff --git a/examples/arrows/pickle/PickleTest.hs b/examples/arrows/pickle/PickleTest.hs
--- a/examples/arrows/pickle/PickleTest.hs
+++ b/examples/arrows/pickle/PickleTest.hs
@@ -5,7 +5,7 @@
 import System.Exit
 import Test.HUnit
 
-import Text.XML.HXT.Arrow
+import Text.XML.HXT.Core
 
 -- ------------------------------------------------------------
 --
@@ -232,7 +232,7 @@
 		 >>>
 		 writeDocumentToString []			-- XmlTree => String
 		 >>>
-		 readFromString [(a_validate, v_0)]		-- String => XmlTree
+		 readFromString [ withValidate no ]		-- String => XmlTree
 		 >>>
 		 arrL (maybeToList . unpickleDoc xpProgram)	-- XmlTree => Program
 	       )
@@ -245,11 +245,11 @@
 		 >>>
 		 arr (pickleDoc xpProgram)			-- Program => XmlTree
 		 >>>
-		 writeDocument [ (a_indent, v_1)		-- XmlTree => formated external XML document
+		 writeDocument [ withIndent yes			-- XmlTree => formated external XML document
 			       ] "pickle.xml"
 		 >>>
-		 readDocument  [ (a_remove_whitespace, v_1)	-- formated external XML document => XmlTree
-			       , (a_validate, v_0)
+		 readDocument  [ withRemoveWS yes		-- formated external XML document => XmlTree
+			       , withValidate no
 			       ] "pickle.xml"
 		 >>>
 		 arrL (maybeToList . unpickleDoc xpProgram)	-- XmlTree => Program
@@ -263,12 +263,12 @@
 	       ( constA p					-- take the Program value
 		 >>>
 		 xpickleDocument   xpProgram
-                                 [ (a_indent, v_1)		-- Program => formated external XML document
+                                 [ withIndent yes		-- Program => formated external XML document
 				 ] "pickle.xml"
 		 >>>
 		 xunpickleDocument xpProgram
-                                   [ (a_remove_whitespace, v_1)	-- formated external XML document => Program
-				   , (a_validate, v_0)
+                                   [ withRemoveWS yes		-- formated external XML document => Program
+				   , withValidate no
 				   ] "pickle.xml"
 	       )
 	res7	:: IO [Program]					-- the most important case
@@ -279,13 +279,13 @@
 	       ( constA p					-- take the Program value
 		 >>>
 		 xpickleDocument   xpProgram
-                                 [ (a_indent, v_1)		-- Program => formated external XML document
-				 , (a_addDTD, v_1)
+                                 [ withIndent yes		-- Program => formated external XML document
+				 , withSysAttr a_addDTD v_1	-- with inline DTD
 				 ] "pickle.xml"
 		 >>>
 		 xunpickleDocument xpProgram
-                                   [ (a_remove_whitespace, v_1)	-- formated external XML document => Program
-				   , (a_validate, v_1)
+                                   [ withRemoveWS yes		-- formated external XML document => Program
+				   , withValidate yes
 				   ] "pickle.xml"
 	       )
 
diff --git a/hxt.cabal b/hxt.cabal
--- a/hxt.cabal
+++ b/hxt.cabal
@@ -1,7 +1,7 @@
 -- arch-tag: Haskell XML Toolbox main description file
 Name:           hxt
-Version:        8.5.4
-Synopsis:       A collection of tools for processing XML with Haskell. 
+Version:        9.0.0
+Synopsis:       A collection of tools for processing XML with Haskell.
 Description:    The Haskell XML Toolbox bases on the ideas of HaXml and HXML,
                 but introduces a more general approach for processing XML with Haskell.
                 The Haskell XML Toolbox uses a generic data model for representing XML documents,
@@ -10,8 +10,11 @@
                 an XPath expression evaluator, an XSLT library, a RelaxNG schema validator
                 and funtions for serialization and deserialization of user defined data.
                 The library makes extensive use of the arrow approach for processing XML.
-                Since version 8.5 XPath and XSLT have been moved to separate packages hxt-xpath and hxt-xslt,
-                serialisation is in package hxt-binary
+                Since version 9 the toolbox is partitioned into various (sub-)packages.
+                This package contains the core functionality,
+                hxt-curl, hxt-tagsoup, hxt-relaxng, hxt-xpath, hxt-xslt, hxt-regex-xmlschema contain the extensions.
+                hxt-unicode contains encoding and decoding functions,
+                hxt-charproperties char properties for unicode and XML.
 License:        OtherLicense
 License-file:   LICENSE
 Author:         Uwe Schmidt, Martin Schmidt, Torben Kuseler
@@ -56,25 +59,14 @@
  examples/arrows/hparser/namespace1.xml
  examples/arrows/hparser/valid1.rng
  examples/arrows/hparser/valid1.xml
- examples/arrows/hrelaxng/.ghci
- examples/arrows/hrelaxng/HRelaxNG.hs
- examples/arrows/hrelaxng/invalid1.xml
- examples/arrows/hrelaxng/invalid2.rng
- examples/arrows/hrelaxng/invalid3.rng
- examples/arrows/hrelaxng/Makefile
- examples/arrows/hrelaxng/valid1.rng
- examples/arrows/hrelaxng/valid1.xml
- examples/arrows/hrelaxng/valid2.rng
- examples/arrows/hrelaxng/valid2.xml
  examples/arrows/performance/GenDoc.hs
  examples/arrows/performance/Makefile
  examples/arrows/pickle/Makefile
  examples/arrows/pickle/PickleTest.hs
- examples/arrows/RegexXMLSchema/Makefile
- examples/arrows/RegexXMLSchema/REtest.hs
 
 library
  exposed-modules:
+  Control.Arrow.ArrowExc,
   Control.Arrow.ArrowIO,
   Control.Arrow.ArrowIf,
   Control.Arrow.ArrowList,
@@ -88,10 +80,10 @@
   Control.Arrow.StateListArrow,
   Data.AssocList,
   Data.Atom,
-  Data.Char.UTF8,
+  Data.Function.Selector,
   Data.Tree.Class,
   Data.Tree.NTree.TypeDefs,
-  Text.XML.HXT.Arrow,
+  Text.XML.HXT.Arrow.Binary,
   Text.XML.HXT.Arrow.DTDProcessing,
   Text.XML.HXT.Arrow.DocumentInput,
   Text.XML.HXT.Arrow.DocumentOutput,
@@ -107,22 +99,27 @@
   Text.XML.HXT.Arrow.ReadDocument,
   Text.XML.HXT.Arrow.WriteDocument,
   Text.XML.HXT.Arrow.XmlArrow,
-  Text.XML.HXT.Arrow.XmlIOStateArrow,
+  Text.XML.HXT.Arrow.XmlOptions,
   Text.XML.HXT.Arrow.XmlRegex,
+  Text.XML.HXT.Arrow.XmlState,
+  Text.XML.HXT.Arrow.XmlState.ErrorHandling,
+  Text.XML.HXT.Arrow.XmlState.MimeTypeTable,
+  Text.XML.HXT.Arrow.XmlState.RunIOStateArrow,
+  Text.XML.HXT.Arrow.XmlState.TraceHandling,
+  Text.XML.HXT.Arrow.XmlState.TypeDefs,
+  Text.XML.HXT.Arrow.XmlState.URIHandling,
+  Text.XML.HXT.Arrow.XmlState.SystemConfig,
+  Text.XML.HXT.Core,
   Text.XML.HXT.DOM.FormatXmlTree,
   Text.XML.HXT.DOM.Interface,
-  Text.XML.HXT.DOM.IsoLatinTables,
   Text.XML.HXT.DOM.MimeTypeDefaults,
   Text.XML.HXT.DOM.MimeTypes,
   Text.XML.HXT.DOM.QualifiedName,
   Text.XML.HXT.DOM.ShowXml,
   Text.XML.HXT.DOM.TypeDefs,
-  Text.XML.HXT.DOM.UTF8Decoding,
-  Text.XML.HXT.DOM.Unicode,
   Text.XML.HXT.DOM.Util,
   Text.XML.HXT.DOM.XmlKeywords,
   Text.XML.HXT.DOM.XmlNode,
-  Text.XML.HXT.DOM.XmlOptions,
   Text.XML.HXT.DTDValidation.AttributeValueValidation,
   Text.XML.HXT.DTDValidation.DTDValidation,
   Text.XML.HXT.DTDValidation.DocTransformation,
@@ -133,10 +130,8 @@
   Text.XML.HXT.DTDValidation.Validation,
   Text.XML.HXT.DTDValidation.XmlRE,
   Text.XML.HXT.IO.GetFILE,
-  Text.XML.HXT.IO.GetHTTPLibCurl,
   Text.XML.HXT.Parser.HtmlParsec,
   Text.XML.HXT.Parser.ProtocolHandlerUtil,
-  Text.XML.HXT.Parser.TagSoup,
   Text.XML.HXT.Parser.XhtmlEntities,
   Text.XML.HXT.Parser.XmlCharParser,
   Text.XML.HXT.Parser.XmlDTDParser,
@@ -144,27 +139,7 @@
   Text.XML.HXT.Parser.XmlEntities,
   Text.XML.HXT.Parser.XmlParsec,
   Text.XML.HXT.Parser.XmlTokenParser,
-  Text.XML.HXT.RelaxNG,
-  Text.XML.HXT.RelaxNG.BasicArrows,
-  Text.XML.HXT.RelaxNG.CreatePattern,
-  Text.XML.HXT.RelaxNG.DataTypeLibMysql,
-  Text.XML.HXT.RelaxNG.DataTypeLibUtils,
-  Text.XML.HXT.RelaxNG.DataTypeLibraries,
-  Text.XML.HXT.RelaxNG.DataTypes,
-  Text.XML.HXT.RelaxNG.PatternFunctions,
-  Text.XML.HXT.RelaxNG.PatternToString,
-  Text.XML.HXT.RelaxNG.Schema,
-  Text.XML.HXT.RelaxNG.SchemaGrammar,
-  Text.XML.HXT.RelaxNG.Simplification,
-  Text.XML.HXT.RelaxNG.Unicode.Blocks,
-  Text.XML.HXT.RelaxNG.Unicode.CharProps,
-  Text.XML.HXT.RelaxNG.Utils,
-  Text.XML.HXT.RelaxNG.Validation,
-  Text.XML.HXT.RelaxNG.Validator,
-  Text.XML.HXT.RelaxNG.XmlSchema.DataTypeLibW3C,
-  Text.XML.HXT.RelaxNG.XmlSchema.Regex,
-  Text.XML.HXT.RelaxNG.XmlSchema.RegexMatch,
-  Text.XML.HXT.RelaxNG.XmlSchema.RegexParser,
+  Text.XML.HXT.XMLSchema.DataTypeLibW3CNames,
   Text.XML.HXT.Version
 
  hs-source-dirs: src
@@ -183,5 +158,7 @@
                 network    >= 2.1 && < 3,
                 deepseq    >= 1.1 && < 2,
                 bytestring >= 0.9 && < 1,
-                tagsoup    >= 0.10 && < 0.11,
-                curl       >= 1.3 && < 2
+                binary     >= 0.5 && < 1,
+                hxt-charproperties  >= 9 && < 10,
+                hxt-unicode         >= 9 && < 10,
+                hxt-regex-xmlschema >= 9 && < 10
diff --git a/src/Control/Arrow/ArrowExc.hs b/src/Control/Arrow/ArrowExc.hs
new file mode 100644
--- /dev/null
+++ b/src/Control/Arrow/ArrowExc.hs
@@ -0,0 +1,38 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Control.Arrow.ArrowExc
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe\@fh-wedel.de)
+   Stability  : experimental
+   Portability: not portable
+
+   The exception arrow class
+
+-}
+
+-- ------------------------------------------------------------
+
+module Control.Arrow.ArrowExc
+    ( ArrowExc(..)
+    )
+where
+
+import           Control.Arrow
+import           Control.Arrow.ArrowIO
+
+import           Control.Exception      ( SomeException
+                                        )
+
+class (Arrow a, ArrowChoice a, ArrowZero a, ArrowIO a) => ArrowExc a where
+    tryA        :: a b c -> a b (Either SomeException c)
+
+    catchA      :: a b c -> a SomeException c -> a b c
+    catchA f h  = tryA f
+		  >>>
+		  ( h ||| returnA )
+
+
+-- ------------------------------------------------------------
diff --git a/src/Control/Arrow/ArrowIO.hs b/src/Control/Arrow/ArrowIO.hs
--- a/src/Control/Arrow/ArrowIO.hs
+++ b/src/Control/Arrow/ArrowIO.hs
@@ -8,9 +8,8 @@
    Maintainer : Uwe Schmidt (uwe\@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id: ArrowIO.hs,v 1.6 2005/09/02 17:09:39 hxml Exp $
 
-Lifting of IO actions to arrows
+  Lifting of IO actions to arrows
 
 -}
 
diff --git a/src/Control/Arrow/ArrowIf.hs b/src/Control/Arrow/ArrowIf.hs
--- a/src/Control/Arrow/ArrowIf.hs
+++ b/src/Control/Arrow/ArrowIf.hs
@@ -8,14 +8,12 @@
    Maintainer : Uwe Schmidt (uwe\@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id: ArrowIf.hs,v 1.8 2006/05/04 14:17:53 hxml Exp $
 
-Conditionals for List Arrows
-
-This module defines conditional combinators for list arrows.
+   Conditionals for List Arrows
 
-The empty list as result represents False, none empty lists True.
+   This module defines conditional combinators for list arrows.
 
+   The empty list as result represents False, none empty lists True.
 -}
 
 -- ------------------------------------------------------------
diff --git a/src/Control/Arrow/ArrowList.hs b/src/Control/Arrow/ArrowList.hs
--- a/src/Control/Arrow/ArrowList.hs
+++ b/src/Control/Arrow/ArrowList.hs
@@ -8,17 +8,16 @@
    Maintainer : Uwe Schmidt (uwe\@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id: ArrowList.hs,v 1.11 2006/06/01 12:59:04 hxml Exp $
 
-The List Arrow Class
+   The list arrow class
 
-This module defines the interface for list arrows.
+   This module defines the interface for list arrows.
 
-A list arrow is a function, that gives a list of results
-for a given argument. A single element result represents a normal function.
-An empty list oven indicates, the function is undefined for the given argument.
-The empty list may also represent False, none empty lists True.
-A list with more than one element gives all results for a nondeterministic function.
+   A list arrow is a function, that gives a list of results
+   for a given argument. A single element result represents a normal function.
+   An empty list oven indicates, the function is undefined for the given argument.
+   The empty list may also represent False, none empty lists True.
+   A list with more than one element gives all results for a nondeterministic function.
 
 -}
 
diff --git a/src/Control/Arrow/ArrowState.hs b/src/Control/Arrow/ArrowState.hs
--- a/src/Control/Arrow/ArrowState.hs
+++ b/src/Control/Arrow/ArrowState.hs
@@ -9,7 +9,7 @@
 
    Maintainer : Uwe Schmidt (uwe\@fh-wedel.de)
    Stability  : experimental
-   Portability: multy parameter classes and functional depenedencies required
+   Portability: multi parameter classes and functional depenedencies required
 
    Arrows for managing an explicit state
 
diff --git a/src/Control/Arrow/ArrowTree.hs b/src/Control/Arrow/ArrowTree.hs
--- a/src/Control/Arrow/ArrowTree.hs
+++ b/src/Control/Arrow/ArrowTree.hs
@@ -2,19 +2,17 @@
 
 {- |
    Module     : Control.Arrow.ArrowTree
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
    License    : MIT
 
    Maintainer : Uwe Schmidt (uwe\@fh-wedel.de)
-   Stability  : experimental
+   Stability  : stable
    Portability: portable
-   Version    : $Id: ArrowTree.hs,v 1.12 2006/11/30 16:05:24 hxml Exp $
 
-List arrows for tree processing.
-
-Trees that implement the "Data.Tree.Class" interface, can be processed
-with these arrows.
+   List arrows for tree processing.
 
+   Trees that implement the "Data.Tree.Class" interface, can be processed
+   with these arrows.
 -}
 
 -- ------------------------------------------------------------
@@ -181,7 +179,7 @@
     -- The search is performed top down. All nodes of the tree are searched, even within the
     -- subtrees of trees for which the predicate holds.
     --
-    -- example: @ multy isHtmlTable @ selects all table elements, even nested ones.
+    -- example: @ multi isHtmlTable @ selects all table elements, even nested ones.
 
     multi               :: Tree t => a (t b) c -> a (t b) c
     multi f             = f                                     -- combine result for root
diff --git a/src/Control/Arrow/IOListArrow.hs b/src/Control/Arrow/IOListArrow.hs
--- a/src/Control/Arrow/IOListArrow.hs
+++ b/src/Control/Arrow/IOListArrow.hs
@@ -23,14 +23,18 @@
 
 import Control.Category
 
-import           Control.Arrow
-import           Control.Arrow.ArrowIf
-import           Control.Arrow.ArrowList
-import           Control.Arrow.ArrowNF
-import           Control.Arrow.ArrowTree
-import           Control.Arrow.ArrowIO
+import Control.Arrow
+import Control.Arrow.ArrowExc
+import Control.Arrow.ArrowIf
+import Control.Arrow.ArrowIO
+import Control.Arrow.ArrowList
+import Control.Arrow.ArrowNF
+import Control.Arrow.ArrowTree
 
-import           Control.DeepSeq
+import Control.DeepSeq
+import Control.Exception      		( SomeException
+					, try
+					)
 
 -- ------------------------------------------------------------
 
@@ -116,6 +120,16 @@
     arrIO cmd           = IOLA $ \x -> do
                                        res <- cmd x
                                        return [res]
+
+instance ArrowExc IOLA where
+    tryA f      = IOLA $ \ x -> do
+				res <- try' $ runIOLA f x
+				return $ case res of
+				  Left  er -> [Left er]
+				  Right ys -> [Right x' | x' <- ys]
+	where
+	try'    :: IO a -> IO (Either SomeException a)
+	try'    = try
 
 instance ArrowIOIf IOLA where
     isIOA p             = IOLA $ \x -> do
diff --git a/src/Control/Arrow/IOStateListArrow.hs b/src/Control/Arrow/IOStateListArrow.hs
--- a/src/Control/Arrow/IOStateListArrow.hs
+++ b/src/Control/Arrow/IOStateListArrow.hs
@@ -24,19 +24,23 @@
     )
 where
 
-import           Prelude hiding (id, (.))
+import Prelude hiding (id, (.))
 
-import           Control.Category
+import Control.Category
 
-import           Control.Arrow
-import           Control.Arrow.ArrowIf
-import           Control.Arrow.ArrowIO
-import           Control.Arrow.ArrowList
-import           Control.Arrow.ArrowNF
-import           Control.Arrow.ArrowTree
-import           Control.Arrow.ArrowState
+import Control.Arrow
+import Control.Arrow.ArrowExc
+import Control.Arrow.ArrowIf
+import Control.Arrow.ArrowIO
+import Control.Arrow.ArrowList
+import Control.Arrow.ArrowNF
+import Control.Arrow.ArrowTree
+import Control.Arrow.ArrowState
 
-import           Control.DeepSeq
+import Control.DeepSeq
+import Control.Exception                ( SomeException
+                                        , try
+                                        )
 
 -- ------------------------------------------------------------
 
@@ -144,6 +148,16 @@
     arrIO cmd           = IOSLA $ \ s x -> do
                                            res <- cmd x
                                            return (s, [res])
+
+instance ArrowExc (IOSLA s) where
+    tryA f              = IOSLA $ \ s x -> do
+                                           res <- try' $ runIOSLA f s x
+                                           return $ case res of
+                                              Left   er      -> (s,  [Left er])
+                                              Right (s1, ys) -> (s1, [Right x' | x' <- ys])
+        where
+        try'            :: IO a -> IO (Either SomeException a)
+        try'            = try
 
 instance ArrowIOIf (IOSLA s) where
     isIOA p             = IOSLA $ \ s x -> do
diff --git a/src/Control/Arrow/ListArrows.hs b/src/Control/Arrow/ListArrows.hs
--- a/src/Control/Arrow/ListArrows.hs
+++ b/src/Control/Arrow/ListArrows.hs
@@ -17,12 +17,13 @@
 
 module Control.Arrow.ListArrows
     ( module Control.Arrow                      -- arrow classes
-    , module Control.Arrow.ArrowList
+    , module Control.Arrow.ArrowExc
     , module Control.Arrow.ArrowIf
+    , module Control.Arrow.ArrowIO
+    , module Control.Arrow.ArrowList
     , module Control.Arrow.ArrowNF
     , module Control.Arrow.ArrowState
     , module Control.Arrow.ArrowTree
-    , module Control.Arrow.ArrowIO
 
     , module Control.Arrow.ListArrow            -- arrow types
     , module Control.Arrow.StateListArrow
@@ -32,6 +33,7 @@
 where
 
 import Control.Arrow                            -- arrow classes
+import Control.Arrow.ArrowExc
 import Control.Arrow.ArrowList
 import Control.Arrow.ArrowIf
 import Control.Arrow.ArrowNF
diff --git a/src/Data/AssocList.hs b/src/Data/AssocList.hs
--- a/src/Data/AssocList.hs
+++ b/src/Data/AssocList.hs
@@ -1,8 +1,20 @@
--- |
--- simple key value assocciation list
--- implemented as unordered list of pairs
---
--- Version : $Id: AssocList.hs,v 1.2 2005/05/27 13:15:23 hxml Exp $
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Data.AssocList
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   Simple key value assocciation list
+   implemented as unordered list of pairs
+
+-}
+
+-- ------------------------------------------------------------
 
 module Data.AssocList
     ( module Data.AssocList
diff --git a/src/Data/Atom.hs b/src/Data/Atom.hs
--- a/src/Data/Atom.hs
+++ b/src/Data/Atom.hs
@@ -65,12 +65,11 @@
 import           Data.ByteString.Internal       ( toForeignPtr, c2w, w2c )
 import           Data.ByteString                ( ByteString, pack, unpack )
 import qualified Data.Map                       as M
+import           Data.String.UTF8Decoding       ( decodeUtf8 )
+import           Data.String.Unicode            ( unicodeToUtf8 )
 import           Data.Typeable
 
 import           System.IO.Unsafe               ( unsafePerformIO )
-
-import           Text.XML.HXT.DOM.Unicode       ( unicodeToUtf8 )
-import           Text.XML.HXT.DOM.UTF8Decoding  ( decodeUtf8 )
 
 -- ------------------------------------------------------------
 
diff --git a/src/Data/Char/UTF8.hs b/src/Data/Char/UTF8.hs
deleted file mode 100644
--- a/src/Data/Char/UTF8.hs
+++ /dev/null
@@ -1,363 +0,0 @@
-{-
-
-Copyright (c) 2002, members of the Haskell Internationalisation Working
-Group All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-* Redistributions of source code must retain the above copyright notice,
-   this list of conditions and the following disclaimer.
-* Redistributions in binary form must reproduce the above copyright notice,
-   this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-* Neither the name of the Haskell Internationalisation Working Group nor
-   the names of its contributors may be used to endorse or promote products
-   derived from this software without specific prior written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
-
-This module provides lazy stream encoding/decoding facilities for UTF-8,
-the Unicode Transformation Format with 8-bit words.
-
-2002-09-02  Sven Moritz Hallberg <pesco@gmx.de>
-
--}
-
-{-
-
-2007-04-30 Henning Thielemann:
-Slight changes to make decode lazy.
-The calls of 'reverse' in the original version have broken laziness
-and thus had memory leaks.
-
--}
-
-module Data.Char.UTF8
-  ( encode, decode,
-    decodeEmbedErrors,
-    encodeOne, decodeOne,
-    Error, -- Haddock does not want to document signatures with private types
-    -- these functions should be moved to a utility module
-  ) where
-
-import Data.Char (ord, chr)
-import Data.Word (Word8, Word16, Word32)
-import Data.Bits (Bits, shiftL, shiftR, (.&.), (.|.))
-
-import Data.List (unfoldr)
-
-import Text.XML.HXT.DOM.Util (partitionEither, swap, toMaybe)
-
-
-
--- - UTF-8 in General -
-
--- Adapted from the Unicode standard, version 3.2,
--- Table 3.1 "UTF-8 Bit Distribution" (excluded are UTF-16 encodings):
-
---   Scalar                    1st Byte  2nd Byte  3rd Byte  4th Byte
---           000000000xxxxxxx  0xxxxxxx
---           00000yyyyyxxxxxx  110yyyyy  10xxxxxx
---           zzzzyyyyyyxxxxxx  1110zzzz  10yyyyyy  10xxxxxx
---   000uuuzzzzzzyyyyyyxxxxxx  11110uuu  10zzzzzz  10yyyyyy  10xxxxxx
-
--- Also from the Unicode standard, version 3.2,
--- Table 3.1B "Legal UTF-8 Byte Sequences":
-
---   Code Points         1st Byte  2nd Byte  3rd Byte  4th Byte
---     U+0000..U+007F    00..7F
---     U+0080..U+07FF    C2..DF    80..BF
---     U+0800..U+0FFF    E0        A0..BF    80..BF
---     U+1000..U+CFFF    E1..EC    80..BF    80..BF
---     U+D000..U+D7FF    ED        80..9F    80..BF
---     U+D800..U+DFFF    ill-formed
---     U+E000..U+FFFF    EE..EF    80..BF    80..BF
---    U+10000..U+3FFFF   F0        90..BF    80..BF    80..BF
---    U+40000..U+FFFFF   F1..F3    80..BF    80..BF    80..BF
---   U+100000..U+10FFFF  F4        80..8F    80..BF    80..BF
-
-
-
--- - Encoding Functions -
-
--- Must the encoder ensure that no illegal byte sequences are output or
--- can we trust the Haskell system to supply only legal values?
--- For now I include error case for the surrogate values U+D800..U+DFFF and
--- out-of-range scalars.
-
--- The function is pretty much a transscript of table 3.1B with error checks.
--- It dispatches the actual encoding to functions specific to the number of
--- required bytes.
-
-encodeOne :: Char -> [Word8]
-encodeOne c
-    -- The report guarantees in (6.1.2) that this won't happen:
-    --   | n < 0       = error "encodeUTF8: ord returned a negative value"
-    | n < 0x0080  = encodeOne_onebyte n8
-    | n < 0x0800  = encodeOne_twobyte n16
-    | n < 0xD800  = encodeOne_threebyte n16
-    | n < 0xE000  = error "encodeUTF8: ord returned a surrogate value"
-    | n < 0x10000       = encodeOne_threebyte n16
-    -- Haskell 98 only talks about 16 bit characters, but ghc handles 20.1.
-    | n < 0x10FFFF      = encodeOne_fourbyte n32
-    | otherwise  = error "encodeUTF8: ord returned a value above 0x10FFFF"
-    where
-    n = ord c            :: Int
-    n8 = fromIntegral n  :: Word8
-    n16 = fromIntegral n :: Word16
-    n32 = fromIntegral n :: Word32
-
-
--- With the above, a stream decoder is trivial:
-
-encode :: [Char] -> [Word8]
-encode = concatMap encodeOne
-
-
--- Now follow the individual encoders for certain numbers of bytes...
---           _
---          / |  __  ___  __ __
---         / ^| //  /__/ // //
---        /.==| \\ //_  // //
--- It's  //  || // \_/_//_//_  and it's here to stay!
-
-encodeOne_onebyte :: Word8 -> [Word8]
-encodeOne_onebyte cp = [cp]
-
-
--- 00000yyyyyxxxxxx -> 110yyyyy 10xxxxxx
-
-encodeOne_twobyte :: Word16 -> [Word8]
-encodeOne_twobyte cp = [(0xC0.|.ys), (0x80.|.xs)]
-    where
-    xs, ys :: Word8
-    ys = fromIntegral (shiftR cp 6)
-    xs = (fromIntegral cp) .&. 0x3F
-
-
--- zzzzyyyyyyxxxxxx -> 1110zzzz 10yyyyyy 10xxxxxx
-
-encodeOne_threebyte :: Word16 -> [Word8]
-encodeOne_threebyte cp = [(0xE0.|.zs), (0x80.|.ys), (0x80.|.xs)]
-    where
-    xs, ys, zs :: Word8
-    xs = (fromIntegral cp) .&. 0x3F
-    ys = (fromIntegral (shiftR cp 6)) .&. 0x3F
-    zs = fromIntegral (shiftR cp 12)
-
-
--- 000uuuzzzzzzyyyyyyxxxxxx -> 11110uuu 10zzzzzz 10yyyyyy 10xxxxxx
-
-encodeOne_fourbyte :: Word32 -> [Word8]
-encodeOne_fourbyte cp = [0xF0.|.us, 0x80.|.zs, 0x80.|.ys, 0x80.|.xs]
-    where
-    xs, ys, zs, us :: Word8
-    xs = (fromIntegral cp) .&. 0x3F
-    ys = (fromIntegral (shiftR cp 6)) .&. 0x3F
-    zs = (fromIntegral (shiftR cp 12)) .&. 0x3F
-    us = fromIntegral (shiftR cp 18)
-
-
-
--- - Decoding -
-
--- The decoding is a bit more involved. The byte sequence could contain all
--- sorts of corruptions. The user must be able to either notice or ignore these
--- errors.
-
--- I will first look at the decoding of a single character. The process
--- consumes a certain number of bytes from the input. It returns the
--- remaining input and either an error and the index of its occurance in the
--- byte sequence or the decoded character.
-
-data Error
-
--- The first byte in a sequence starts with either zero, two, three, or four
--- ones and one zero to indicate the length of the sequence. If it doesn't,
--- it is invalid. It is dropped and the next byte interpreted as the start
--- of a new sequence.
-
-    = InvalidFirstByte
-
--- All bytes in the sequence except the first match the bit pattern 10xxxxxx.
--- If one doesn't, it is invalid. The sequence up to that point is dropped
--- and the "invalid" byte interpreted as the start of a new sequence. The error
--- includes the length of the partial sequence and the number of expected bytes.
-
-    | InvalidLaterByte Int      -- the byte at relative index n was invalid
-
--- If a sequence ends prematurely, it has been truncated. It dropped and
--- decoding stops. The error reports the actual and expected lengths of the
--- sequence.
-
-    | Truncated Int Int         -- only n of m expected bytes were present
-
--- Some sequences would represent code points which would be encoded as a
--- shorter sequence by a conformant encoder. Such non-shortest sequences are
--- considered erroneous and dropped. The error reports the actual and
--- expected number of bytes used.
-
-    | NonShortest Int Int       -- n instead of m bytes were used
-
--- Unicode code points are in the range of [0..0x10FFFF]. Any values outside
--- of those bounds are simply invalid.
-
-    | ValueOutOfBounds
-
--- There is no such thing as "surrogate pairs" any more in UTF-8. The
--- corresponding code points now form illegal byte sequences.
-
-    | Surrogate
-      deriving (Show, Eq)
-
-
--- Second, third, and fourth bytes share the common requirement to start
--- with the bit sequence 10. So, here's the function to check that property.
-
-first_bits_not_10 :: Word8 -> Bool
-first_bits_not_10 b
-    | (b.&.0xC0) /= 0x80  = True
-    | otherwise           = False
-
-
--- Erm, OK, the single-character decoding function's return type is a bit
--- longish. It is a tripel:
-
---  - The first component contains the decoded character or an error
---    if the byte sequence was erroneous.
---  - The second component contains the number of bytes that were consumed
---    from the input.
---  - The third component contains the remaining bytes of input.
-
-decodeOne :: [Word8] -> (Either Error Char, Int, [Word8])
-decodeOne bs@(b1:rest)
-    | b1 < 0x80   = decodeOne_onebyte bs
-    | b1 < 0xC0   = (Left InvalidFirstByte, 1, rest)
-    | b1 < 0xE0   = decodeOne_twobyte bs
-    | b1 < 0xF0   = decodeOne_threebyte bs
-    | b1 < 0xF5   = decodeOne_fourbyte bs
-    | otherwise   = (Left ValueOutOfBounds, 1, rest)
-decodeOne [] = error "UTF8.decodeOne: No input"
-
-
--- 0xxxxxxx -> 000000000xxxxxxx
-
-decodeOne_onebyte :: [Word8] -> (Either Error Char, Int, [Word8])
-decodeOne_onebyte (b:bs) = (Right (cpToChar b), 1, bs)
-decodeOne_onebyte[] = error "UTF8.decodeOne_onebyte: No input (can't happen)"
-
-cpToChar :: Integral a => a -> Char
-cpToChar = chr . fromIntegral
-
-
--- 110yyyyy 10xxxxxx -> 00000yyyyyxxxxxx
-
-decodeOne_twobyte :: [Word8] -> (Either Error Char, Int, [Word8])
-decodeOne_twobyte (_:[])
-    = (Left (Truncated 1 2), 1, [])
-decodeOne_twobyte (b1:b2:bs)
-    | b1 < 0xC2            = (Left (NonShortest 2 1), 2, bs)
-    | first_bits_not_10 b2 = (Left (InvalidLaterByte 1), 1, (b2:bs))
-    | otherwise            = (Right (cpToChar result), 2, bs)
-    where
-    xs, ys, result :: Word32
-    xs = fromIntegral (b2.&.0x3F)
-    ys = fromIntegral (b1.&.0x1F)
-    result = shiftL ys 6 .|. xs
-decodeOne_twobyte[] = error "UTF8.decodeOne_twobyte: No input (can't happen)"
-
-
--- 1110zzzz 10yyyyyy 10xxxxxx -> zzzzyyyyyyxxxxxx
-
-decodeOne_threebyte :: [Word8] -> (Either Error Char, Int, [Word8])
-decodeOne_threebyte (_:[])   = threebyte_truncated 1
-decodeOne_threebyte (_:_:[]) = threebyte_truncated 2
-decodeOne_threebyte bs@(b1:b2:b3:rest)
-    | first_bits_not_10 b2
-        = (Left (InvalidLaterByte 1), 1, drop 1 bs)
-    | first_bits_not_10 b3
-        = (Left (InvalidLaterByte 2), 2, drop 2 bs)
-    | result < 0x0080
-        = (Left (NonShortest 3 1), 3, rest)
-    | result < 0x0800
-        = (Left (NonShortest 3 2), 3, rest)
-    | result >= 0xD800 && result < 0xE000
-        = (Left Surrogate, 3, rest)
-    | otherwise
-        = (Right (cpToChar result), 3, rest)
-    where
-    xs, ys, zs, result :: Word32
-    xs = fromIntegral (b3.&.0x3F)
-    ys = fromIntegral (b2.&.0x3F)
-    zs = fromIntegral (b1.&.0x0F)
-    result = shiftL zs 12 .|. shiftL ys 6 .|. xs
-decodeOne_threebyte[]
- = error "UTF8.decodeOne_threebyte: No input (can't happen)"
-
-threebyte_truncated :: Int -> (Either Error Char, Int, [Word8])
-threebyte_truncated n = (Left (Truncated n 3), n, [])
-
-
--- 11110uuu 10zzzzzz 10yyyyyy 10xxxxxx -> 000uuuzzzzzzyyyyyyxxxxxx
-
-decodeOne_fourbyte :: [Word8] -> (Either Error Char, Int, [Word8])
-decodeOne_fourbyte (_:[])     = fourbyte_truncated 1
-decodeOne_fourbyte (_:_:[])   = fourbyte_truncated 2
-decodeOne_fourbyte (_:_:_:[]) = fourbyte_truncated 3
-decodeOne_fourbyte bs@(b1:b2:b3:b4:rest)
-    | first_bits_not_10 b2
-        = (Left (InvalidLaterByte 1), 1, drop 1 bs)
-    | first_bits_not_10 b3
-        = (Left (InvalidLaterByte 2), 2, drop 2 bs)
-    | first_bits_not_10 b4
-        = (Left (InvalidLaterByte 3), 3, drop 3 bs)
-    | result < 0x0080
-        = (Left (NonShortest 4 1), 4, rest)
-    | result < 0x0800
-        = (Left (NonShortest 4 2), 4, rest)
-    | result < 0x10000
-        = (Left (NonShortest 4 3), 4, rest)
-    | result > 0x10FFFF
-        = (Left ValueOutOfBounds, 4, rest)
-    | otherwise
-        = (Right (cpToChar result), 4, rest)
-    where
-    xs, ys, zs, us, result :: Word32
-    xs = fromIntegral (b4 .&. 0x3F)
-    ys = fromIntegral (b3 .&. 0x3F)
-    zs = fromIntegral (b2 .&. 0x3F)
-    us = fromIntegral (b1 .&. 0x07)
-    result = xs .|. shiftL ys 6 .|. shiftL zs 12 .|. shiftL us 18
-decodeOne_fourbyte[]
- = error "UTF8.decodeOne_fourbyte: No input (can't happen)"
-
-fourbyte_truncated :: Int -> (Either Error Char, Int, [Word8])
-fourbyte_truncated n = (Left (Truncated n 4), n, [])
-
-
--- The decoder examines all input, recording decoded characters as well as
--- error-index pairs along the way.
-
-decode :: [Word8] -> ([Char], [(Error,Int)])
-decode = swap . partitionEither . decodeEmbedErrors
-
-decodeEmbedErrors :: [Word8] -> [Either (Error,Int) Char]
-decodeEmbedErrors =
-   unfoldr (\(pos,xs) ->
-       toMaybe
-          (not $ null xs)
-          (let (c,n,rest) = decodeOne xs
-           in  (either (\err -> Left (err,pos)) Right c,
-                (pos+n,rest)))) .
-   (,) 0
diff --git a/src/Data/Function/Selector.hs b/src/Data/Function/Selector.hs
new file mode 100644
--- /dev/null
+++ b/src/Data/Function/Selector.hs
@@ -0,0 +1,139 @@
+{-# OPTIONS -XMultiParamTypeClasses -XFunctionalDependencies  -XFlexibleInstances #-}
+
+module Data.Function.Selector
+where
+
+import Prelude 		hiding (id,(.))
+
+import Control.Arrow
+import Control.Category
+
+infixr 3 .&&&.
+
+-- ------------------------------------------------------------
+
+-- | A Selector is a pair of an access function and a modifying function
+-- for reading and updating parts of a composite type
+
+data Selector s a       = S { getS :: s -> a
+			    , setS :: a -> s -> s
+			    }
+
+chgS			:: Selector s a -> (a -> a) -> (s -> s)
+chgS sel f s		= setS sel x s
+			  where
+			  x = f . getS sel $ s
+
+chgM			:: (Monad m) => Selector s a -> (a -> m a) -> (s -> m s)
+chgM sel f s		= do
+			  y <- f x
+			  return $ setS sel y s
+			  where
+			  x = getS sel $ s
+
+-- | Alias for constructor S
+
+mkSelector		:: (s -> a) -> (a -> s -> s) -> Selector s a
+mkSelector		= S
+
+-- (.), (>>>), (<<<)
+
+instance Category Selector where
+    id				= S { getS = id
+				    , setS = const
+				    }
+    (S g2 s2) . (S g1 s1)	= S { getS = g2 . g1
+				    , setS = \ x s ->
+				            let x1  = g1 s    in
+				            let x1' = s2 x x1 in
+				            s1 x1' s
+				    }
+
+idS                     	:: Selector s s
+idS                     	= id
+
+(.&&&.)		                :: Selector s a -> Selector s b -> Selector s (a, b)
+(.&&&.) (S g1 s1) (S g2 s2)	= S { getS = g1 &&& g2
+                                    , setS = \ (x, y) -> s2 y . s1 x
+                                    }
+
+-- ------------------------------------------------------------
+-- TODO: delete theses
+{-
+subS                    :: Selector b c -> Selector a b -> Selector a c
+subS = (.)
+
+pairS                   :: Selector s a -> Selector s b -> Selector s (a, b)
+pairS = (.&&&.)
+
+chgS                    :: Selector s a -> (a -> a) -> (s -> s)
+chgS = update
+
+putS                    :: Selector s a -> a -> (s -> s)
+putS = setS
+
+-}
+-- ------------------------------------------------------------
+{-
+type Selector s a       = (s -> a, a -> s -> s)
+
+subS                    :: Selector b c -> Selector a b -> Selector a c
+subS (g2, s2) (g1, s1)  = ( g2 . g1
+                          , s1s2
+                          )
+                          where
+                          s1s2 x s = s'
+                              where
+                              x1  = g1 s
+                              x1' = s2 x x1
+                              s'  = s1 x1' s
+
+pairS                   :: Selector s a -> Selector s b -> Selector s (a, b)
+pairS (g1, s1) (g2, s2) = ( g1 &&& g2
+                          , \ (x, y) -> s2 y . s1 x
+                          )
+
+chgS                    :: Selector s a -> (a -> a) -> (s -> s)
+chgS (g, s) f x         = s (f (g x)) x
+
+getS                    :: Selector s a -> s -> a
+getS                    = fst                           -- getS (g, _s) x = g x
+
+putS                    :: Selector s a -> a -> (s -> s)
+putS s v                = chgS s (const v)
+
+idS                     :: Selector s s
+idS                     = (id, const)
+-}
+-- ------------------------------------------------------------
+
+-- | Selectors for pairs and 3-tuples: comp1, comp2, comp3,
+-- this can be extended to n-tuples
+
+class Comp1 s a | s -> a where  comp1	:: Selector s a
+class Comp2 s a | s -> a where  comp2	:: Selector s a
+class Comp3 s a | s -> a where  comp3	:: Selector s a
+
+
+instance Comp1 (a, b) a where		comp1	= S { getS = fst
+						    , setS = \ x1 (_, x2) -> (x1, x2)
+						    }
+
+instance Comp2 (a, b) b where		comp2	= S { getS = snd
+						    , setS = \ x2 (x1, _) -> (x1, x2)
+						    }
+
+instance Comp1 (a, b, c) a where	comp1	= S { getS = \ (x1, _, _) -> x1
+						    , setS = \ x1 (_, x2, x3) -> (x1, x2, x3)
+						    }
+
+instance Comp2 (a, b, c) b where	comp2	= S { getS = \ (_, x2, _) -> x2
+						    , setS = \ x2 (x1, _, x3) -> (x1, x2, x3)
+						    }
+
+instance Comp3 (a, b, c) c where	comp3	= S { getS = \ (_, _, x3) -> x3
+						    , setS = \ x3 (x1, x2, _) -> (x1, x2, x3)
+						    }
+
+-- ------------------------------------------------------------
+
diff --git a/src/Data/Tree/NTree/TypeDefs.hs b/src/Data/Tree/NTree/TypeDefs.hs
--- a/src/Data/Tree/NTree/TypeDefs.hs
+++ b/src/Data/Tree/NTree/TypeDefs.hs
@@ -27,6 +27,7 @@
 
 import Control.DeepSeq
 
+import Data.Binary
 import Data.Tree.Class
 import Data.Typeable
 
@@ -50,6 +51,13 @@
 
 instance (NFData a) => NFData (NTree a) where
     rnf (NTree n cl)                    = rnf n `seq` rnf cl
+
+instance (Binary a) => Binary (NTree a) where
+    put (NTree n cs)    = put n >> put cs
+    get                 = do
+                          n  <- get
+                          cs <- get
+                          return (NTree n cs)
 
 -- | NTree implements class Functor
 
diff --git a/src/Text/XML/HXT/Arrow.hs b/src/Text/XML/HXT/Arrow.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/Arrow.hs
+++ /dev/null
@@ -1,64 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.Arrow
-   Copyright  : Copyright (C) 2006-2010 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : stable
-   Portability: portable
-
-   The HXT arrow interface
-
-   The application programming interface to the arrow modules of the Haskell XML Toolbox.
-   This module exports all important arrows for input, output, parsing, validating and transforming XML.
-   It also exports all basic datatypes and functions of the toolbox.
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.Arrow
-    ( module Control.Arrow.ListArrows
-
-    , module Text.XML.HXT.DOM.Interface
-
-    , module Text.XML.HXT.Arrow.XmlArrow
-    , module Text.XML.HXT.Arrow.XmlIOStateArrow
-
-    , module Text.XML.HXT.Arrow.DocumentInput
-    , module Text.XML.HXT.Arrow.DocumentOutput
-    , module Text.XML.HXT.Arrow.Edit
-    , module Text.XML.HXT.Arrow.GeneralEntitySubstitution
-    , module Text.XML.HXT.Arrow.Namespace
-    , module Text.XML.HXT.Arrow.ProcessDocument
-    , module Text.XML.HXT.Arrow.ReadDocument
-    , module Text.XML.HXT.Arrow.WriteDocument
-    , module Text.XML.HXT.Arrow.Pickle
-
-    , module Text.XML.HXT.Version
-    )
-where
-
-import Control.Arrow.ListArrows                 -- arrow classes
-
-import Data.Atom ()                             -- import this explicitly
-
-import Text.XML.HXT.DOM.Interface
-import Text.XML.HXT.Arrow.DocumentInput
-import Text.XML.HXT.Arrow.DocumentOutput
-import Text.XML.HXT.Arrow.Edit
-import Text.XML.HXT.Arrow.GeneralEntitySubstitution
-import Text.XML.HXT.Arrow.Namespace
-import Text.XML.HXT.Arrow.Pickle
-import Text.XML.HXT.Arrow.ProcessDocument
-import Text.XML.HXT.Arrow.ReadDocument
-import Text.XML.HXT.Arrow.WriteDocument
-import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
-import Text.XML.HXT.Arrow.XmlRegex ()           -- import this explicitly
-
-import Text.XML.HXT.Version
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/Binary.hs b/src/Text/XML/HXT/Arrow/Binary.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/Binary.hs
@@ -0,0 +1,69 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.Binary
+   Copyright  : Copyright (C) 2008 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : experimental
+   Portability: portable
+
+   De-/Serialisation arrows for XmlTrees and other arbitrary values with a Binary instance
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.Binary
+    ( readBinaryValue
+    , writeBinaryValue
+    )
+where
+
+import           Control.Arrow          ()
+import           Control.Arrow.ArrowExc
+import           Control.Arrow.ArrowList
+import           Control.Arrow.ArrowIO
+
+import           Control.DeepSeq
+
+import           Data.Binary
+import qualified Data.ByteString.Lazy   as B
+
+import           Text.XML.HXT.Arrow.XmlState.ErrorHandling
+import           Text.XML.HXT.Arrow.XmlState.TypeDefs
+
+-- ------------------------------------------------------------
+
+readBinaryValue         :: (NFData a, Binary a) => String -> IOStateArrow s b a
+readBinaryValue file    = flip decodeBinaryValue file $< getSysVar theBinaryDeCompression
+
+-- | Read a serialied value from a file, optionally decompress it and decode the value
+-- In case of an error, the error message is issued and the arrow fails
+
+decodeBinaryValue         :: (NFData a, Binary a) => DeCompressionFct -> String -> IOStateArrow s b a
+decodeBinaryValue decompress file
+                          = arrIO0 ( do
+                                     r <- dec
+                                     rnf r `seq` return r
+                                   )
+                            `catchA`
+                            issueExc "readBinaryValue"
+    where
+    dec                 = B.readFile file >>= return . decode . decompress
+
+-- | Serialize a value, optionally compress it, and write it to a file.
+-- In case of an error, the error message is issued and the arrow fails
+
+writeBinaryValue        :: (Binary a) => String -> IOStateArrow s a ()
+writeBinaryValue file   = flip encodeBinaryValue file $< getSysVar theBinaryCompression
+
+encodeBinaryValue        :: (Binary a) => CompressionFct -> String -> IOStateArrow s a ()
+encodeBinaryValue compress file
+                         = arrIO enc
+                           `catchA`
+                           issueExc "writeBinaryXmlTree"
+    where
+    enc                  = B.writeFile file . compress . encode
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/DTDProcessing.hs b/src/Text/XML/HXT/Arrow/DTDProcessing.hs
--- a/src/Text/XML/HXT/Arrow/DTDProcessing.hs
+++ b/src/Text/XML/HXT/Arrow/DTDProcessing.hs
@@ -8,7 +8,6 @@
    Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id: DTDProcessing.hs,v 1.9 2006/05/11 14:47:19 hxml Exp $
 
    DTD processing function for
    including external parts of a DTD
@@ -34,7 +33,7 @@
 import qualified Text.XML.HXT.DOM.XmlNode as XN
 
 import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
+import Text.XML.HXT.Arrow.XmlState
 
 import Text.XML.HXT.Arrow.ParserInterface
     ( parseXmlDTDdecl
@@ -127,7 +126,7 @@
       processRoot
           = ( traceMsg 1 ("processDTD: process parameter entities")
               >>>
-              setParamString a_standalone ""
+              setSysAttrString a_standalone ""
               >>>
               ( addDocType
                 `whenNot`
diff --git a/src/Text/XML/HXT/Arrow/DocumentInput.hs b/src/Text/XML/HXT/Arrow/DocumentInput.hs
--- a/src/Text/XML/HXT/Arrow/DocumentInput.hs
+++ b/src/Text/XML/HXT/Arrow/DocumentInput.hs
@@ -8,7 +8,6 @@
    Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id$
 
    State arrows for document input
 -}
@@ -22,36 +21,37 @@
     , getEncoding
     , getTextEncoding
     , decodeDocument
+    , addInputError
     )
 where
 
-import Control.Arrow                            -- arrow classes
-import Control.Arrow.ArrowList
-import Control.Arrow.ArrowIf
-import Control.Arrow.ArrowTree
-import Control.Arrow.ArrowIO
-import Control.Arrow.ListArrow
-
-import Data.List                                ( isPrefixOf )
-
-import System.FilePath                          ( takeExtension )
+import           Control.Arrow                            -- arrow classes
+import           Control.Arrow.ArrowList
+import           Control.Arrow.ArrowIf
+import           Control.Arrow.ArrowTree
+import           Control.Arrow.ArrowIO
+import           Control.Arrow.ListArrow
 
-import Text.XML.HXT.DOM.Unicode                 ( getDecodingFct
+import           Data.List                      ( isPrefixOf )
+import           Data.String.Unicode            ( getDecodingFct
                                                 , guessEncoding
                                                 , normalizeNL
                                                 )
 
+import           System.FilePath                ( takeExtension )
+
 import qualified Text.XML.HXT.IO.GetFILE        as FILE
-import qualified Text.XML.HXT.IO.GetHTTPLibCurl as LibCURL
 
-import Text.XML.HXT.DOM.Interface
+import           Text.XML.HXT.DOM.Interface
 
-import Text.XML.HXT.Arrow.ParserInterface       ( parseXmlDocEncodingSpec
+import           Text.XML.HXT.Arrow.ParserInterface
+                                                ( parseXmlDocEncodingSpec
                                                 , parseXmlEntityEncodingSpec
                                                 , removeEncodingSpec
                                                 )
-import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
+import           Text.XML.HXT.Arrow.XmlArrow
+import           Text.XML.HXT.Arrow.XmlState
+import           Text.XML.HXT.Arrow.XmlState.TypeDefs
 
 -- ----------------------------------------------------------
 
@@ -101,10 +101,7 @@
 
 getFileContents         :: IOStateArrow s XmlTree XmlTree
 getFileContents
-    = applyA ( ( ( getAttrValue  a_strict_input
-                   >>>
-                   arr isTrueValue
-                 )
+    = applyA ( ( getSysVar theStrictInput
                  &&&
                  ( getAttrValue transferURI
                    >>>
@@ -116,7 +113,7 @@
                >>>
                arrIO (uncurry FILE.getCont)
                >>>
-               ( arr (uncurry addError) -- io error occured
+               ( arr (uncurry addInputError) -- io error occured
                  |||
                  arr addTxtContent      -- content read
                )
@@ -126,20 +123,18 @@
 
 getStdinContents                :: IOStateArrow s XmlTree XmlTree
 getStdinContents
-    = applyA (  getAttrValue  a_strict_input
-                >>>
-                arr isTrueValue
+    = applyA (  getSysVar theStrictInput
                 >>>
                 arrIO FILE.getStdinCont
                >>>
-               ( arr (uncurry addError) -- io error occured
+               ( arr (uncurry addInputError) -- io error occured
                  |||
                  arr addTxtContent      -- content read
                )
              )
 
-addError                :: [(String, String)] -> String -> IOStateArrow s XmlTree XmlTree
-addError al e
+addInputError                :: Attributes -> String -> IOStateArrow s XmlTree XmlTree
+addInputError al e
     = issueFatal e
       >>>
       seqA (map (uncurry addAttr) al)
@@ -150,7 +145,7 @@
 addMimeType
     = addMime $< ( getAttrValue transferURI
                    >>>
-                   ( uriToMime $< getSysParam xio_mimeTypes )
+                   ( uriToMime $< getMimeTypeTable )
                  )
     where
     addMime mt
@@ -168,41 +163,7 @@
 
 getHttpContents         :: IOStateArrow s XmlTree XmlTree
 getHttpContents
-    = getCont $<< ( getAttrValue transferURI
-                    &&&
-                    ( ( getAttrlAsAssoc         -- get all attributes of root node
-                        &&&
-                        getAllParamsString      -- get all system params
-                      )
-                      >>^ uncurry addEntries    -- merge them, attributes overwrite system params
-                    )
-                  )
-      where
-      getAttrlAsAssoc                           -- get the attributes as assoc list
-          = listA ( getAttrl
-                    >>> ( getName
-                          &&&
-                          xshow getChildren
-                        )
-                  )
-
-      getCont uri options
-          = applyA ( ( traceMsg 2 ( "get HTTP via libcurl, uri=" ++ show uri ++ " options=" ++ show options )
-                       >>>
-                       arrIO0 ( LibCURL.getCont options uri )
-                     )
-                     >>>
-                     ( arr (uncurry addError)
-                       |||
-                       arr addContent
-                     )
-                   )
-
-      addContent        :: (AssocList String String, String) -> IOStateArrow s XmlTree XmlTree
-      addContent (al, c)
-          = replaceChildren (txt c)
-            >>>
-            seqA (map (uncurry addAttr) al)
+    = withoutUserState $ applyA $ getSysVar theHttpHandler
 
 getURIContents          :: IOStateArrow s XmlTree XmlTree
 getURIContents
@@ -349,7 +310,7 @@
              arr guessEncoding
            , getAttrValue transferEncoding      -- 2. guess: take the transfer encoding
            , getAttrValue a_encoding            -- 3. guess: take encoding parameter in root node
-           , getParamString a_encoding          -- 4. guess: take encoding parameter in global state
+           , getSysVar  theInputEncoding        -- 4. guess: take encoding parameter in global state
            , constA utf8                        -- default : utf8
            ]
       >. (head . filter (not . null))           -- make the filter deterministic: take 1. entry from list of guesses
@@ -358,7 +319,7 @@
 getTextEncoding
     = catA [ getAttrValue transferEncoding      -- 1. guess: take the transfer encoding
            , getAttrValue a_encoding            -- 2. guess: take encoding parameter in root node
-           , getParamString a_encoding          -- 3. guess: take encoding parameter in global state
+           , getSysVar theInputEncoding         -- 3. guess: take encoding parameter in global state
            , constA isoLatin1                   -- default : no encoding
            ]
       >. (head . filter (not . null))           -- make the filter deterministic: take 1. entry from list of guesses
@@ -379,7 +340,7 @@
         found df
             = traceMsg 2 ("decodeDocument: encoding is " ++ show enc)
               >>>
-              ( decodeText df $< getAttrValue a_ignore_encoding_errors )
+              ( decodeText df $< getSysVar theEncodingErrors )
               >>>
               addAttr transferEncoding enc
 
@@ -388,7 +349,7 @@
               >>>
               setDocumentStatusFromSystemState "decoding document"
 
-        decodeText df ignoreErrs
+        decodeText df withEncErrors
             = processChildren
               ( getText                                                 -- get the document content
                 >>> arr df                                              -- decode the text, result is (string, [errMsg])
@@ -396,9 +357,8 @@
                         ^>> mkText
                       )
                       <+>
-                      ( if isTrueValue ignoreErrs
-                        then none                                       -- encoding errors are ignored
-                        else
+                      ( if withEncErrors
+                        then
                         ( arrL snd                                      -- take the error messages
                           >>>
                           arr ((enc ++) . (" encoding error" ++))       -- prefix with enc error
@@ -407,6 +367,7 @@
                           >>>
                           none                                          -- neccessary for type match with <+>
                         )
+                        else none
                       )
                     )
               )
diff --git a/src/Text/XML/HXT/Arrow/DocumentOutput.hs b/src/Text/XML/HXT/Arrow/DocumentOutput.hs
--- a/src/Text/XML/HXT/Arrow/DocumentOutput.hs
+++ b/src/Text/XML/HXT/Arrow/DocumentOutput.hs
@@ -31,12 +31,11 @@
 import Control.Arrow.ArrowIO
 import Control.Arrow.ListArrow
 
-import Text.XML.HXT.DOM.Unicode                 ( getOutputEncodingFct )
+import Data.String.Unicode                      ( getOutputEncodingFct )
+
 import Text.XML.HXT.DOM.Interface
 
 import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
-
 import Text.XML.HXT.Arrow.Edit                  ( addHeadlineToXmlDoc
                                                 , addXmlPi
                                                 , addXmlPiEncoding
@@ -44,6 +43,8 @@
                                                 , numberLinesInXmlDoc
                                                 , treeRepOfXmlDoc
                                                 )
+import Text.XML.HXT.Arrow.XmlState
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
 
 import System.IO                                ( Handle
                                                 , IOMode(..)
@@ -54,7 +55,6 @@
                                                 , hClose
                                                 , stdout
                                                 )
-
 import System.IO.Error                          ( try )
 
 -- ------------------------------------------------------------
@@ -63,45 +63,47 @@
 
 putXmlDocument  :: Bool -> String -> IOStateArrow s XmlTree XmlTree
 putXmlDocument textMode dst
-    = perform ( xshow getChildren
+    = perform putDoc
+      where
+      putDoc
+          = xshow getChildren
+            >>>
+            arrIO (\ s -> try ( hPutDocument (\h -> hPutStrLn h s)))
+            >>>
+            ( ( traceMsg 1 ("io error, document not written to " ++ outFile)
                 >>>
-                arrIO (\ s -> try ( hPutDocument (\h -> hPutStrLn h s)))
+                arr show >>> mkError c_fatal
                 >>>
-                ( ( traceMsg 1 ("io error, document not written to " ++ outFile)
-                    >>>
-                    arr show >>> mkError c_fatal
-                    >>>
-                    filterErrorMsg
-                  )
-                  |||
-                  ( traceMsg 2 ("document written to " ++ outFile)
-                    >>>
-                    none
-                  )
-                )
+                filterErrorMsg
               )
-      where
-      isStdout  = null dst || dst == "-"
+              |||
+              ( traceMsg 2 ("document written to " ++ outFile)
+                >>>
+                none
+              )
+            )
+          where
+          isStdout  = null dst || dst == "-"
 
-      outFile   = if isStdout
-                  then "stdout"
-                       else show dst
+          outFile   = if isStdout
+                      then "stdout"
+                      else show dst
 
-      hPutDocument      :: (Handle -> IO ()) -> IO ()
-      hPutDocument action
-          | isStdout
-              = do
-                hSetBinaryMode stdout (not textMode)
-                action stdout
-                hSetBinaryMode stdout False
-          | otherwise
-              = do
-                handle <- ( if textMode
-                            then openFile
-                            else openBinaryFile
-                          ) dst WriteMode
-                action handle
-                hClose handle
+          hPutDocument      :: (Handle -> IO ()) -> IO ()
+          hPutDocument action
+              | isStdout
+                  = do
+                    hSetBinaryMode stdout (not textMode)
+                    action stdout
+                    hSetBinaryMode stdout False
+              | otherwise
+                  = do
+                    handle <- ( if textMode
+                                then openFile
+                                else openBinaryFile
+                              ) dst WriteMode
+                    action handle
+                    hClose handle
 
 -- |
 -- write the tree representation of a document to a file
@@ -135,9 +137,9 @@
 
 getEncodingParam        :: IOStateArrow s XmlTree String
 getEncodingParam
-    = catA [ getParamString a_output_encoding   -- 4. guess: take output encoding parameter from global state
-           , getParamString a_encoding          -- 5. guess: take encoding parameter from global state
-           , constA utf8                        -- default : utf8
+    = catA [ getSysVar theOutputEncoding   -- 4. guess: take output encoding parameter from global state
+           , getSysVar theInputEncoding    -- 5. guess: take encoding parameter from global state
+           , constA utf8                   -- default : utf8
            ]
       >. (head . filter (not . null))
 
diff --git a/src/Text/XML/HXT/Arrow/Edit.hs b/src/Text/XML/HXT/Arrow/Edit.hs
--- a/src/Text/XML/HXT/Arrow/Edit.hs
+++ b/src/Text/XML/HXT/Arrow/Edit.hs
@@ -66,10 +66,11 @@
 import           Control.Arrow.ArrowTree
 import           Control.Arrow.ListArrow
 
+import           Data.Char.Properties.XMLCharProps      ( isXmlSpaceChar )
+
 import           Text.XML.HXT.Arrow.XmlArrow
 import           Text.XML.HXT.DOM.Interface
 import qualified Text.XML.HXT.DOM.XmlNode       as XN
-import           Text.XML.HXT.DOM.Unicode               ( isXmlSpaceChar )
 import           Text.XML.HXT.DOM.FormatXmlTree         ( formatXmlTree )
 import           Text.XML.HXT.Parser.HtmlParsec         ( emptyHtmlTags )
 import           Text.XML.HXT.Parser.XmlEntities        ( xmlEntities )
@@ -110,7 +111,7 @@
       canonicalize1Node
           = (deep isPi `when` isDTD)            -- remove DTD parts, except PIs
             >>>
-            (none `when` toBeRemoved)           -- remove unintersting nodes
+            (none `when` toBeRemoved)           -- remove uninteresting nodes
             >>>
             ( processAttrl ( processChildren transfCharRef
                              >>>
diff --git a/src/Text/XML/HXT/Arrow/GeneralEntitySubstitution.hs b/src/Text/XML/HXT/Arrow/GeneralEntitySubstitution.hs
--- a/src/Text/XML/HXT/Arrow/GeneralEntitySubstitution.hs
+++ b/src/Text/XML/HXT/Arrow/GeneralEntitySubstitution.hs
@@ -8,7 +8,6 @@
    Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id: GeneralEntitySubstitution.hs,v 1.13 2006/05/01 18:56:24 hxml Exp $
 
    general entity substitution
 
@@ -26,8 +25,9 @@
 import Control.Arrow.ArrowTree
 
 import Text.XML.HXT.DOM.Interface
+
 import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
+import Text.XML.HXT.Arrow.XmlState
 
 import Text.XML.HXT.Arrow.ParserInterface
     ( parseXmlAttrValue
diff --git a/src/Text/XML/HXT/Arrow/Namespace.hs b/src/Text/XML/HXT/Arrow/Namespace.hs
--- a/src/Text/XML/HXT/Arrow/Namespace.hs
+++ b/src/Text/XML/HXT/Arrow/Namespace.hs
@@ -109,14 +109,14 @@
 
 -- ------------------------------------------------------------
 
--- | generate unique namespaces and add all namespace declarations to the root element
+-- | generate unique namespaces and add all namespace declarations to all top nodes containing a namespace declaration
+-- Usually the top node containing namespace declarations is the root node, but this isn't mandatory.
 --
 -- Calls 'cleanupNamespaces' with 'collectNamespaceDecl'
 
-uniqueNamespaces                :: ArrowXml a => a XmlTree XmlTree
-uniqueNamespaces
-    = fromLA $
-      cleanupNamespaces collectNamespaceDecl
+uniqueNamespaces                	:: ArrowXml a => a XmlTree XmlTree
+uniqueNamespaces                	= fromLA $
+					  cleanupNamespaces' collectNamespaceDecl
 
 -- | generate unique namespaces and add all namespace declarations for all prefix-uri pairs in all qualified names
 --
@@ -124,10 +124,22 @@
 -- Calls 'cleanupNamespaces' with @ collectNamespaceDecl \<+> collectPrefixUriPairs @
 
 uniqueNamespacesFromDeclAndQNames       :: ArrowXml a => a XmlTree XmlTree
-uniqueNamespacesFromDeclAndQNames
-    = fromLA $
-      cleanupNamespaces (collectNamespaceDecl <+> collectPrefixUriPairs)
+uniqueNamespacesFromDeclAndQNames       = fromLA $
+					  cleanupNamespaces' ( collectNamespaceDecl
+							       <+>
+							       collectPrefixUriPairs
+							     )
 
+cleanupNamespaces' 			:: LA XmlTree (String, String) -> LA XmlTree XmlTree
+cleanupNamespaces' collectNamespaces	= processTopDownUntil
+					  ( hasNamespaceDecl `guards` cleanupNamespaces collectNamespaces )
+    where
+    hasNamespaceDecl			= isElem
+					  >>>
+					  getAttrl
+					  >>>
+					  isNamespaceDeclAttr
+
 -- | does the real work for namespace cleanup.
 --
 -- The parameter is used for collecting namespace uris and prefixes from the input tree
@@ -148,7 +160,7 @@
             changeQName renamePrefix                    -- update namespace prefix of element names
           )
           >>>
-          attachEnv env1                                -- all all namespaces as attributes to the root node attribute list
+          attachEnv env1                                -- add all namespaces as attributes to the root node attribute list
         where
         renamePrefix    :: QName -> QName
         renamePrefix n
diff --git a/src/Text/XML/HXT/Arrow/ParserInterface.hs b/src/Text/XML/HXT/Arrow/ParserInterface.hs
--- a/src/Text/XML/HXT/Arrow/ParserInterface.hs
+++ b/src/Text/XML/HXT/Arrow/ParserInterface.hs
@@ -1,8 +1,19 @@
--- |
--- interface to the HXT XML and DTD parsers
---
--- version: $Id: ParserInterface.hs,v 1.1 2006/05/01 18:56:24 hxml Exp $
+-- ------------------------------------------------------------
 
+{- |
+   Module     : Text.XML.HXT.Arrow.ParserInterface
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   interface to the HXT XML and DTD parsers
+-}
+
+-- ------------------------------------------------------------
+
 module Text.XML.HXT.Arrow.ParserInterface
     ( module Text.XML.HXT.Arrow.ParserInterface )
 where
@@ -19,11 +30,9 @@
 import Text.XML.HXT.DOM.Interface
 import Text.XML.HXT.Arrow.XmlArrow
 
-import qualified Text.XML.HXT.Parser.TagSoup             as TS
 import qualified Text.XML.HXT.Parser.HtmlParsec          as HP
 import qualified Text.XML.HXT.Parser.XmlParsec           as XP
 import qualified Text.XML.HXT.Parser.XmlDTDParser        as DP
-import qualified Text.XML.HXT.DTDValidation.Validation   as VA
 
 -- ------------------------------------------------------------
 
@@ -68,25 +77,6 @@
 
 parseHtmlContent                :: ArrowList a => a String XmlTree
 parseHtmlContent                = arrL  HP.parseHtmlContent
-
-parseHtmlTagSoup                :: ArrowList a => Bool -> Bool -> Bool -> Bool -> Bool -> a (String, String) XmlTree
-parseHtmlTagSoup withNamespaces withWarnings preserveCmt removeWS asHtml
-                                = arr2L (TS.parseHtmlTagSoup withNamespaces withWarnings preserveCmt removeWS asHtml)
-
--- ------------------------------------------------------------
-
-validateDoc                     :: ArrowList a => a XmlTree XmlTree
-validateDoc                     = fromLA ( VA.validate
-                                           `when`
-                                           VA.getDTDSubset      -- validate only when DTD decl is present
-                                         )
-
-transformDoc                    :: ArrowList a => a XmlTree XmlTree
-transformDoc                    = fromLA VA.transform
-
--- old stuff
--- validateDoc                  = arrL VA.validate
--- transformDoc                 = arrL VA.transform
 
 -- ------------------------------------------------------------
 
diff --git a/src/Text/XML/HXT/Arrow/Pickle.hs b/src/Text/XML/HXT/Arrow/Pickle.hs
--- a/src/Text/XML/HXT/Arrow/Pickle.hs
+++ b/src/Text/XML/HXT/Arrow/Pickle.hs
@@ -8,7 +8,6 @@
    Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id$
 
 Pickler functions for converting between user defined data types
 and XmlTree data. Usefull for persistent storage and retreival
@@ -50,6 +49,7 @@
       -- from Text.XML.HXT.Arrow.Pickle.Xml
     , pickleDoc
     , unpickleDoc
+    , showPickled
 
     , PU(..)
     , XmlPickler
@@ -57,9 +57,29 @@
     , xp4Tuple
     , xp5Tuple
     , xp6Tuple
+    , xp7Tuple
+    , xp8Tuple
+    , xp9Tuple
+    , xp10Tuple
+    , xp11Tuple
+    , xp12Tuple
+    , xp13Tuple
+    , xp14Tuple
+    , xp15Tuple
+    , xp16Tuple
+    , xp17Tuple
+    , xp18Tuple
+    , xp19Tuple
+    , xp20Tuple
+    , xp21Tuple
+    , xp22Tuple
+    , xp23Tuple
+    , xp24Tuple
+
     , xpAddFixedAttr
     , xpAlt
     , xpAttr
+    , xpTextAttr
     , xpAttrFixed
     , xpAttrImplied
     , xpChoice
@@ -102,10 +122,12 @@
 import           Control.Arrow.ListArrows
 
 import           Text.XML.HXT.DOM.Interface
-import           Text.XML.HXT.Arrow.XmlArrow
-import           Text.XML.HXT.Arrow.XmlIOStateArrow
+
 import           Text.XML.HXT.Arrow.ReadDocument
 import           Text.XML.HXT.Arrow.WriteDocument
+import           Text.XML.HXT.Arrow.XmlArrow
+import           Text.XML.HXT.Arrow.XmlState
+import           Text.XML.HXT.Arrow.XmlState.TypeDefs
 
 import           Text.XML.HXT.Arrow.Pickle.Xml
 import           Text.XML.HXT.Arrow.Pickle.Schema
@@ -123,21 +145,25 @@
 -- An option evaluated by this arrow is 'a_addDTD'.
 -- If 'a_addDTD' is set ('v_1'), the pickler DTD is added as an inline DTD into the document.
 
-xpickleDocument         :: PU a -> Attributes -> String -> IOStateArrow s a XmlTree
-xpickleDocument xp al dest
-    = xpickleVal xp
+xpickleDocument         :: PU a -> SysConfigList -> String -> IOStateArrow s a XmlTree
+xpickleDocument xp config dest
+    = localSysEnv
+      $
+      configSysVars config
       >>>
+      xpickleVal xp
+      >>>
       traceMsg 1 "xpickleVal applied"
       >>>
-      ( if lookup1 a_addDTD al == v_1
-        then replaceChildren ( (constA undefined >>> xpickleDTD xp >>> getChildren)
-                               <+>
-                               getChildren
-                             )
-        else this
-      )
+      ifA ( getSysAttr a_addDTD >>> isA (== v_1) )
+          ( replaceChildren ( (constA undefined >>> xpickleDTD xp >>> getChildren)
+			      <+>
+			      getChildren
+                            )
+	  )
+          this
       >>>
-      writeDocument al dest
+      writeDocument [] dest
 
 -- | Option for generating and adding DTD when document is pickled
 
@@ -154,9 +180,9 @@
 -- when applied with the appropriate options. When during pickling indentation is switched on,
 -- the whitespace must be removed during unpickling.
 
-xunpickleDocument       :: PU a -> Attributes -> String -> IOStateArrow s b a
-xunpickleDocument xp al src
-                        = readDocument al src
+xunpickleDocument       :: PU a -> SysConfigList -> String -> IOStateArrow s b a
+xunpickleDocument xp conf src
+                        = readDocument conf src
                           >>>
                           traceMsg 1 ("xunpickleVal for " ++ show src ++ " started")
                           >>>
@@ -166,11 +192,11 @@
 
 -- | Write out the DTD generated out of a pickler. Calls 'xpicklerDTD'
 
-xpickleWriteDTD         :: PU b -> Attributes -> String -> IOStateArrow s b XmlTree
-xpickleWriteDTD xp al dest
+xpickleWriteDTD         :: PU b -> SysConfigList -> String -> IOStateArrow s b XmlTree
+xpickleWriteDTD xp config dest
                         = xpickleDTD xp
                           >>>
-                          writeDocument al dest
+                          writeDocument config dest
 
 -- | The arrow for generating the DTD out of a pickler
 --
@@ -204,7 +230,7 @@
                                   >>>
                                   writeDocumentToString []
                                   >>>
-                                  readFromString [(a_validate, v_1)]
+                                  readFromString [withValidate True]
                                   >>>
                                   ( xunpickleVal xp
                                     `orElse`
@@ -240,5 +266,3 @@
 thePicklerDTD           = dtdDescrToXml . dtdDescr . theSchema
 
 -- ------------------------------------------------------------
-
-
diff --git a/src/Text/XML/HXT/Arrow/Pickle/DTD.hs b/src/Text/XML/HXT/Arrow/Pickle/DTD.hs
--- a/src/Text/XML/HXT/Arrow/Pickle/DTD.hs
+++ b/src/Text/XML/HXT/Arrow/Pickle/DTD.hs
@@ -26,7 +26,7 @@
 
 import           Text.XML.HXT.DOM.Interface
 import           Text.XML.HXT.Arrow.Pickle.Schema
-import           Text.XML.HXT.RelaxNG.XmlSchema.DataTypeLibW3C
+import           Text.XML.HXT.XMLSchema.DataTypeLibW3CNames
 
 -- ------------------------------------------------------------
 
diff --git a/src/Text/XML/HXT/Arrow/Pickle/Schema.hs b/src/Text/XML/HXT/Arrow/Pickle/Schema.hs
--- a/src/Text/XML/HXT/Arrow/Pickle/Schema.hs
+++ b/src/Text/XML/HXT/Arrow/Pickle/Schema.hs
@@ -23,7 +23,7 @@
 where
 
 import Text.XML.HXT.DOM.TypeDefs
-import Text.XML.HXT.RelaxNG.XmlSchema.DataTypeLibW3C
+import Text.XML.HXT.XMLSchema.DataTypeLibW3CNames
 
 import Data.List
     ( sort )
diff --git a/src/Text/XML/HXT/Arrow/Pickle/Xml.hs b/src/Text/XML/HXT/Arrow/Pickle/Xml.hs
--- a/src/Text/XML/HXT/Arrow/Pickle/Xml.hs
+++ b/src/Text/XML/HXT/Arrow/Pickle/Xml.hs
@@ -1,3 +1,5 @@
+{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
+
 -- ------------------------------------------------------------
 
 {- |
@@ -38,6 +40,8 @@
 module Text.XML.HXT.Arrow.Pickle.Xml
 where
 
+import           Control.Arrow.ListArrows
+
 import           Data.Maybe
 import           Data.Map (Map)
 import qualified Data.Map as M
@@ -45,11 +49,12 @@
 import           Text.XML.HXT.DOM.Interface
 import qualified Text.XML.HXT.DOM.XmlNode as XN
 
-import           Control.Arrow.ListArrows
-import           Text.XML.HXT.Arrow.XmlArrow
+import           Text.XML.HXT.Arrow.Edit          (xshowEscapeXml)
 import           Text.XML.HXT.Arrow.Pickle.Schema
 import           Text.XML.HXT.Arrow.ReadDocument  (xread)
-import           Text.XML.HXT.Arrow.Edit          (xshowEscapeXml)
+import           Text.XML.HXT.Arrow.WriteDocument (writeDocumentToString)
+import           Text.XML.HXT.Arrow.XmlArrow
+import           Text.XML.HXT.Arrow.XmlState
 
 -- ------------------------------------------------------------
 
@@ -119,6 +124,13 @@
 
 -- ------------------------------------------------------------
 
+-- | Pickles a value, then writes the document to a string.
+
+showPickled :: (XmlPickler a) => SysConfigList -> a -> String
+showPickled a = concat . (pickleDoc xpickle >>> runLA (writeDocumentToString a))
+
+-- ------------------------------------------------------------
+
 -- | The zero pickler
 --
 -- Encodes nothing, fails always during unpickling
@@ -220,6 +232,8 @@
 xpWrapMaybe             :: (a -> Maybe b, b -> a) -> PU a -> PU b
 xpWrapMaybe (i, j) pa   = (xpSeq j pa (xpLiftMaybe . i)) { theSchema = theSchema pa }
 
+-- ------------------------------------------------------------
+
 -- | pickle a pair of values sequentially
 --
 -- Used for pairs or together with wrap for pickling
@@ -268,6 +282,191 @@
     toSix   ~(a, ~(b, ~(c, ~(d, ~(e, f))))) = (a,  b,  c,  d,  e, f    )
     fromSix ~(a,   b,   c,   d,   e, f)     = (a, (b, (c, (d, (e, f)))))
 
+-- ------------------------------------------------------------
+
+-- | Like 'xpPair' and 'xpTriple' but for 7-tuples
+--
+-- Thanks to Tony Morris for doing xp7Tuple, ..., xp24Tuple.
+
+xp7Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+            PU f -> PU g -> PU (a, b, c, d, e, f, g)
+xp7Tuple a b c d e f g
+    = xpWrap ( \ (a, (b, c, d, e, f, g)) -> (a, b, c, d, e, f, g)
+             , \ (a, b, c, d, e, f, g)   -> (a, (b, c, d, e, f, g))
+             )
+      (xpPair a (xp6Tuple b c d e f g))
+
+xp8Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+            PU f -> PU g -> PU h -> PU (a, b, c, d, e, f, g, h)
+xp8Tuple a b c d e f g h
+    = xpWrap ( \ ((a, b), (c, d, e, f, g, h)) -> (a, b, c, d, e, f, g, h)
+             , \ (a, b, c, d, e, f, g, h) -> ((a, b), (c, d, e, f, g, h))
+             )
+      (xpPair (xpPair a b) (xp6Tuple c d e f g h))
+
+xp9Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+            PU f -> PU g -> PU h -> PU i -> PU (a, b, c, d, e, f, g, h, i)
+xp9Tuple a b c d e f g h i
+    = xpWrap ( \ ((a, b, c), (d, e, f, g, h, i)) -> (a, b, c, d, e, f, g, h, i)
+             , \ (a, b, c, d, e, f, g, h, i) -> ((a, b, c), (d, e, f, g, h, i))
+             )
+      (xpPair (xpTriple a b c) (xp6Tuple d e f g h i))
+
+xp10Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU (a, b, c, d, e, f, g, h, i, j)
+xp10Tuple a b c d e f g h i j
+    = xpWrap ( \ ((a, b, c, d), (e, f, g, h, i, j)) -> (a, b, c, d, e, f, g, h, i, j)
+             , \ (a, b, c, d, e, f, g, h, i, j) -> ((a, b, c, d), (e, f, g, h, i, j))
+             )
+      (xpPair (xp4Tuple a b c d) (xp6Tuple e f g h i j))
+
+xp11Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU (a, b, c, d, e, f, g, h, i, j, k)
+xp11Tuple a b c d e f g h i j k
+    = xpWrap ( \ ((a, b, c, d, e), (f, g, h, i, j, k)) -> (a, b, c, d, e, f, g, h, i, j, k)
+             , \ (a, b, c, d, e, f, g, h, i, j, k) -> ((a, b, c, d, e), (f, g, h, i, j, k))
+             )
+      (xpPair (xp5Tuple a b c d e) (xp6Tuple f g h i j k))
+
+xp12Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU (a, b, c, d, e, f, g, h, i, j, k, l)
+xp12Tuple a b c d e f g h i j k l
+    = xpWrap ( \ ((a, b, c, d, e, f), (g, h, i, j, k, l)) -> (a, b, c, d, e, f, g, h, i, j, k, l)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l) -> ((a, b, c, d, e, f), (g, h, i, j, k, l))
+             )
+      (xpPair (xp6Tuple a b c d e f) (xp6Tuple g h i j k l))
+
+xp13Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m)
+xp13Tuple a b c d e f g h i j k l m
+    = xpWrap ( \ (a, (b, c, d, e, f, g), (h, i, j, k, l, m)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m) -> (a, (b, c, d, e, f, g), (h, i, j, k, l, m))
+             )
+      (xpTriple a (xp6Tuple b c d e f g) (xp6Tuple h i j k l m))
+
+xp14Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
+xp14Tuple a b c d e f g h i j k l m n
+    = xpWrap ( \ ((a, b), (c, d, e, f, g, h), (i, j, k, l, m, n)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> ((a, b), (c, d, e, f, g, h), (i, j, k, l, m, n))
+             )
+      (xpTriple (xpPair a b) (xp6Tuple c d e f g h) (xp6Tuple i j k l m n))
+
+xp15Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
+xp15Tuple a b c d e f g h i j k l m n o
+    = xpWrap ( \ ((a, b, c), (d, e, f, g, h, i), (j, k, l, m, n, o)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> ((a, b, c), (d, e, f, g, h, i), (j, k, l, m, n, o))
+             )
+      (xpTriple (xpTriple a b c) (xp6Tuple d e f g h i) (xp6Tuple j k l m n o))
+
+xp16Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU p -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
+xp16Tuple a b c d e f g h i j k l m n o p
+    = xpWrap ( \ ((a, b, c, d), (e, f, g, h, i, j), (k, l, m, n, o, p)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) -> ((a, b, c, d), (e, f, g, h, i, j), (k, l, m, n, o, p))
+             )
+      (xpTriple (xp4Tuple a b c d) (xp6Tuple e f g h i j) (xp6Tuple k l m n o p))
+
+xp17Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU p -> PU q -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q)
+xp17Tuple a b c d e f g h i j k l m n o p q
+    = xpWrap ( \ ((a, b, c, d, e), (f, g, h, i, j, k), (l, m, n, o, p, q)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q) -> ((a, b, c, d, e), (f, g, h, i, j, k), (l, m, n, o, p, q))
+             )
+      (xpTriple (xp5Tuple a b c d e) (xp6Tuple f g h i j k) (xp6Tuple l m n o p q))
+
+xp18Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU p -> PU q -> PU r -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r)
+xp18Tuple a b c d e f g h i j k l m n o p q r
+    = xpWrap ( \ ((a, b, c, d, e, f), (g, h, i, j, k, l), (m, n, o, p, q, r)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r) -> ((a, b, c, d, e, f), (g, h, i, j, k, l), (m, n, o, p, q, r))
+             )
+      (xpTriple (xp6Tuple a b c d e f) (xp6Tuple g h i j k l) (xp6Tuple m n o p q r))
+
+xp19Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU p -> PU q -> PU r -> PU s -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s)
+xp19Tuple a b c d e f g h i j k l m n o p q r s
+    = xpWrap ( \ (a, (b, c, d, e, f, g), (h, i, j, k, l, m), (n, o, p, q, r, s)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s) -> (a, (b, c, d, e, f, g), (h, i, j, k, l, m), (n, o, p, q, r, s))
+             )
+      (xp4Tuple a (xp6Tuple b c d e f g) (xp6Tuple h i j k l m) (xp6Tuple n o p q r s))
+
+xp20Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU p -> PU q -> PU r -> PU s -> PU t ->
+             PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)
+xp20Tuple a b c d e f g h i j k l m n o p q r s t
+    = xpWrap ( \ ((a, b), (c, d, e, f, g, h), (i, j, k, l, m, n), (o, p, q, r, s, t)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t) -> ((a, b), (c, d, e, f, g, h), (i, j, k, l, m, n), (o, p, q, r, s, t))
+             )
+      (xp4Tuple (xpPair a b) (xp6Tuple c d e f g h) (xp6Tuple i j k l m n) (xp6Tuple o p q r s t))
+
+xp21Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU p -> PU q -> PU r -> PU s -> PU t ->
+             PU u -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u)
+xp21Tuple a b c d e f g h i j k l m n o p q r s t u
+    = xpWrap ( \ ((a, b, c), (d, e, f, g, h, i), (j, k, l, m, n, o), (p, q, r, s, t, u)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u) -> ((a, b, c), (d, e, f, g, h, i), (j, k, l, m, n, o), (p, q, r, s, t, u))
+             )
+      (xp4Tuple (xpTriple a b c) (xp6Tuple d e f g h i) (xp6Tuple j k l m n o) (xp6Tuple p q r s t u))
+
+xp22Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU p -> PU q -> PU r -> PU s -> PU t ->
+             PU u -> PU v -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v)
+xp22Tuple a b c d e f g h i j k l m n o p q r s t u v
+    = xpWrap ( \ ((a, b, c, d), (e, f, g, h, i, j), (k, l, m, n, o, p), (q, r, s, t, u, v)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v) -> ((a, b, c, d), (e, f, g, h, i, j), (k, l, m, n, o, p), (q, r, s, t, u, v))
+             )
+      (xp4Tuple (xp4Tuple a b c d) (xp6Tuple e f g h i j) (xp6Tuple k l m n o p) (xp6Tuple q r s t u v))
+
+xp23Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU p -> PU q -> PU r -> PU s -> PU t ->
+             PU u -> PU v -> PU w -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w)
+xp23Tuple a b c d e f g h i j k l m n o p q r s t u v w
+    = xpWrap ( \ ((a, b, c, d, e), (f, g, h, i, j, k), (l, m, n, o, p, q), (r, s, t, u, v, w)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w) -> ((a, b, c, d, e), (f, g, h, i, j, k), (l, m, n, o, p, q), (r, s, t, u, v, w))
+             )
+      (xp4Tuple (xp5Tuple a b c d e) (xp6Tuple f g h i j k) (xp6Tuple l m n o p q) (xp6Tuple r s t u v w))
+
+-- | Hopefully no one needs a xp25Tuple
+
+xp24Tuple :: PU a -> PU b -> PU c -> PU d -> PU e ->
+             PU f -> PU g -> PU h -> PU i -> PU j ->
+             PU k -> PU l -> PU m -> PU n -> PU o ->
+             PU p -> PU q -> PU r -> PU s -> PU t ->
+             PU u -> PU v -> PU w -> PU x -> PU (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x)
+xp24Tuple a b c d e f g h i j k l m n o p q r s t u v w x
+    = xpWrap ( \ ((a, b, c, d, e, f), (g, h, i, j, k, l), (m, n, o, p, q, r), (s, t, u, v, w, x)) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x)
+             , \ (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x) -> ((a, b, c, d, e, f), (g, h, i, j, k, l), (m, n, o, p, q, r), (s, t, u, v, w, x))
+             )
+      (xp4Tuple (xp6Tuple a b c d e f) (xp6Tuple g h i j k l) (xp6Tuple m n o p q r) (xp6Tuple s t u v w x))
+
+-- ------------------------------------------------------------
+
+
 -- | Pickle a string into an XML text node
 --
 -- One of the most often used primitive picklers. Attention:
@@ -623,6 +822,10 @@
 xpAttr          :: String -> PU a -> PU a
 xpAttr          = xpAttrQN . mkName
 
+-- | A text attribute.
+xpTextAttr :: String -> PU String
+xpTextAttr = flip xpAttr xpText
+
 -- | Add an optional attribute for an optional value (Maybe a).
 
 xpAttrImplied   :: String -> PU a -> PU (Maybe a)
@@ -692,3 +895,42 @@
     xpickle = xpOption xpickle
 
 -- ------------------------------------------------------------
+
+-- ------------------------------------------------------------
+{-
+-- | Extra library functions for HXT.
+module Text.XML.HXT.Extras(
+                     showPickled,
+                     textAttr,
+                     xp7Tuple,
+                     xp8Tuple,
+                     xp9Tuple,
+                     xp10Tuple,
+                     xp11Tuple,
+                     xp12Tuple,
+                     xp13Tuple,
+                     xp14Tuple,
+                     xp15Tuple,
+                     xp16Tuple,
+                     xp17Tuple,
+                     xp18Tuple,
+                     xp19Tuple,
+                     xp20Tuple,
+                     xp21Tuple,
+                     xp22Tuple,
+                     xp23Tuple,
+                     xp24Tuple
+                   ) where
+
+import Text.XML.HXT.Arrow
+
+-- | Pickles a value then writes the document to a string.
+showPickled :: (XmlPickler a) => Attributes -> a -> String
+showPickled a = concat . (pickleDoc xpickle >>> runLA (writeDocumentToString a))
+
+-- | A text attribute.
+textAttr :: String -> PU String
+textAttr = flip xpAttr xpText
+-}
+-- ------------------------------------------------------------
+
diff --git a/src/Text/XML/HXT/Arrow/ProcessDocument.hs b/src/Text/XML/HXT/Arrow/ProcessDocument.hs
--- a/src/Text/XML/HXT/Arrow/ProcessDocument.hs
+++ b/src/Text/XML/HXT/Arrow/ProcessDocument.hs
@@ -8,7 +8,6 @@
    Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id: ProcessDocument.hs,v 1.3 2006/08/30 16:20:52 hxml Exp $
 
    Compound arrows for reading, parsing, validating and writing XML documents
 
@@ -22,6 +21,7 @@
     , parseHtmlDocument
     , validateDocument
     , propagateAndValidateNamespaces
+    , andValidateNamespaces
     , getDocumentContents
     )
 where
@@ -30,40 +30,39 @@
 import Control.Arrow.ArrowList
 import Control.Arrow.ArrowIf
 import Control.Arrow.ArrowTree
+import Control.Arrow.ListArrow                  ( fromLA )
 
 import Text.XML.HXT.DOM.Interface
+
 import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
+import Text.XML.HXT.Arrow.XmlState
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
 
-import Text.XML.HXT.Arrow.ParserInterface
-    ( parseXmlDoc
-    , parseHtmlDoc
-    , parseHtmlTagSoup
-    , substHtmlEntityRefs
-    , validateDoc
-    , transformDoc
-    )
+import Text.XML.HXT.Arrow.ParserInterface       ( parseXmlDoc
+                                                , parseHtmlDoc
+                                                , substHtmlEntityRefs
+                                                )
 
-import Text.XML.HXT.Arrow.Edit
-    ( transfAllCharRef
-    )
+import Text.XML.HXT.Arrow.Edit                  ( transfAllCharRef
+                                                )
 
 import Text.XML.HXT.Arrow.GeneralEntitySubstitution
-    ( processGeneralEntities
-    )
+                                               ( processGeneralEntities
+                                               )
 
-import Text.XML.HXT.Arrow.DTDProcessing
-    ( processDTD
-    )
+import Text.XML.HXT.Arrow.DTDProcessing        ( processDTD
+                                               )
 
-import Text.XML.HXT.Arrow.DocumentInput
-    ( getXmlContents
-    )
+import Text.XML.HXT.Arrow.DocumentInput        ( getXmlContents
+                                               )
 
-import Text.XML.HXT.Arrow.Namespace
-    ( propagateNamespaces
-    , validateNamespaces
-    )
+import Text.XML.HXT.Arrow.Namespace            ( propagateNamespaces
+                                               , validateNamespaces
+                                               )
+import Text.XML.HXT.DTDValidation.Validation   ( validate
+                                               , getDTDSubset
+                                               , transform
+                                               )
 
 -- ------------------------------------------------------------
 
@@ -87,7 +86,7 @@
 -}
 
 parseXmlDocument        :: Bool -> IOStateArrow s XmlTree XmlTree
-parseXmlDocument validate
+parseXmlDocument validate'
     = ( replaceChildren ( ( getAttrValue a_source
                             &&&
                             xshow getChildren
@@ -106,7 +105,7 @@
         >>>
         transfAllCharRef
         >>>
-        ( if validate
+        ( if validate'
           then validateDocument
           else this
         )
@@ -129,19 +128,14 @@
 
 -}
 
-parseHtmlDocument       :: Bool -> Bool -> Bool -> Bool -> Bool -> Bool -> IOStateArrow s XmlTree XmlTree
-parseHtmlDocument withTagSoup withNamespaces warnings preserveCmt removeWhitespace asHtml
+parseHtmlDocument       :: IOStateArrow s XmlTree XmlTree
+parseHtmlDocument
     = ( perform ( getAttrValue a_source >>> traceValue 1 (("parseHtmlDoc: parse HTML document " ++) . show) )
         >>>
-        replaceChildren ( ( getAttrValue a_source               -- get source name
-                            &&&
-                            xshow getChildren
-                          )                                     -- get string to be parsed
-                          >>>
-                          parseHtml
-                        )
+        ( parseHtml $< getSysVar theTagSoup )
         >>>
-        removeWarnings
+        ( removeWarnings $< getSysVar (theWarnings .&&&. theTagSoup )
+        )
         >>>
         setDocumentStatusFromSystemState "parse HTML document"
         >>>
@@ -156,20 +150,24 @@
       )
       `when` documentStatusOk
     where
-    parseHtml
-        | withTagSoup   = traceMsg 1 ("parse document with tagsoup " ++
-                                      ( if asHtml then "HT" else "X" ) ++ "ML parser"
-                                     )
-                          >>>
-                          parseHtmlTagSoup withNamespaces warnings preserveCmt removeWhitespace asHtml
+    parseHtml withTagSoup'
+        | withTagSoup'  = withoutUserState $< getSysVar theTagSoupParser -- withoutUserState parseHtmlTagSoup
 
         | otherwise     = traceMsg 1 ("parse document with parsec HTML parser")
                           >>>
-                          parseHtmlDoc                          -- run parser
+                          replaceChildren
+                          ( ( getAttrValue a_source             -- get source name
+                              &&&
+                              xshow getChildren
+                            )                                   -- get string to be parsed
+                            >>>
+                            parseHtmlDoc                        -- run parser
+                          )
                           >>>
                           substHtmlEntityRefs                   -- substitute entity refs
-    removeWarnings
-        | withTagSoup
+
+    removeWarnings (warnings, withTagSoup')
+        | withTagSoup'
           &&
           not warnings  = this
         | otherwise     = processTopDownWithAttrl
@@ -209,9 +207,11 @@
         >>>
         setDocumentStatusFromSystemState "document validation"
         >>>
+        traceMsg 1 "document validated, transforming doc with respect to DTD"
+        >>>
         transformDoc
         >>>
-        traceMsg 1 "document validated"
+        traceMsg 1 "document transformed"
         >>>
         traceSource
         >>>
@@ -245,7 +245,14 @@
         >>>
         traceDoc "propagating namespaces done"
         >>>
-        traceMsg 1 "validating namespaces"
+        andValidateNamespaces
+      )
+      `when`
+      documentStatusOk
+
+andValidateNamespaces  :: IOStateArrow s XmlTree XmlTree
+andValidateNamespaces
+    = ( traceMsg 1 "validating namespaces"
         >>>
         ( setDocumentStatusFromSystemState "namespace propagation"
           `when`
@@ -269,16 +276,25 @@
    For supported protocols see 'Text.XML.HXT.Arrow.DocumentInput.getXmlContents'
 -}
 
-getDocumentContents     :: Attributes -> String -> IOStateArrow s b XmlTree
-getDocumentContents options src
+getDocumentContents     :: String -> IOStateArrow s b XmlTree
+getDocumentContents src
     = root [] []
       >>>
       addAttr a_source src
       >>>
-      seqA (map (uncurry addAttr) options)                                      -- add all options to doc root
-      >>>                                                                       -- e.g. getXmlContents needs some of these
       traceMsg 1 ("readDocument: start processing document " ++ show src)
       >>>
       getXmlContents
+
+-- ------------------------------------------------------------
+
+validateDoc                     :: ArrowList a => a XmlTree XmlTree
+validateDoc                     = fromLA ( validate
+                                           `when`
+                                           getDTDSubset      -- validate only when DTD decl is present
+                                         )
+
+transformDoc                    :: ArrowList a => a XmlTree XmlTree
+transformDoc                    = fromLA transform
 
 -- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/ReadDocument.hs b/src/Text/XML/HXT/Arrow/ReadDocument.hs
--- a/src/Text/XML/HXT/Arrow/ReadDocument.hs
+++ b/src/Text/XML/HXT/Arrow/ReadDocument.hs
@@ -6,11 +6,10 @@
    License    : MIT
 
    Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
+   Stability  : stable
    Portability: portable
-   Version    : $Id: ReadDocument.hs,v 1.10 2006/11/24 07:41:37 hxml Exp $
 
-Compound arrows for reading an XML\/HTML document or an XML\/HTML string
+   Compound arrows for reading an XML\/HTML document or an XML\/HTML string
 
 -}
 
@@ -28,179 +27,167 @@
 
 import Control.Arrow.ListArrows
 
-import Data.Char                                ( isDigit )
 import Text.XML.HXT.DOM.Interface
-import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
 
+import Text.XML.HXT.Arrow.XmlArrow
 import Text.XML.HXT.Arrow.Edit                  ( canonicalizeAllNodes
                                                 , canonicalizeForXPath
                                                 , canonicalizeContents
                                                 , rememberDTDAttrl
                                                 , removeDocWhiteSpace
                                                 )
-
 import Text.XML.HXT.Arrow.ParserInterface
-
 import Text.XML.HXT.Arrow.ProcessDocument       ( getDocumentContents
                                                 , parseXmlDocument
                                                 , parseHtmlDocument
                                                 , propagateAndValidateNamespaces
+                                                , andValidateNamespaces
                                                 )
-
-import Text.XML.HXT.RelaxNG.Validator           ( validateDocumentWithRelaxSchema )
+import Text.XML.HXT.Arrow.XmlState
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
 
 -- ------------------------------------------------------------
-
+--
 {- |
 the main document input filter
 
-this filter can be configured by an option list, a value of type 'Text.XML.HXT.DOM.TypeDefs.Attributes'
-
-available options:
-
-* 'a_parse_html': use HTML parser, else use XML parser (default)
-
-- 'a_tagsoup' : use light weight and lazy parser based on tagsoup lib
-
-- 'a_parse_by_mimetype' : select the parser by the mime type of the document
-                          (pulled out of the HTTP header). When the mime type is set to \"text\/html\"
-                          the HTML parser (parsec or tagsoup) is taken, when it\'s set to
-                          \"text\/xml\" or \"text\/xhtml\" the XML parser (parsec or tagsoup) is taken.
-                          If the mime type is something else no further processing is performed,
-                          the contents is given back to the application in form of a single text node.
-                          If the default document encoding ('a_encoding') is set to isoLatin1, this even enables processing
-                          of arbitray binary data.
-
-- 'a_validate' : validate document againsd DTD (default), else skip validation
-
-- 'a_relax_schema' : validate document with Relax NG, the options value is the schema URI
-                     this implies using XML parser, no validation against DTD, and canonicalisation
-
-- 'a_check_namespaces' : check namespaces, else skip namespace processing (default)
-
-- 'a_canonicalize' : canonicalize document (default), else skip canonicalization
-
-- 'a_preserve_comment' : preserve comments during canonicalization, else remove comments (default)
-
-- 'a_remove_whitespace' : remove all whitespace, used for document indentation, else skip this step (default)
-
-- 'a_indent' : indent document by inserting whitespace, else skip this step (default)
-
-- 'a_issue_warnings' : issue warnings, when parsing HTML (default), else ignore HTML parser warnings
-
-- 'a_issue_errors' : issue all error messages on stderr (default), or ignore all error messages
-
-- 'a_ignore_encoding_errors': ignore all encoding errors, default is issue all encoding errors
-
-- 'a_ignore_none_xml_contents': ignore document contents of none XML\/HTML documents.
-                                This option can be useful for implementing crawler like applications, e.g. an URL checker.
-                                In those cases net traffic can be reduced.
-
-- 'a_trace' : trace level: values: 0 - 4
-
-- 'a_proxy' : proxy for http access, e.g. www-cache:3128
-
-- 'a_redirect' : automatically follow redirected URIs, default is yes
+this filter can be configured by a list of configuration options, a value of type 'Text.XML.HXT.XmlState.TypeDefs.SysConfig'
 
-- 'a_use_curl' : obsolete and ignored, HTTP acccess is always done with curl bindings for libcurl
+for all available options see module 'Text.XML.HXT.XmlState.SystemConfig'
 
-- 'a_strict_input' : file input is done strictly using the 'Data.ByteString' input functions. This ensures correct closing of files, especially when working with
-                     the tagsoup parser and not processing the whole input data. Default is off. The @ByteString@ input usually is not faster than the buildin @hGetContents@
-                     for strings.
+- @withValidate yes\/no@ :
+  switch on\/off DTD validation. Only for XML parsed documents, not for HTML parsing.
 
-- 'a_options_curl' : deprecated but for compatibility reasons still supported.
-                     More options passed to the curl binding.
-                     Instead of using this option to set a whole bunch of options at once for curl
-                     it is recomended to use the @curl-.*@ options syntax described below.
+- @withParseHTML yes\/no@ :
+  switch on HTML parsing.
 
-- 'a_encoding' : default document encoding ('utf8', 'isoLatin1', 'usAscii', 'iso8859_2', ... , 'iso8859_16', ...).
-                 Only XML, HTML and text documents are decoded,
-                 default decoding for XML\/HTML is utf8, for text iso latin1 (no decoding).
-                 The whole content is returned in a single text node.
+- @withParseByMimeType yes\/no@ :
+  select XML\/HTML parser by document mime type.
+  text\/xml and text\/xhtml are parsed as XML, text\/html as HTML.
 
-- 'a_mime_types' : set the mime type table for file input with given file. The format of this config file must be in the syntax of a debian linux \"mime.types\" config file
+- @withCheckNamespaces yes\/no@ :
+  Switch on\/off namespace propagation and checking
 
-- 'a_if_modified_since' : read document conditionally, only if the document is newer than the given date and time argument, the contents is delivered,
-                          else just the root node with the meta data is returned. The date and time must be given in "System.Locale.rfc822DateFormat".
+- @withInputEncoding <encoding-spec>@ :
+  Set default encoding.
 
-- curl options : the HTTP interface with libcurl can be configured with a lot of options. To support these options in an easy way, there is a naming convetion:
-                 Every option, which has the prefix @curl@ and the rest of the name forms an option as described in the curl man page, is passed to the curl binding lib.
-                 See 'Text.XML.HXT.IO.GetHTTPLibCurl.getCont' for examples. Currently most of the options concerning HTTP requests are implemented.
+- @withTagSoup@ :
+  use light weight and lazy parser based on tagsoup lib.
+  This is only available when package hxt-tagsoup is installed and
+  'Text.XML.HXT.TagSoup' is imported
 
-All attributes not evaluated by readDocument are stored in the created document root node for easy access of the various
-options in e.g. the input\/output modules
+- @withRelaxNG <schema.rng>@ :
+  validate document with Relax NG, the parameter is for the schema URI.
+  This implies using XML parser, no validation against DTD, and canonicalisation.
 
-If the document name is the empty string or an uri of the form \"stdin:\", the document is read from standard input.
+- @withCurl [<curl-option>...]@ :
+  Use the libCurl binding for HTTP access.
+  This is only available when package hxt-curl is installed and
+  'Text.XML.HXT.Curl' is imported
+                   
+- @withHTTP [<http-option>...]@ :
+  Use the Haskell HTTP package for HTTP access.
+  This is only available when package hxt-http is installed and
+  'Text.XML.HXT.HTTP' is imported
 
 examples:
 
-> readDocument [ ] "test.xml"
+> readDocument [] "test.xml"
 
 reads and validates a document \"test.xml\", no namespace propagation, only canonicalization is performed
 
-> readDocument [ (a_validate, "0")
->              , (a_encoding, isoLatin1)
->              , (a_parse_by_mimetype, "1")
->              ] "http://localhost/test.php"
+> ...
+> import Text.XML.HXT.Curl
+> ...
+>
+> readDocument [ withValidate        no
+>              , withInputEncoding   isoLatin1
+>              , withParseByMimeType yes
+>              , withCurl []
+>              ] \"http:\/\/localhost\/test.php\"
 
 reads document \"test.php\", parses it as HTML or XML depending on the mimetype given from the server, but without validation, default encoding 'isoLatin1'.
-
+HTTP access is done via libCurl.
 
-> readDocument [ (a_parse_html, "1")
->              , (a_encoding, isoLatin1)
+> readDocument [ withParseHTML       yes
+>              , withInputEncoding   isoLatin1
 >              ] ""
 
 reads a HTML document from standard input, no validation is done when parsing HTML, default encoding is 'isoLatin1',
-parsing is done with tagsoup parser, but input is read strictly
 
-> readDocument [ (a_encoding, isoLatin1)
->              , (a_mime_type,    "/etc/mime.types")
->              , (a_tagsoup,      "1")
->              , (a_strict_input, "1")
+> readDocument [ withInputEncoding  isoLatin1
+>              , withValidate       no
+>              , withMimeTypeFile   "/etc/mime.types"
+>              , withStrictInput    yes
 >              ] "test.svg"
 
-reads an SVG document from standard input, sets the mime type by looking in the system mimetype config file, default encoding is 'isoLatin1',
-parsing is done with the lightweight tagsoup parser, which implies no validation.
+reads an SVG document from \"test.svg\", sets the mime type by looking in the system mimetype config file,
+default encoding is 'isoLatin1',
 
-> readDocument [ (a_parse_html,     "1")
->              , (a_proxy,          "www-cache:3128")
->              , (a_curl,           "1")
->              , (a_issue_warnings, "0")
+> ...
+> import Text.XML.HXT.Curl
+> import Text.XML.HXT.TagSoup
+> ...
+>
+> readDocument [ withParseHTML      yes
+>              , withTagSoup
+>              , withProxy          "www-cache:3128"
+>              , withCurl           []
+>              , withWarnings       no
 >              ] "http://www.haskell.org/"
 
-reads Haskell homepage with HTML parser ignoring any warnings, with http access via external program curl and proxy \"www-cache\" at port 3128
+reads Haskell homepage with HTML parser, ignoring any warnings
+(at the time of writing, there were some HTML errors),
+with http access via libCurl interface
+and proxy \"www-cache\" at port 3128,
+parsing is done with tagsoup HTML parser.
+This requires packages \"hxt-curl\" and \"hxt-tagsoup\" to be installed
 
-> readDocument [ (a_validate,          "1")
->              , (a_check_namespace,   "1")
->              , (a_remove_whitespace, "1")
->              , (a_trace,             "2")
+> readDocument [ withValidate          yes
+>              , withCheckNamespaces   yes
+>              , withRemoveWS          yes
+>              , withTrace             2
+>              , withHTTP              []
 >              ] "http://www.w3c.org/"
 
-read w3c home page (xhtml), validate and check namespaces, remove whitespace between tags, trace activities with level 2
+read w3c home page (xhtml), validate and check namespaces, remove whitespace between tags, trace activities with level 2.
+HTTP access is done with Haskell HTTP package
 
 for minimal complete examples see 'Text.XML.HXT.Arrow.WriteDocument.writeDocument' and 'runX', the main starting point for running an XML arrow.
 -}
 
-readDocument    :: Attributes -> String -> IOStateArrow s b XmlTree
-readDocument userOptions src
-    = case getTraceLev of
-      Nothing   ->                    readDocument' userOptions src
-      Just l    -> withTraceLevel l $ readDocument' userOptions src
-    where
-    getTraceLev = do
-                  s <- lookup a_trace $ userOptions
-                  if not (null s) && all isDigit s
-                      then return (read s)
-                      else fail "not a number"
+readDocument    :: SysConfigList -> String -> IOStateArrow s b XmlTree
+readDocument config src
+    = localSysEnv
+      $
+      readDocument' config src
 
-readDocument'   :: Attributes -> String -> IOStateArrow s b XmlTree
-readDocument' userOptions src
-    = loadMineTypes (lookup1 a_mime_types userOptions)
+readDocument'   :: SysConfigList -> String -> IOStateArrow s b XmlTree
+readDocument' config src
+    = configSysVars config
       >>>
-      getDocumentContents options src
+      readD $< getSysVar theWithCache
+    where
+    readD True  = constA undefined		-- just for generalizing the signature to: IOStateArrow s b       XmlTree
+                  >>>                           -- instead of                              IOStateArrow s XmlTree XmlTree
+                  (withoutUserState $< (getSysVar theCacheRead >>^ ($ src)))
+    readD False	= readDocument'' src
+
+readDocument''   :: String -> IOStateArrow s b XmlTree
+readDocument'' src
+    = getDocumentContents src
       >>>
-      ( processDoc $< getMimeType )
+      ( processDoc
+        $<<
+        ( getMimeType
+          &&&
+          getSysVar (theParseByMimeType   .&&&.
+                     theParseHTML         .&&&.
+                     theAcceptedMimeTypes .&&&.
+                     theRelaxValidate
+                    )
+        )
+      )
       >>>
       traceMsg 1 ("readDocument: " ++ show src ++ " processed")
       >>>
@@ -208,48 +195,40 @@
       >>>
       traceTree
     where
-    options
-        = addEntries userOptions defaultOptions
-
-    defaultOptions
-        = [ ( a_parse_html,               v_0 )
-          , ( a_tagsoup,                  v_0 )
-          , ( a_strict_input,             v_0 )
-          , ( a_validate,                 v_1 )
-          , ( a_issue_warnings,           v_1 )
-          , ( a_check_namespaces,         v_0 )
-          , ( a_canonicalize,             v_1 )
-          , ( a_preserve_comment,         v_0 )
-          , ( a_remove_whitespace,        v_0 )
-          , ( a_parse_by_mimetype,        v_0 )
-          , ( a_ignore_encoding_errors,   v_0 )
-          , ( a_ignore_none_xml_contents, v_0 )
-          , ( a_accept_mimetypes,         ""  )
-          ]
-
-    loadMineTypes ""    = this
-    loadMineTypes f     = setMimeTypeTableFromFile f
-
     getMimeType
         = getAttrValue transferMimeType >>^ stringToLower
 
-    processDoc mimeType
+    processDoc mimeType (parseByMimeType, (parseHtml, (acceptedMimeTypes, validateWithRelax)))
         = traceMsg 1 (unwords [ "readDocument:", show src
                               , "(mime type:", show mimeType, ") will be processed"])
           >>>
-          ( if isAcceptedMimeType (lookup1 a_accept_mimetypes options) mimeType
+          ( if isAcceptedMimeType acceptedMimeTypes mimeType
             then ( ifA (fromLA hasEmptyBody)
                    ( replaceChildren none )                                     -- empty response, e.g. in if-modified-since request
-                   ( parse
+                   ( ( parse $< getSysVar (theValidate              .&&&.
+                                           theIgnoreNoneXmlContents .&&&.
+                                           theTagSoup
+                                          )
+                     )
                      >>>
                      ( if isXmlOrHtml
-                       then ( checknamespaces
+                       then ( ( checknamespaces $< getSysVar (theCheckNamespaces .&&&.
+                                                              theTagSoup
+                                                             )
+                              )
                               >>>
                               rememberDTDAttrl
                               >>>
-                              canonicalize
+                              ( canonicalize $< getSysVar (thePreserveComment .&&&.
+                                                           theCanonicalize    .&&&.
+                                                           theTagSoup
+                                                          )
+                              )
                               >>>
-                              whitespace
+                              ( whitespace $< getSysVar (theRemoveWS .&&&.
+                                                         theTagSoup
+                                                        )
+                              )
                               >>>
                               relax
                             )
@@ -272,7 +251,7 @@
                                             ( getChildren >>> isWhiteSpace )
                                           )
 
-        isAcceptedMimeType              :: String -> String -> Bool
+        isAcceptedMimeType              :: [String] -> String -> Bool
         isAcceptedMimeType mts mt
             | null mts
               ||
@@ -280,9 +259,7 @@
             | otherwise                 = foldr (matchMt mt') False $ mts'
             where
             mt'                         = parseMt mt
-            mts'                        = words
-                                          >>>
-                                          map parseMt
+            mts'                        = map parseMt
                                           $
                                           mts
             parseMt                     = break (== '/')
@@ -293,75 +270,73 @@
                                             (mi == mis || mis == "*")
                                           )
                                           || r
-        parse
+        parse (validate, (removeNoneXml, withTagSoup'))
+	    | not isXmlOrHtml           = if removeNoneXml
+					  then replaceChildren none             -- don't parse, if mime type is not XML nor HTML
+					  else this                             -- but remove contents when option is set
+
             | isHtml
-              ||
-              withTagSoup               = parseHtmlDocument                     -- parse as HTML or with tagsoup XML
-                                          withTagSoup
-                                          withNamespaces
-                                          issueW
-                                          (not (hasOption a_canonicalize) && preserveCmt)
-                                          removeWS
-                                          isHtml
-            | validateWithRelax         = parseXmlDocument False                -- for Relax NG use XML parser without validation
-            | isXml                     = parseXmlDocument validate             -- parse as XML
-            | removeNoneXml             = replaceChildren none                  -- don't parse, if mime type is not XML nor HTML
-            | otherwise                 = this                                  -- but remove contents when option is set
-        checknamespaces
-            | (withNamespaces && not withTagSoup)
+	      ||
+              withTagSoup'              = configSysVar (setS theLowerCaseNames isHtml)
+                                          >>>
+                                          parseHtmlDocument                     -- parse as HTML or with tagsoup XML
+
+            | isXml                     = parseXmlDocument (not validateWithRelax && validate)           -- parse as XML
+            | otherwise                 = this                                  -- suppress warning
+
+        checknamespaces (withNamespaces, withTagSoup')
+            | withNamespaces
+	      &&
+	      withTagSoup'		= andValidateNamespaces			-- propagation is done in tagsoup
+
+            | withNamespaces
               ||
-              validateWithRelax         = propagateAndValidateNamespaces
+              validateWithRelax         = propagateAndValidateNamespaces	-- RelaxNG requires correct namespaces
+
             | otherwise                 = this
-        canonicalize
-            | withTagSoup               = this                                  -- tagsoup already removes redundant stuff
+
+        canonicalize (preserveCmt, (canonicalize', withTagSoup'))
+            | withTagSoup'              = this                                  -- tagsoup already removes redundant stuff
             | validateWithRelax         = canonicalizeAllNodes
-            | hasOption a_canonicalize
+            | canonicalize'
               &&
               preserveCmt               = canonicalizeForXPath
-            | hasOption a_canonicalize  = canonicalizeAllNodes
+            | canonicalize'             = canonicalizeAllNodes
             | otherwise                 = this
+
         relax
-            | validateWithRelax         = validateDocumentWithRelaxSchema options relaxSchema
+            | validateWithRelax         = withoutUserState $< getSysVar theRelaxValidator
             | otherwise                 = this
-        whitespace
+
+        whitespace (removeWS, withTagSoup')
             | removeWS
               &&
-              not withTagSoup           = removeDocWhiteSpace                   -- tagsoup already removes whitespace
+              not withTagSoup'          = removeDocWhiteSpace                   -- tagsoup already removes whitespace
             | otherwise                 = this
-        validateWithRelax       = hasEntry a_relax_schema options
-        relaxSchema             = lookup1 a_relax_schema options
-        parseHtml               = hasOption a_parse_html
-        isHtml                  = parseHtml                                     -- force HTML
-                                  ||
-                                  ( parseByMimeType && isHtmlMimeType mimeType )
-        isXml                   = ( not parseByMimeType && not parseHtml )
-                                  ||
-                                  ( parseByMimeType
-                                    &&
-                                    ( isXmlMimeType mimeType
-                                      ||
-                                      null mimeType
-                                    )                                           -- mime type is XML or not known
-                                  )
+
+        isHtml                          = ( not parseByMimeType && parseHtml )  -- force HTML
+					  ||
+					  ( parseByMimeType && isHtmlMimeType mimeType )
+
+        isXml                           = ( not parseByMimeType && not parseHtml )
+					  ||
+					  ( parseByMimeType
+					    &&
+					    ( isXmlMimeType mimeType
+					      ||
+					      null mimeType
+					    )                                   -- mime type is XML or not known
+					  )
+
         isXmlOrHtml     = isHtml || isXml
-        parseByMimeType = hasOption a_parse_by_mimetype
-        validate        = hasOption a_validate
-        withNamespaces  = hasOption a_check_namespaces
-        withTagSoup     = hasOption a_tagsoup
-        issueW          = hasOption a_issue_warnings
-        removeWS        = hasOption a_remove_whitespace
-        preserveCmt     = hasOption a_preserve_comment
-        removeNoneXml   = hasOption a_ignore_none_xml_contents
-        hasOption n     = optionIsSet n options
 
 -- ------------------------------------------------------------
 
 -- |
 -- the arrow version of 'readDocument', the arrow input is the source URI
 
-readFromDocument        :: Attributes -> IOStateArrow s String XmlTree
-readFromDocument userOptions
-    = applyA ( arr $ readDocument userOptions )
+readFromDocument        :: SysConfigList -> IOStateArrow s String XmlTree
+readFromDocument config	= applyA ( arr $ readDocument config )
 
 -- ------------------------------------------------------------
 
@@ -373,18 +348,19 @@
 --
 -- Default encoding: No encoding is done, the String argument is taken as Unicode string
 
-readString      :: Attributes -> String -> IOStateArrow s b XmlTree
-readString userOptions content
-    = readDocument ( (a_encoding, unicodeString) : userOptions ) (stringProtocol ++ content)
+readString      	:: SysConfigList -> String -> IOStateArrow s b XmlTree
+readString config content
+    			= readDocument (withInputEncoding unicodeString : config)
+                          (stringProtocol ++ content)
 
 -- ------------------------------------------------------------
 
 -- |
 -- the arrow version of 'readString', the arrow input is the source URI
 
-readFromString  :: Attributes -> IOStateArrow s String XmlTree
-readFromString userOptions
-    = applyA ( arr $ readString userOptions )
+readFromString  	:: SysConfigList -> IOStateArrow s String XmlTree
+readFromString config
+    			= applyA ( arr $ readString config )
 
 -- ------------------------------------------------------------
 
diff --git a/src/Text/XML/HXT/Arrow/WriteDocument.hs b/src/Text/XML/HXT/Arrow/WriteDocument.hs
--- a/src/Text/XML/HXT/Arrow/WriteDocument.hs
+++ b/src/Text/XML/HXT/Arrow/WriteDocument.hs
@@ -17,6 +17,7 @@
 
 module Text.XML.HXT.Arrow.WriteDocument
     ( writeDocument
+    , writeDocument'
     , writeDocumentToString
     , prepareContents
     )
@@ -28,9 +29,13 @@
 import Control.Arrow.ArrowTree
 
 import Text.XML.HXT.DOM.Interface
-import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
 
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.Arrow.XmlState
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
+import Text.XML.HXT.Arrow.XmlState.RunIOStateArrow
+                                                ( initialSysState
+                                                )
 import Text.XML.HXT.Arrow.Edit                  ( escapeHtmlDoc
                                                 , escapeXmlDoc
                                                 , haskellRepOfXmlDoc
@@ -40,13 +45,13 @@
                                                 , removeDocWhiteSpace
                                                 , treeRepOfXmlDoc
                                                 )
-
 import Text.XML.HXT.Arrow.DocumentOutput        ( putXmlDocument
                                                 , encodeDocument
                                                 , encodeDocument'
                                                 )
 
 -- ------------------------------------------------------------
+--
 
 {- |
 the main filter for writing documents
@@ -57,38 +62,39 @@
 
 if @ destination @ is the empty string or \"-\", stdout is used as output device
 
-available options are
+for available options see 'Text.XML.HXT.Arrow.XmlState.SystemConfig'
 
-* 'a_indent' : indent document for readability, (default: no indentation)
 
-- 'a_remove_whitespace' : remove all redundant whitespace for shorten text (default: no removal)
-
-- 'a_output_encoding' : encoding of document, default is 'a_encoding' or 'utf8'
-
-- 'a_output_xml' : (default) issue XML: quote special XML chars \>,\<,\",\',& where neccessary
+- @withOutputXML@ :
+ (default) issue XML: quote special XML chars \>,\<,\",\',& where neccessary
                    add XML processing instruction
-                   and encode document with respect to 'a_output_encoding',
-                   if explicitly switched of, the plain text is issued, this is useful
-                   for non XML output, e.g. generated Haskell code, LaTex, Java, ...
+                   and encode document with respect to output encoding,
 
-- 'a_output_html' : issue XHTML: quote alle XML chars, use HTML entity refs or char refs for none ASCII chars
+- @withOutputHTML@ :
+ issue HTML: translate all special XML chars and all HTML chars with a corresponding entity reference
+ into entity references. Do not generate empty elements, e.g. @<script .../>@ for HTML elements, that are allowed
+ to contain a none empty body. Result is for the example is @<script ...></script>@.
+ The short form introduces trouble in various browsers.
 
-- 'a_no_empty_elements' : do not write the short form \<name .../\> for empty elements. When 'a_output_html' is set,
-                          the always empty HTML elements are still written in short form, but not the others, as e.g. the script element.
-                          Empty script elements, like \<script href=\"...\"/\>, are always a problem for firefox and others.
-                          When XML output is generated with this option, all empty elements are written in the long form.
+- @withOutputXHTML@ :
+ same as @withOutputHTML@, but all none ASCII chars are substituted by char references.
 
-- 'a_no_empty_elem_for' : do not generate empty elements for the element names given in the comma separated list of this option value.
-                          This option overwrites the above described 'a_no_empty_elements' option
+- @withOutputPLAIN@ :
+ Do not substitute any chars. This is useful when generating something else than XML/HTML, e.g. Haskell source code.
 
-- 'a_add_default_dtd' : if the document to be written was build by reading another document containing a Document Type Declaration,
-                        this DTD is inserted into the output document (default: no insert)
+- @withXmlPi yes/no@ :
+ Add a @<?xml version=... encoding=... ?>@ processing instruction to the beginning of the document.
+ Default is yes.
 
-- 'a_no_xml_pi' : suppress generation of \<?xml ... ?\> processing instruction
+- @withAddDefaultDTD@ :
+  if the document to be written was build by reading another document containing a Document Type Declaration,
+  this DTD is inserted into the output document (default: no insert)
 
-- 'a_show_tree' : show tree representation of document (for debugging)
+- @withShowTree yes/no@ :
+  show DOM tree representation of document (for debugging)
 
-- 'a_show_haskell' : show Haskell representaion of document (for debugging)
+- @withShowHaskell yes/no@ :
+  show Haskell representaion of document (for debugging)
 
  a minimal main program for copying a document
  has the following structure:
@@ -96,7 +102,7 @@
 > module Main
 > where
 >
-> import Text.XML.HXT.Arrow
+> import Text.XML.HXT.Core
 >
 > main        :: IO ()
 > main
@@ -107,46 +113,66 @@
 >            )
 >       return ()
 
-an example for copying a document to standard output with tracing and evaluation of
+an example for copying a document from the web to standard output with global trace level 1, input trace level 2,
+output encoding isoLatin1,
+and evaluation of
 error code is:
 
 > module Main
 > where
 >
-> import Text.XML.HXT.Arrow
+> import Text.XML.HXT.Core
+> import Text.XML.HXT.Curl
+> -- or
+> -- import Text.XML.HXT.HTTP
 > import System.Exit
 >
 > main        :: IO ()
 > main
 >     = do
->       [rc] <- runX ( readDocument  [ (a_trace, "1")
->                                    ] "hello.xml"
->                      >>>
->                      writeDocument [ (a_output_encoding, isoLatin1)
->                                    ] "-"        -- output to stdout
->                      >>>
->                      getErrStatus
->                    )
+>       [rc] <- runX
+>               ( configSysVars [ withTrace 1          -- set the defaults for all read-,
+>                               , withCurl []          -- write- and other operations
+>                                 -- or withHTTP []
+>                               ]
+>                 >>>
+>                 readDocument  [ withTrace     2      -- use these additional
+>                               , withParseHTML yes    -- options only for this read
+>                               ]
+>                               "http://www.haskell.org/"
+>                 >>>
+>                 writeDocument [ withOutputEncoding isoLatin1
+>                               ]
+>                               ""                     -- output to stdout
+>                 >>>
+>                 getErrStatus
+>               )
 >       exitWith ( if rc >= c_err
 >                  then ExitFailure 1
 >                  else ExitSuccess
 >                )
 -}
 
-writeDocument   :: Attributes -> String -> IOStateArrow s XmlTree XmlTree
-writeDocument userOptions dst
-    = perform ( traceMsg 1 ("writeDocument: destination is " ++ show dst)
-                >>>
-                prepareContents userOptions encodeDocument
-                >>>
-                putXmlDocument textMode dst
-                >>>
-                traceMsg 1 "writeDocument: finished"
-              )
+writeDocument   	:: SysConfigList -> String -> IOStateArrow s XmlTree XmlTree
+writeDocument config dst
+    = localSysEnv
+      $
+      configSysVars config
+      >>>
+      perform ( (flip writeDocument') dst $< getSysVar theTextMode )
+
+writeDocument'  	:: Bool -> String -> IOStateArrow s XmlTree XmlTree
+writeDocument' textMode dst
+    = ( traceMsg 1 ("writeDocument: destination is " ++ show dst)
+        >>>
+        ( (flip prepareContents) encodeDocument $< getSysVar idS )
+        >>>
+        putXmlDocument textMode dst
+        >>>
+        traceMsg 1 "writeDocument: finished"
+      )
       `when`
       documentStatusOk
-    where
-    textMode    = optionIsSet a_text_mode userOptions
 
 -- ------------------------------------------------------------
 
@@ -154,7 +180,7 @@
 -- Convert a document into a string. Formating is done the same way
 -- and with the same options as in 'writeDocument'. Default output encoding is
 -- no encoding, that means the result is a normal unicode encode haskell string.
--- The default may be overwritten with the 'Text.XML.HXT.XmlKeywords.a_output_encoding' option.
+-- The default may be overwritten with the 'Text.XML.HXT.Arrow.XmlState.SystemConfig.withOutputEncoding' option.
 -- The XML PI can be suppressed by the 'Text.XML.HXT.XmlKeywords.a_no_xml_pi' option.
 --
 -- This arrow fails, when the encoding scheme is not supported.
@@ -162,13 +188,13 @@
 -- The XML PI is suppressed, if not explicitly turned on with an
 -- option @ (a_no_xml_pi, v_0) @
 
-writeDocumentToString   :: ArrowXml a => Attributes  -> a XmlTree String
-writeDocumentToString userOptions
-    = prepareContents ( addEntries
-                        userOptions
-                        [ (a_output_encoding, unicodeString)
-                        , (a_no_xml_pi, v_1)
-                        ]
+writeDocumentToString   :: ArrowXml a => SysConfigList  -> a XmlTree String
+writeDocumentToString config
+    = prepareContents ( foldr (>>>) id (withOutputEncoding unicodeString :
+                                        withXmlPi          no            :
+                                        config
+                                       )
+                        $ initialSysState
                       ) encodeDocument'
       >>>
       xshow getChildren
@@ -178,70 +204,59 @@
 -- |
 -- indent and format output
 
-prepareContents :: ArrowXml a => Attributes -> (Bool -> String -> a XmlTree XmlTree) -> a XmlTree XmlTree
-prepareContents userOptions encodeDoc
+prepareContents :: ArrowXml a => XIOSysState -> (Bool -> String -> a XmlTree XmlTree) -> a XmlTree XmlTree
+prepareContents config encodeDoc
     = indent
       >>>
       addDtd
       >>>
       format
     where
-    formatEmptyElems
-        | not (null noEmptyElemFor)     = preventEmptyElements noEmptyElemFor
-        | hasOption a_no_empty_elements
-          ||
-          hasOption a_output_xhtml      = preventEmptyElements []
-        | otherwise                     = const this
+    indent'	 = getS theIndent      config
+    removeWS'    = getS theRemoveWS    config
+    showTree'    = getS theShowTree    config
+    showHaskell' = getS theShowHaskell config
+    outHtml'     = getS theOutputFmt   config ==  HTMLoutput
+    outXhtml'    = getS theOutputFmt   config == XHTMLoutput
+    outXml'      = getS theOutputFmt   config ==   XMLoutput
+    noPi'        = not $ getS theXmlPi       config
+    noEEsFor'    = getS theNoEmptyElemFor  config
+    addDDTD'     = getS theAddDefaultDTD   config
+    outEnc'      = getS theOutputEncoding  config
+
     addDtd
-        | hasOption a_add_default_dtd   = addDefaultDTDecl
+        | addDDTD'                      = addDefaultDTDecl
         | otherwise                     = this
     indent
-        | hasOption a_indent            = indentDoc                     -- document indentation
-        | hasOption a_remove_whitespace = removeDocWhiteSpace           -- remove all whitespace between tags
+        | indent'                       = indentDoc                     -- document indentation
+        | removeWS'                     = removeDocWhiteSpace           -- remove all whitespace between tags
         | otherwise                     = this
 
     format
-        | hasOption a_show_tree         = treeRepOfXmlDoc
-        | hasOption a_show_haskell      = haskellRepOfXmlDoc
-        | hasOption a_output_html       = formatEmptyElems True
+        | showTree'                     = treeRepOfXmlDoc
+        | showHaskell'                  = haskellRepOfXmlDoc
+        | outHtml'                      = preventEmptyElements noEEsFor' True
                                           >>>
                                           escapeHtmlDoc                 -- escape al XML and HTML chars >= 128
                                           >>>
                                           encodeDoc                     -- convert doc into text with respect to output encoding with ASCII as default
-                                            suppressXmlPi ( lookupDef usAscii a_output_encoding options )
-        | hasOption a_output_xml        = formatEmptyElems (hasOption a_output_xhtml)
+                                            noPi' ( if null outEnc' then usAscii else outEnc' )
+
+        | outXhtml'                     = preventEmptyElements noEEsFor' True
                                           >>>
                                           escapeXmlDoc                  -- escape lt, gt, amp, quot,
                                           >>>
                                           encodeDoc                     -- convert doc into text with respect to output encoding
-                                            suppressXmlPi ( lookupDef "" a_output_encoding options )
+                                            noPi' outEnc'
+        | outXml'                       = ( if null noEEsFor'
+                                            then this
+                                            else preventEmptyElements noEEsFor' False
+                                          )
+                                          >>>
+                                          escapeXmlDoc                  -- escape lt, gt, amp, quot,
+                                          >>>
+                                          encodeDoc                     -- convert doc into text with respect to output encoding
+                                            noPi' outEnc'
         | otherwise                     = this
-
-    suppressXmlPi                                                       -- remove <?xml ... ?> when set
-        = hasOption a_no_xml_pi
-
-    noEmptyElemFor
-        = words
-          . map (\ c -> if c == ',' then ' ' else c)
-          . lookup1 a_no_empty_elem_for
-          $ options
-
-    hasOption n
-        = optionIsSet n options
-
-    options = addEntries
-              userOptions
-              [ ( a_indent,             v_0 )
-              , ( a_remove_whitespace,  v_0 )
-              , ( a_output_xml,         v_1 )
-              , ( a_show_tree,          v_0 )
-              , ( a_show_haskell,       v_0 )
-              , ( a_output_html,        v_0 )
-              , ( a_output_xhtml,       v_0 )
-              , ( a_no_xml_pi,          v_0 )
-              , ( a_no_empty_elements,  v_0 )
-              , ( a_no_empty_elem_for,  ""  )
-              , ( a_add_default_dtd,    v_0 )
-              ]
 
 -- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/XmlArrow.hs b/src/Text/XML/HXT/Arrow/XmlArrow.hs
--- a/src/Text/XML/HXT/Arrow/XmlArrow.hs
+++ b/src/Text/XML/HXT/Arrow/XmlArrow.hs
@@ -31,11 +31,10 @@
 import           Control.Arrow.IOListArrow
 import           Control.Arrow.IOStateListArrow
 
+import           Data.Char.Properties.XMLCharProps        ( isXmlSpaceChar )
 import           Data.Maybe
 
 import           Text.XML.HXT.DOM.Interface
-import           Text.XML.HXT.DOM.Unicode       ( isXmlSpaceChar
-                                                )
 import qualified Text.XML.HXT.DOM.XmlNode as XN
 import qualified Text.XML.HXT.DOM.ShowXml as XS
 
diff --git a/src/Text/XML/HXT/Arrow/XmlIOStateArrow.hs b/src/Text/XML/HXT/Arrow/XmlIOStateArrow.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/Arrow/XmlIOStateArrow.hs
+++ /dev/null
@@ -1,989 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.Arrow.XmlIOStateArrow
-   Copyright  : Copyright (C) 2010 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : stable
-   Portability: portable
-
-   the basic state arrows for XML processing
-
-   A state is needed for global processing options,
-   like encoding options, document base URI, trace levels
-   and error message handling
-
-   The state is separated into a user defined state
-   and a system state. The system state contains variables
-   for error message handling, for tracing, for the document base
-   for accessing XML documents with relative references, e.g. DTDs,
-   and a global key value store. This assoc list has strings as keys
-   and lists of XmlTrees as values. It is used to store arbitrary
-   XML and text values, e.g. user defined global options.
-
-   The user defined part of the store is in the default case empty, defined as ().
-   It can be extended with an arbitray data type
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.Arrow.XmlIOStateArrow
-    ( -- * Data Types
-      XIOState(..),
-      XIOSysState(..),
-      IOStateArrow,
-      IOSArrow,
-
-      -- * Running Arrows
-      initialState,
-      initialSysState,
-      runX,
-
-      -- * User State Manipulation
-      getUserState,
-      setUserState,
-      changeUserState,
-      withExtendedUserState,
-      withOtherUserState,
-
-      -- * Global System State Access
-      getSysParam,
-      changeSysParam,
-
-      setParamList,
-      setParam,
-      unsetParam,
-      getParam,
-      getAllParams,
-      getAllParamsString,
-      setParamString,
-      getParamString,
-      setParamInt,
-      getParamInt,
-
-      -- * Error Message Handling
-      clearErrStatus,
-      setErrStatus,
-      getErrStatus,
-      setErrMsgStatus,
-      setErrorMsgHandler,
-
-      errorMsgStderr,
-      errorMsgCollect,
-      errorMsgStderrAndCollect,
-      errorMsgIgnore,
-
-      getErrorMessages,
-
-      filterErrorMsg,
-      issueWarn,
-      issueErr,
-      issueFatal,
-      setDocumentStatus,
-      setDocumentStatusFromSystemState,
-      documentStatusOk,
-
-      -- * Document Base
-      setBaseURI,
-      getBaseURI,
-      changeBaseURI,
-      setDefaultBaseURI,
-      getDefaultBaseURI,
-      runInLocalURIContext,
-
-      -- * Tracing
-      setTraceLevel,
-      getTraceLevel,
-      withTraceLevel,
-      setTraceCmd,
-      getTraceCmd,
-      trace,
-      traceMsg,
-      traceValue,
-      traceString,
-      traceSource,
-      traceTree,
-      traceDoc,
-      traceState,
-
-      -- * URI Manipulation
-      expandURIString,
-      expandURI,
-      mkAbsURI,
-
-      getFragmentFromURI,
-      getPathFromURI,
-      getPortFromURI,
-      getQueryFromURI,
-      getRegNameFromURI,
-      getSchemeFromURI,
-      getUserInfoFromURI,
-
-      -- * Mime Type Handling
-      setMimeTypeTable,
-      setMimeTypeTableFromFile
-      )
-where
-
-import Control.Arrow                            -- arrow classes
-import Control.Arrow.ArrowList
-import Control.Arrow.ArrowIf
-import Control.Arrow.ArrowTree
-import Control.Arrow.ArrowIO
-import Control.Arrow.IOStateListArrow
-
-import Control.Monad                    ( mzero
-                                        , mplus )
-import Control.DeepSeq
-
-import Text.XML.HXT.DOM.Interface
-import Text.XML.HXT.Arrow.XmlArrow
-
-import Text.XML.HXT.Arrow.Edit          ( addHeadlineToXmlDoc
-                                        , treeRepOfXmlDoc
-                                        , indentDoc
-                                        )
-
-import Data.Maybe
-
-import Network.URI                      ( URI
-                                        , escapeURIChar
-                                        , isUnescapedInURI
-                                        , nonStrictRelativeTo
-                                        , parseURIReference
-                                        , uriAuthority
-                                        , uriFragment
-                                        , uriPath
-                                        , uriPort
-                                        , uriQuery
-                                        , uriRegName
-                                        , uriScheme
-                                        , uriUserInfo
-                                        )
-
-import System.IO                        ( hPutStrLn
-                                        , hFlush
-                                        , stderr
-                                        )
-
-import System.Directory                 ( getCurrentDirectory )
-
--- ------------------------------------------------------------
-{- $datatypes -}
-
-
--- |
--- predefined system state data type with all components for the
--- system functions, like trace, error handling, ...
-
-data XIOSysState        = XIOSys  { xio_trace                   :: ! Int
-                                  , xio_traceCmd                ::   Int -> String -> IO ()
-                                  , xio_errorStatus             :: ! Int
-                                  , xio_errorModule             :: ! String
-                                  , xio_errorMsgHandler         ::   String -> IO ()
-                                  , xio_errorMsgCollect         :: ! Bool
-                                  , xio_errorMsgList            :: ! XmlTrees
-                                  , xio_baseURI                 :: ! String
-                                  , xio_defaultBaseURI          :: ! String
-                                  , xio_attrList                :: ! (AssocList String XmlTrees)
-                                  , xio_mimeTypes               ::   MimeTypeTable
-                                  }
-
-instance NFData XIOSysState where
-    rnf (XIOSys tr _trc es em _emh emc eml bu du al _mt)
-        = rnf tr `seq` rnf es `seq` rnf em `seq` rnf emc `seq` rnf eml `seq` rnf bu `seq` rnf du `seq` rnf al
-
--- |
--- state datatype consists of a system state and a user state
--- the user state is not fixed
-
-data XIOState us        = XIOState { xio_sysState               :: ! XIOSysState
-                                   , xio_userState              :: ! us
-                                   }
-
-instance (NFData us) => NFData (XIOState us) where
-    rnf (XIOState sys usr)      = rnf sys `seq` rnf usr
-
--- |
--- The arrow type for stateful arrows
-
-type IOStateArrow s b c = IOSLA (XIOState s) b c
-
--- |
--- The arrow for stateful arrows with no user defined state
-
-type IOSArrow b c       = IOStateArrow () b c
-
--- ------------------------------------------------------------
-
-
--- | the default global state, used as initial state when running an 'IOSArrow' with 'runIOSLA' or
--- 'runX'
-
-initialState    :: us -> XIOState us
-initialState s  = XIOState { xio_sysState       = initialSysState
-                           , xio_userState      = s
-                           }
-
-initialSysState :: XIOSysState
-initialSysState = XIOSys { xio_trace            = 0
-                         , xio_traceCmd         = traceOutputToStderr
-                         , xio_errorStatus      = c_ok
-                         , xio_errorModule      = ""
-                         , xio_errorMsgHandler  = hPutStrLn stderr
-                         , xio_errorMsgCollect  = False
-                         , xio_errorMsgList     = []
-                         , xio_baseURI          = ""
-                         , xio_defaultBaseURI   = ""
-                         , xio_attrList         = []
-                         , xio_mimeTypes        = defaultMimeTypeTable
-                         }
-
--- ------------------------------------------------------------
-
--- |
--- apply an 'IOSArrow' to an empty root node with 'initialState' () as initial state
---
--- the main entry point for running a state arrow with IO
---
--- when running @ runX f@ an empty XML root node is applied to @f@.
--- usually @f@ will start with a constant arrow (ignoring the input), e.g. a 'Text.XML.HXT.Arrow.ReadDocument.readDocument' arrow.
---
--- for usage see examples with 'Text.XML.HXT.Arrow.WriteDocument.writeDocument'
---
--- if input has to be feed into the arrow use 'Control.Arrow.IOStateListArrow.runIOSLA' like in @ runIOSLA f emptyX inputDoc @
-
-runX            :: IOSArrow XmlTree c -> IO [c]
-runX            = runXIOState (initialState ())
-
-runXIOState     :: XIOState s -> IOStateArrow s XmlTree c -> IO [c]
-runXIOState s0 f
-    = do
-      (_finalState, res) <- runIOSLA (emptyRoot >>> f) s0 undefined
-      return res
-    where
-    emptyRoot    = root [] []
-
--- ------------------------------------------------------------
-
-{- user state -}
-
--- | read the user defined part of the state
-
-getUserState    :: IOStateArrow s b s
-getUserState
-    = IOSLA $ \ s _ ->
-      return (s, [xio_userState s])
-
--- | change the user defined part of the state
-
-changeUserState         :: (b -> s -> s) -> IOStateArrow s b b
-changeUserState cf
-    = IOSLA $ \ s v ->
-      let s' = s { xio_userState = cf v (xio_userState s) }
-      in return (s', [v])
-
--- | set the user defined part of the state
-
-setUserState            :: IOStateArrow s s s
-setUserState
-    = changeUserState const
-
--- | extend user state
---
--- Run an arrow with an extended user state component, The old component
--- is stored together with a new one in a pair, the arrow is executed with this
--- extended state, and the augmented state component is removed form the state
--- when the arrow has finished its execution
-
-withExtendedUserState   :: s1 -> IOStateArrow (s1, s0) b c -> IOStateArrow s0 b c
-withExtendedUserState initS1 f
-    = IOSLA $ \ s0 x ->
-      do
-      ~(finalS, res) <- runIOSLA f ( XIOState { xio_sysState  =          xio_sysState  s0
-                                              , xio_userState = (initS1, xio_userState s0)
-                                              }
-                                   ) x
-      return ( XIOState { xio_sysState  =      xio_sysState  finalS
-                        , xio_userState = snd (xio_userState finalS)
-                        }
-             , res
-             )
-
--- | change the type of user state
---
--- This conversion is useful, when running a state arrow with another
--- structure of the user state, e.g. with () when executing some IO arrows
-
-withOtherUserState      :: s1 -> IOStateArrow s1 b c -> IOStateArrow s0 b c
-withOtherUserState s1 f
-    = IOSLA $ \ s x ->
-      do
-      (s', res) <- runIOSLA f ( XIOState { xio_sysState  = xio_sysState s
-                                         , xio_userState = s1
-                                         }
-                              ) x
-      return ( XIOState { xio_sysState  = xio_sysState  s'
-                        , xio_userState = xio_userState s
-                        }
-             , res
-             )
-
--- ------------------------------------------------------------
-
-{- $system state params -}
-
-getSysParam     :: (XIOSysState -> c) -> IOStateArrow s b c
-getSysParam f
-    = IOSLA $ \ s _x ->
-      return (s, (:[]) . f . xio_sysState $ s)
-
-changeSysParam          :: (b -> XIOSysState -> XIOSysState) -> IOStateArrow s b b
-changeSysParam cf
-    = ( IOSLA $ \ s v ->
-        let s' = changeSysState (cf v) s
-        in return (s', [v])
-      )
-    where
-    changeSysState css s = s { xio_sysState = css (xio_sysState s) }
-
--- | store a single XML tree in global state under a given attribute name
-
-setParam        :: String -> IOStateArrow s XmlTree XmlTree
-setParam n
-    = (:[]) ^>> setParamList n
-
--- | store a list of XML trees in global system state under a given attribute name
-
-setParamList    :: String -> IOStateArrow s XmlTrees XmlTree
-setParamList n
-    = changeSysParam addE
-      >>>
-      arrL id
-    where
-    addE x s = s { xio_attrList = addEntry n x (xio_attrList s) }
-
--- | remove an entry in global state, arrow input remains unchanged
-
-unsetParam      :: String -> IOStateArrow s b b
-unsetParam n
-    = changeSysParam delE
-    where
-    delE _ s = s { xio_attrList = delEntry n (xio_attrList s) }
-
--- | read an attribute value from global state
-
-getParam        :: String -> IOStateArrow s b XmlTree
-getParam n
-    = getAllParams
-      >>>
-      arrL (lookup1 n)
-
--- | read all attributes from global state
-
-getAllParams    :: IOStateArrow s b (AssocList String XmlTrees)
-getAllParams
-    = getSysParam xio_attrList
-
--- | read all attributes from global state
--- and convert the values to strings
-
-getAllParamsString      :: IOStateArrow s b (AssocList String String)
-getAllParamsString
-    = getAllParams
-      >>>
-      listA ( unlistA
-              >>>
-              second (xshow unlistA)
-            )
-
-setParamString  :: String -> String -> IOStateArrow s b b
-setParamString n v
-    = perform ( txt v
-                >>>
-                setParam n
-              )
-
--- | read a string value from global state,
--- if parameter not set \"\" is returned
-
-getParamString  :: String -> IOStateArrow s b String
-getParamString n
-    = xshow (getParam n)
-
--- | store an int value in global state
-
-setParamInt     :: String -> Int -> IOStateArrow s b b
-setParamInt n v
-    = setParamString n (show v)
-
--- | read an int value from global state
---
--- > getParamInt 0 myIntAttr
-
-getParamInt     :: Int -> String -> IOStateArrow s b Int
-getParamInt def n
-    = getParamString n
-      >>^
-      (\ x -> if null x then def else read x)
-
--- ------------------------------------------------------------
-
--- | reset global error variable
-
-changeErrorStatus       :: (Int -> Int -> Int) -> IOStateArrow s Int Int
-changeErrorStatus f
-    = changeSysParam (\ l s -> s { xio_errorStatus = f l (xio_errorStatus s) })
-
-clearErrStatus          :: IOStateArrow s b b
-clearErrStatus
-    = perform (constA 0 >>> changeErrorStatus min)
-
--- | set global error variable
-
-setErrStatus            :: IOStateArrow s Int Int
-setErrStatus
-    = changeErrorStatus max
-
--- | read current global error status
-
-getErrStatus            :: IOStateArrow s XmlTree Int
-getErrStatus
-    = getSysParam xio_errorStatus
-
--- | raise the global error status level to that of the input tree
-
-setErrMsgStatus :: IOStateArrow s XmlTree XmlTree
-setErrMsgStatus
-    = perform ( getErrorLevel
-                >>>
-                setErrStatus
-              )
-
--- | set the error message handler and the flag for collecting the errors
-
-setErrorMsgHandler      :: Bool -> (String -> IO ()) -> IOStateArrow s b b
-setErrorMsgHandler c f
-    = changeSysParam cf
-    where
-    cf _ s = s { xio_errorMsgHandler = f
-               , xio_errorMsgCollect = c }
-
--- | error message handler for output to stderr
-
-sysErrorMsg             :: IOStateArrow s XmlTree XmlTree
-sysErrorMsg
-    = perform ( getErrorLevel &&& getErrorMsg
-                >>>
-                arr formatErrorMsg
-                >>>
-                ( IOSLA $ \ s e ->
-                  do
-                  (xio_errorMsgHandler . xio_sysState $ s) e
-                  return (s, undefined)
-                )
-              )
-    where
-    formatErrorMsg (level, msg) = "\n" ++ errClass level ++ ": " ++ msg
-    errClass l
-        = fromMaybe "fatal error" . lookup l $ msgList
-          where
-          msgList       = [ (c_ok,      "no error")
-                          , (c_warn,    "warning")
-                          , (c_err,     "error")
-                          , (c_fatal,   "fatal error")
-                          ]
-
-
--- | the default error message handler: error output to stderr
-
-errorMsgStderr          :: IOStateArrow s b b
-errorMsgStderr          = setErrorMsgHandler False (hPutStrLn stderr)
-
--- | error message handler for collecting errors
-
-errorMsgCollect         :: IOStateArrow s b b
-errorMsgCollect         = setErrorMsgHandler True (const $ return ())
-
--- | error message handler for output to stderr and collecting
-
-errorMsgStderrAndCollect        :: IOStateArrow s b b
-errorMsgStderrAndCollect        = setErrorMsgHandler True (hPutStrLn stderr)
-
--- | error message handler for ignoring errors
-
-errorMsgIgnore          :: IOStateArrow s b b
-errorMsgIgnore          = setErrorMsgHandler False (const $ return ())
-
--- |
--- if error messages are collected by the error handler for
--- processing these messages by the calling application,
--- this arrow reads the stored messages and clears the error message store
-
-getErrorMessages        :: IOStateArrow s b XmlTree
-getErrorMessages
-    = getSysParam (reverse . xio_errorMsgList)          -- reverse the list of errors
-      >>>
-      clearErrorMsgList                                 -- clear the error list in the system state
-      >>>
-      arrL id
-
-clearErrorMsgList       :: IOStateArrow s b b
-clearErrorMsgList
-    = changeSysParam (\ _ s -> s { xio_errorMsgList = [] } )
-
-addToErrorMsgList       :: IOStateArrow s XmlTree XmlTree
-addToErrorMsgList
-    = changeSysParam cf
-    where
-    cf t s = if xio_errorMsgCollect s
-             then s { xio_errorMsgList = t : xio_errorMsgList s }
-             else s
-
--- ------------------------------------------------------------
-
--- |
--- filter error messages from input trees and issue errors
-
-filterErrorMsg          :: IOStateArrow s XmlTree XmlTree
-filterErrorMsg
-    = ( setErrMsgStatus
-        >>>
-        sysErrorMsg
-        >>>
-        addToErrorMsgList
-        >>>
-        none
-      )
-      `when`
-      isError
-
--- | generate a warnig message
-
-issueWarn               :: String -> IOStateArrow s b b
-issueWarn msg           = perform (warn msg  >>> filterErrorMsg)
-
--- | generate an error message
-issueErr                :: String -> IOStateArrow s b b
-issueErr msg            = perform (err msg   >>> filterErrorMsg)
-
--- | generate a fatal error message, e.g. document not found
-
-issueFatal              :: String -> IOStateArrow s b b
-issueFatal msg          = perform (fatal msg >>> filterErrorMsg)
-
--- |
--- add the error level and the module where the error occured
--- to the attributes of a document root node and remove the children when level is greater or equal to 'c_err'.
--- called by 'setDocumentStatusFromSystemState' when the system state indicates an error
-
-setDocumentStatus       :: Int -> String -> IOStateArrow s XmlTree XmlTree
-setDocumentStatus level msg
-    = ( addAttrl ( sattr a_status (show level)
-                   <+>
-                   sattr a_module msg
-                 )
-        >>>
-        ( if level >= c_err
-          then setChildren []
-          else this
-        )
-      )
-      `when`
-      isRoot
-
--- |
--- check whether the error level attribute in the system state
--- is set to error, in this case the children of the document root are
--- removed and the module name where the error occured and the error level are added as attributes with 'setDocumentStatus'
--- else nothing is changed
-
-setDocumentStatusFromSystemState                :: String -> IOStateArrow s XmlTree XmlTree
-setDocumentStatusFromSystemState msg
-    = setStatus $< getErrStatus
-    where
-    setStatus level
-        | level <= c_warn       = this
-        | otherwise             = setDocumentStatus level msg
-
-
--- |
--- check whether tree is a document root and the status attribute has a value less than 'c_err'
-
-documentStatusOk        :: ArrowXml a => a XmlTree XmlTree
-documentStatusOk
-    = isRoot
-      >>>
-      ( (getAttrValue a_status
-         >>>
-         isA (\ v -> null v || ((read v)::Int) <= c_warn)
-        )
-        `guards`
-        this
-      )
-
--- ------------------------------------------------------------
-
--- | set the base URI of a document, used e.g. for reading includes, e.g. external entities,
--- the input must be an absolute URI
-
-setBaseURI              :: IOStateArrow s String String
-setBaseURI
-    = changeSysParam (\ b s -> s { xio_baseURI = b } )
-      >>>
-      traceValue 2 (("setBaseURI: new base URI is " ++) . show)
-
--- | read the base URI from the globale state
-
-getBaseURI              :: IOStateArrow s b String
-getBaseURI
-    = getSysParam xio_baseURI
-      >>>
-      ( ( getDefaultBaseURI
-          >>>
-          setBaseURI
-          >>>
-          getBaseURI
-        )
-        `when`
-        isA null                                -- set and get it, if not yet done
-      )
-
--- | change the base URI with a possibly relative URI, can be used for
--- evaluating the xml:base attribute. Returns the new absolute base URI.
--- Fails, if input is not parsable with parseURIReference
---
--- see also: 'setBaseURI', 'mkAbsURI'
-
-changeBaseURI           :: IOStateArrow s String String
-changeBaseURI
-    = mkAbsURI
-      >>>
-      setBaseURI
-
--- | set the default base URI, if parameter is null, the system base (@ file:\/\/\/\<cwd\>\/ @) is used,
--- else the parameter, must be called before any document is read
-
-setDefaultBaseURI       :: String -> IOStateArrow s b String
-setDefaultBaseURI base
-    = ( if null base
-        then arrIO getDir
-        else constA base
-      )
-      >>>
-      changeSysParam (\ b s -> s { xio_defaultBaseURI = b } )
-      >>>
-      traceValue 2 (("setDefaultBaseURI: new default base URI is " ++) . show)
-    where
-    getDir _ = do
-               cwd <- getCurrentDirectory
-               return ("file://" ++ normalize cwd ++ "/")
-
-    -- under Windows getCurrentDirectory returns something like: "c:\path\to\file"
-    -- backslaches are not allowed in URIs and paths must start with a /
-    -- so this is transformed into "/c:/path/to/file"
-
-    normalize wd'@(d : ':' : _)
-        | d `elem` ['A'..'Z'] || d `elem` ['a'..'z']
-            = '/' : concatMap win32ToUriChar wd'
-    normalize wd'
-        = concatMap escapeNonUriChar wd'
-
-    win32ToUriChar '\\' = "/"
-    win32ToUriChar c    = escapeNonUriChar c
-
-    escapeNonUriChar c  = escapeURIChar isUnescapedInURI c   -- from Network.URI
-
-
--- | get the default base URI
-
-getDefaultBaseURI       :: IOStateArrow s b String
-getDefaultBaseURI
-    = getSysParam xio_defaultBaseURI            -- read default uri in system  state
-      >>>
-      ( setDefaultBaseURI ""                    -- set the default uri in system state
-        >>>
-        getDefaultBaseURI ) `when` isA null     -- when uri not yet set
-
--- ------------------------------------------------------------
-
--- | remember base uri, run an arrow and restore the base URI, used with external entity substitution
-
-runInLocalURIContext    :: IOStateArrow s b c -> IOStateArrow s b c
-runInLocalURIContext f
-    = ( getBaseURI &&& this )
-      >>>
-      ( this *** listA f )
-      >>>
-      ( setBaseURI *** this )
-      >>>
-      arrL snd
-
--- ------------------------------------------------------------
-
--- | set the global trace level
-
-setTraceLevel   :: Int -> IOStateArrow s b b
-setTraceLevel l
-    = changeSysParam (\ _ s -> s { xio_trace = l } )
-
--- | read the global trace level
-
-getTraceLevel   :: IOStateArrow s b Int
-getTraceLevel
-    = getSysParam xio_trace
-
--- | set the global trace command. This command does the trace output
-
-setTraceCmd     :: (Int -> String -> IO ()) -> IOStateArrow s b b
-setTraceCmd c
-    = changeSysParam (\ _ s -> s { xio_traceCmd = c } )
-
--- | acces the command for trace output
-
-getTraceCmd     :: IOStateArrow a b (Int -> String -> IO ())
-getTraceCmd
-    = getSysParam xio_traceCmd
-
--- | run an arrow with a given trace level, the old trace level is restored after the arrow execution
-
-withTraceLevel  :: Int -> IOStateArrow s b c -> IOStateArrow s b c
-withTraceLevel level f
-    = ( getTraceLevel       &&& this )
-      >>>
-      ( setTraceLevel level *** listA f )
-      >>>
-      ( restoreTraceLevel   *** this )
-      >>>
-      arrL snd
-    where
-    restoreTraceLevel   :: IOStateArrow s Int Int
-    restoreTraceLevel
-        = setTraceLevel $< this
-
--- | apply a trace arrow and issue message to stderr
-
-trace           :: Int -> IOStateArrow s b String -> IOStateArrow s b b
-trace level trc
-    = perform ( trc
-                >>>
-                ( getTraceCmd &&& this )
-                >>>
-                arrIO (\ (cmd, msg) -> cmd level msg)
-              )
-      `when` ( getTraceLevel
-               >>>
-               isA (>= level)
-             )
-
-traceOutputToStderr     :: Int -> String -> IO ()
-traceOutputToStderr _level msg
-    = do
-      hPutStrLn stderr msg
-      hFlush stderr
-
--- | trace the current value transfered in a sequence of arrows.
---
--- The value is formated by a string conversion function. This is a substitute for
--- the old and less general traceString function
-
-traceValue              :: Int -> (b -> String) -> IOStateArrow s b b
-traceValue level trc
-    = trace level (arr $ (('-' : "- (" ++ show level ++ ") ") ++) . trc)
-
--- | an old alias for 'traceValue'
-
-traceString             :: Int -> (b -> String) -> IOStateArrow s b b
-traceString             = traceValue
-
--- | issue a string message as trace
-
-traceMsg        :: Int -> String -> IOStateArrow s b b
-traceMsg level msg
-    = traceValue level (const msg)
-
--- | issue the source representation of a document if trace level >= 3
---
--- for better readability the source is formated with indentDoc
-
-traceSource     :: IOStateArrow s XmlTree XmlTree
-traceSource
-    = trace 3 $
-      xshow
-      ( choiceA [ isRoot :-> ( indentDoc
-                               >>>
-                               getChildren
-                             )
-                , isElem :-> ( root [] [this]
-                               >>> indentDoc
-                               >>> getChildren
-                               >>> isElem
-                             )
-                , this   :-> this
-                ]
-      )
-
--- | issue the tree representation of a document if trace level >= 4
-traceTree       :: IOStateArrow s XmlTree XmlTree
-traceTree
-    = trace 4 $
-      xshow ( treeRepOfXmlDoc
-              >>>
-              addHeadlineToXmlDoc
-              >>>
-              getChildren
-            )
-
--- | trace a main computation step
--- issue a message when trace level >= 1, issue document source if level >= 3, issue tree when level is >= 4
-
-traceDoc        :: String -> IOStateArrow s XmlTree XmlTree
-traceDoc msg
-    = traceMsg 1 msg
-      >>>
-      traceSource
-      >>>
-      traceTree
-
--- | trace the global state
-
-traceState      :: IOStateArrow s b b
-traceState
-    = perform ( xshow ( (getAllParams >>. concat)
-                        >>>
-                        applyA (arr formatParam)
-                      )
-                >>>
-                traceValue 2 ("global state:\n" ++)
-              )
-      where
-      -- formatParam    :: (String, XmlTrees) -> IOStateArrow s b1 XmlTree
-      formatParam (n, v)
-          = mkelem "param" [sattr "name" n] [arrL (const v)] <+> txt "\n"
-
--- ----------------------------------------------------------
-
--- | parse a URI reference, in case of a failure,
--- try to escape unescaped chars, convert backslashes to slashes for windows paths,
--- and try parsing again
-
-parseURIReference'      :: String -> Maybe URI
-parseURIReference' uri
-    = parseURIReference uri
-      `mplus`
-      ( if unesc
-        then parseURIReference uri'
-        else mzero
-      )
-    where
-    unesc       = not . all isUnescapedInURI $ uri
-
-    escape '\\' = "/"
-    escape c    = escapeURIChar isUnescapedInURI c
-
-    uri'        = concatMap escape uri
-
--- | compute the absolut URI for a given URI and a base URI
-
-expandURIString :: String -> String -> Maybe String
-expandURIString uri base
-    = do
-      base' <- parseURIReference' base
-      uri'  <- parseURIReference' uri
-      abs'  <- nonStrictRelativeTo uri' base'
-      return $ show abs'
-
--- | arrow variant of 'expandURIString', fails if 'expandURIString' returns Nothing
-
-expandURI               :: ArrowXml a => a (String, String) String
-expandURI
-    = arrL (maybeToList . uncurry expandURIString)
-
--- | arrow for expanding an input URI into an absolute URI using global base URI, fails if input is not a legal URI
-
-mkAbsURI                :: IOStateArrow s String String
-mkAbsURI
-    = ( this &&& getBaseURI ) >>> expandURI
-
--- | arrow for selecting the scheme (protocol) of the URI, fails if input is not a legal URI.
---
--- See Network.URI for URI components
-
-getSchemeFromURI        :: ArrowList a => a String String
-getSchemeFromURI        = getPartFromURI scheme
-    where
-    scheme = init . uriScheme
-
--- | arrow for selecting the registered name (host) of the URI, fails if input is not a legal URI
-
-getRegNameFromURI       :: ArrowList a => a String String
-getRegNameFromURI       = getPartFromURI host
-    where
-    host = maybe "" uriRegName . uriAuthority
-
--- | arrow for selecting the port number of the URI without leading \':\', fails if input is not a legal URI
-
-getPortFromURI          :: ArrowList a => a String String
-getPortFromURI          = getPartFromURI port
-    where
-    port = dropWhile (==':') . maybe "" uriPort . uriAuthority
-
--- | arrow for selecting the user info of the URI without trailing \'\@\', fails if input is not a legal URI
-
-getUserInfoFromURI              :: ArrowList a => a String String
-getUserInfoFromURI              = getPartFromURI ui
-    where
-    ui = reverse . dropWhile (=='@') . reverse . maybe "" uriUserInfo . uriAuthority
-
--- | arrow for computing the path component of an URI, fails if input is not a legal URI
-
-getPathFromURI          :: ArrowList a => a String String
-getPathFromURI          = getPartFromURI uriPath
-
--- | arrow for computing the query component of an URI, fails if input is not a legal URI
-
-getQueryFromURI         :: ArrowList a => a String String
-getQueryFromURI         = getPartFromURI uriQuery
-
--- | arrow for computing the fragment component of an URI, fails if input is not a legal URI
-
-getFragmentFromURI      :: ArrowList a => a String String
-getFragmentFromURI      = getPartFromURI uriFragment
-
--- | arrow for computing the path component of an URI, fails if input is not a legal URI
-
-getPartFromURI          :: ArrowList a => (URI -> String) -> a String String
-getPartFromURI sel
-    = arrL (maybeToList . getPart)
-      where
-      getPart s = do
-                  uri <- parseURIReference' s
-                  return (sel uri)
-
--- ------------------------------------------------------------
-
--- | set the table mapping of file extensions to mime types in the system state
---
--- Default table is defined in 'Text.XML.HXT.DOM.MimeTypeDefaults'.
--- This table is used when reading loacl files, (file: protocol) to determine the mime type
-
-setMimeTypeTable        :: MimeTypeTable -> IOStateArrow s b b
-setMimeTypeTable mtt
-    = changeSysParam (\ _ s -> s {xio_mimeTypes = mtt})
-
--- | set the table mapping of file extensions to mime types by an external config file
---
--- The config file must follow the conventions of /etc/mime.types on a debian linux system,
--- that means all empty lines and all lines starting with a # are ignored. The other lines
--- must consist of a mime type followed by a possible empty list of extensions.
--- The list of extenstions and mime types overwrites the default list in the system state
--- of the IOStateArrow
-
-setMimeTypeTableFromFile        :: FilePath -> IOStateArrow s b b
-setMimeTypeTableFromFile file
-    = setMimeTypeTable $< arrIO0 ( readMimeTypeTable file)
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/XmlOptions.hs b/src/Text/XML/HXT/Arrow/XmlOptions.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/XmlOptions.hs
@@ -0,0 +1,242 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.XmlOptions
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   system configuration and common options options
+
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.XmlOptions
+where
+
+import Text.XML.HXT.DOM.Interface
+
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
+import Text.XML.HXT.Arrow.XmlState.SystemConfig
+
+import Data.Maybe
+
+import System.Console.GetOpt
+
+-- ------------------------------------------------------------
+--
+
+-- |
+-- commonly useful options for XML input
+--
+-- can be used for option definition with haskell getopt
+--
+-- defines options: 'a_trace', 'a_proxy', 'a_use_curl', 'a_do_not_use_curl', 'a_options_curl', 'a_encoding',
+-- 'a_issue_errors', 'a_do_not_issue_errors', 'a_parse_html', 'a_parse_by_mimetype', 'a_issue_warnings', 'a_do_not_issue_warnings',
+-- 'a_parse_xml', 'a_validate', 'a_do_not_validate', 'a_canonicalize', 'a_do_not_canonicalize',
+--- 'a_preserve_comment', 'a_do_not_preserve_comment', 'a_check_namespaces', 'a_do_not_check_namespaces',
+-- 'a_remove_whitespace', 'a_do_not_remove_whitespace'
+
+inputOptions    :: [OptDescr SysConfig]
+inputOptions
+    = [ Option "t"      [a_trace]                       (OptArg trc "LEVEL")                    "trace level (0-4), default 1"
+      , Option "p"      [a_proxy]                       (ReqArg  withProxy            "PROXY")  "proxy for http access (e.g. \"www-cache:3128\")"
+      , Option ""       [a_redirect]                    (NoArg  (withRedirect           True))  "automatically follow redirected URIs"
+      , Option ""       [a_no_redirect]                 (NoArg  (withRedirect          False))  "switch off following redirected URIs"
+      , Option ""       [a_default_baseuri]             (ReqArg  withDefaultBaseURI     "URI")  "default base URI, default: \"file:///<cwd>/\""
+      , Option "e"      [a_encoding]                    (ReqArg  withInputEncoding  "CHARSET")  ( "default document encoding (" ++ utf8 ++ ", " ++ isoLatin1 ++ ", " ++ usAscii ++ ", ...)" )
+      , Option ""       [a_mime_types]                  (ReqArg  withMimeTypeFile      "FILE")  "set mime type configuration file, e.g. \"/etc/mime.types\""
+      , Option ""       [a_issue_errors]                (NoArg  (withErrors             True))  "issue all error messages on stderr (default)"
+      , Option ""       [a_do_not_issue_errors]         (NoArg  (withErrors            False))  "ignore all error messages"
+      , Option ""       [a_ignore_encoding_errors]      (NoArg  (withEncodingErrors    False))   "ignore encoding errors"
+      , Option ""       [a_ignore_none_xml_contents]    (NoArg  (withIgnoreNoneXmlContents True)) "discards all contents of none XML/HTML documents, only the meta info remains in the doc tree"
+      , Option ""       [a_accept_mimetypes]            (ReqArg  withMT           "MIMETYPES")  "only accept documents matching the given comma separated list of mimetype specs"
+      , Option "H"      [a_parse_html]                  (NoArg  (withParseHTML          True))  "parse input as HTML, try to interprete everything as HTML, no validation"
+      , Option "M"      [a_parse_by_mimetype]           (NoArg  (withParseByMimeType    True))  "parse dependent on mime type: text/html as HTML, text/xml and text/xhtml and others as XML, else no parse"
+      , Option ""       [a_parse_xml]                   (NoArg  (withParseHTML         False))  "parse input as XML, (default)"
+      , Option ""       [a_strict_input]                (NoArg  (withStrictInput        True))  "read input files strictly, this ensures closing the files correctly even if not read completely"
+      , Option ""       [a_issue_warnings]              (NoArg  (withWarnings           True))  "issue warnings, when parsing HTML (default)"
+      , Option "Q"      [a_do_not_issue_warnings]       (NoArg  (withWarnings          False))  "ignore warnings, when parsing HTML"
+      , Option ""       [a_validate]                    (NoArg  (withValidate           True))  "document validation when parsing XML (default)"
+      , Option "w"      [a_do_not_validate]             (NoArg  (withValidate          False))  "only wellformed check, no validation"
+      , Option ""       [a_canonicalize]                (NoArg  (withCanonicalize       True))  "canonicalize document, remove DTD, comment, transform CDATA, CharRef's, ... (default)"
+      , Option "c"      [a_do_not_canonicalize]         (NoArg  (withCanonicalize      False))  "do not canonicalize document, don't remove DTD, comment, don't transform CDATA, CharRef's, ..."
+      , Option "C"      [a_preserve_comment]            (NoArg  (withPreserveComment    True))  "don't remove comments during canonicalisation"
+      , Option ""       [a_do_not_preserve_comment]     (NoArg  (withPreserveComment   False))  "remove comments during canonicalisation (default)"
+      , Option "n"      [a_check_namespaces]            (NoArg  (withCheckNamespaces    True))  "tag tree with namespace information and check namespaces"
+      , Option ""       [a_do_not_check_namespaces]     (NoArg  (withCheckNamespaces   False))  "ignore namespaces (default)"
+      , Option "r"      [a_remove_whitespace]           (NoArg  (withRemoveWS           True))  "remove redundant whitespace, simplifies tree and processing"
+      , Option ""       [a_do_not_remove_whitespace]    (NoArg  (withRemoveWS          False))  "don't remove redundant whitespace (default)"
+      ]
+    where
+    withMT = withAcceptedMimeTypes . words . map (\ x -> if x == ',' then ' ' else x)
+    trc = withTrace . max 0 . min 9 . (read :: String -> Int) . ('0':) . filter (`elem` "0123456789") . fromMaybe v_1
+
+-- |
+-- commonly useful options for XML output
+--
+-- defines options: 'a_indent', 'a_output_encoding', 'a_output_html' and others
+
+outputOptions   :: [OptDescr SysConfig]
+outputOptions
+    = [ Option "f"      [a_output_file]         (ReqArg (withSysAttr a_output_file) "FILE")   "output file for resulting document (default: stdout)"
+      , Option "i"      [a_indent]              (NoArg  (withIndent               True))      "indent XML output for readability"
+      , Option "o"      [a_output_encoding]     (ReqArg  withOutputEncoding    "CHARSET")      ( "encoding of output (" ++ utf8 ++ ", " ++ isoLatin1 ++ ", " ++ usAscii ++ ")" )
+      , Option ""       [a_output_xml]          (NoArg   withOutputXML                  )      "output of none ASCII chars as HTMl entity references"
+      , Option ""       [a_output_html]         (NoArg   withOutputHTML                 )      "output of none ASCII chars as HTMl entity references"
+      , Option ""       [a_output_xhtml]        (NoArg   withOutputXHTML                )      "output of HTML elements with empty content (script, ...) done in format <elem...></elem> instead of <elem/>"
+      , Option ""       [a_output_plain]        (NoArg   withOutputPLAIN                )      "output of HTML elements with empty content (script, ...) done in format <elem...></elem> instead of <elem/>"
+      , Option ""       [a_no_xml_pi]           (NoArg  (withXmlPi                False))      ("output without <?xml ...?> processing instruction, useful in combination with --" ++ show a_output_html)
+      , Option ""       [a_no_empty_elem_for]   (ReqArg (withNoEmptyElemFor . words') "NAMES")   "output of empty elements done in format <elem...></elem> only for given list of element names"
+      , Option ""       [a_add_default_dtd]     (NoArg  (withAddDefaultDTD         True))      "add the document type declaration given in the input document"
+      , Option ""       [a_text_mode]           (NoArg  (withTextMode              True))      "output in text mode"
+      ]
+    where
+    words'
+        = words
+          . map (\ c -> if c == ',' then ' ' else c)
+
+-- |
+-- commonly useful options
+--
+-- defines options: 'a_verbose', 'a_help'
+
+generalOptions  :: [OptDescr SysConfig]
+generalOptions
+    = [ Option "v"      [a_verbose]             (NoArg  (withSysAttr a_verbose v_1))               "verbose output"
+      , Option "h?"     [a_help]                (NoArg  (withSysAttr a_help    v_1))               "this message"
+      ]
+
+-- |
+-- defines 'a_version' option
+
+versionOptions  :: [OptDescr SysConfig]
+versionOptions
+    = [ Option "V"      [a_version]             (NoArg  (withSysAttr a_version v_1))               "show program version"
+      ]
+
+-- |
+-- debug output options
+
+showOptions     :: [OptDescr SysConfig]
+showOptions
+    = [ Option ""       [a_show_tree]           (NoArg  (withShowTree      True))          "output tree representation instead of document source"
+      , Option ""       [a_show_haskell]        (NoArg  (withShowHaskell   True))          "output internal Haskell representation instead of document source"
+      ]
+
+-- ------------------------------------------------------------
+
+a_accept_mimetypes,
+ a_add_default_dtd,
+ a_canonicalize,
+ a_check_namespaces,
+ a_collect_errors,
+ a_default_baseuri,
+ a_do_not_canonicalize,
+ a_do_not_check_namespaces,
+ a_do_not_issue_errors,
+ a_do_not_issue_warnings,
+ a_do_not_preserve_comment,
+ a_do_not_remove_whitespace,
+ a_do_not_validate,
+ a_error,
+ a_error_log,
+ a_help,
+ a_if_modified_since,
+ a_if_unmodified_since,
+ a_ignore_encoding_errors,
+ a_ignore_none_xml_contents,
+ a_indent,
+ a_issue_errors,
+ a_issue_warnings,
+ a_mime_types,
+ a_no_empty_elements,
+ a_no_empty_elem_for,
+ a_no_redirect,
+ a_no_xml_pi,
+ a_output_file,
+ a_output_xml,
+ a_output_html,
+ a_output_xhtml,
+ a_output_plain,
+ a_parse_by_mimetype,
+ a_parse_html,
+ a_parse_xml,
+ a_preserve_comment,
+ a_proxy,
+ a_redirect,
+ a_remove_whitespace,
+ a_show_haskell,
+ a_show_tree,
+ a_strict_input,
+ a_text_mode,
+ a_trace,
+ a_validate,
+ a_verbose      :: String
+
+a_accept_mimetypes              = "accept-mimetypes"
+a_add_default_dtd               = "add-default-dtd"
+a_canonicalize                  = "canonicalize"
+a_check_namespaces              = "check-namespaces"
+a_collect_errors                = "collect-errors"
+a_default_baseuri               = "default-base-URI"
+a_do_not_canonicalize           = "do-not-canonicalize"
+a_do_not_check_namespaces       = "do-not-check-namespaces"
+a_do_not_issue_errors           = "do-not-issue-errors"
+a_do_not_issue_warnings         = "do-not-issue-warnings"
+a_do_not_preserve_comment       = "do-not-preserve-comment"
+a_do_not_remove_whitespace      = "do-not-remove-whitespace"
+a_do_not_validate               = "do-not-validate"
+a_error                         = "error"
+a_error_log                     = "errorLog"
+a_help                          = "help"
+a_if_modified_since             = "if-modified-since"
+a_if_unmodified_since           = "if-unmodified-since"
+a_ignore_encoding_errors        = "ignore-encoding-errors"
+a_ignore_none_xml_contents      = "ignore-none-xml-contents"
+a_indent                        = "indent"
+a_issue_warnings                = "issue-warnings"
+a_issue_errors                  = "issue-errors"
+a_mime_types                    = "mimetypes"
+a_no_empty_elements             = "no-empty-elements"
+a_no_empty_elem_for             = "no-empty-elem-for"
+a_no_redirect                   = "no-redirect"
+a_no_xml_pi                     = "no-xml-pi"
+a_output_file                   = "output-file"
+a_output_html                   = "output-html"
+a_output_xhtml                  = "output-xhtml"
+a_output_xml                    = "output-xml"
+a_output_plain                  = "output-plain"
+a_parse_by_mimetype             = "parse-by-mimetype"
+a_parse_html                    = "parse-html"
+a_parse_xml                     = "parse-xml"
+a_preserve_comment              = "preserve-comment"
+a_proxy                         = "proxy"
+a_redirect                      = "redirect"
+a_remove_whitespace             = "remove-whitespace"
+a_show_haskell                  = "show-haskell"
+a_show_tree                     = "show-tree"
+a_strict_input                  = "strict-input"
+a_text_mode                     = "text-mode"
+a_trace                         = "trace"
+a_validate                      = "validate"
+a_verbose                       = "verbose"
+
+-- ------------------------------------------------------------
+
+-- |
+-- select options from a predefined list of option desciptions
+
+selectOptions   :: [String] -> [OptDescr a] -> [OptDescr a]
+selectOptions ol os
+    = concat . map (\ on -> filter (\ (Option _ ons _ _) -> on `elem` ons) os) $ ol
+
+removeOptions   :: [String] -> [OptDescr a] -> [OptDescr a]
+removeOptions ol os
+    = filter (\ (Option _ ons _ _) -> not . any (`elem` ol) $ ons ) os
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/XmlRegex.hs b/src/Text/XML/HXT/Arrow/XmlRegex.hs
--- a/src/Text/XML/HXT/Arrow/XmlRegex.hs
+++ b/src/Text/XML/HXT/Arrow/XmlRegex.hs
@@ -28,7 +28,9 @@
     , mkDot
     , mkStar
     , mkAlt
+    , mkAlts
     , mkSeq
+    , mkSeqs
     , mkRep
     , mkRng
     , mkOpt
@@ -61,7 +63,7 @@
 -- ('mkStar', mkRep', 'mkRng') and choice ('mkAlt', 'mkOpt')
 
 matchRegexA             :: XmlRegex -> LA XmlTree XmlTree -> LA XmlTree XmlTrees
-matchRegexA re ts       = ts >>. (\ s -> maybe [] (const [s]) . matchXmlRegex re $ s)
+matchRegexA re ts       = ts >>. (\ s -> maybe [s] (const []) . matchXmlRegex re $ s)
 
 -- | split the sequence of trees computed by the filter a into
 --
@@ -131,8 +133,8 @@
 mkPrimA         :: LA XmlTree XmlTree -> XmlRegex
 mkPrimA a       = mkPrim (not . null . runLA a)
 
-mkDot   :: XmlRegex
-mkDot   = Dot
+mkDot   	:: XmlRegex
+mkDot   	= Dot
 
 mkStar                  :: XmlRegex -> XmlRegex
 mkStar (Zero _)         = mkUnit                -- {}* == ()
@@ -159,6 +161,9 @@
 mkAlt (Alt e1 e2)   e3                  = mkAlt e1 (mkAlt e2 e3)        -- associativity
 mkAlt e1 e2                             = Alt e1 e2
 
+mkAlts                          :: [XmlRegex] -> XmlRegex
+mkAlts                          = foldr mkAlt (mkZero "")
+
 mkSeq                           :: XmlRegex -> XmlRegex -> XmlRegex
 mkSeq e1@(Zero _) _e2           = e1
 mkSeq _e1         e2@(Zero _)   = e2
@@ -166,6 +171,9 @@
 mkSeq e1          Unit          = e1
 mkSeq (Seq e1 e2) e3            = mkSeq e1 (mkSeq e2 e3)
 mkSeq e1 e2                     = Seq e1 e2
+
+mkSeqs                          :: [XmlRegex] -> XmlRegex
+mkSeqs                          = foldr mkSeq mkUnit
 
 mkRep           :: Int -> XmlRegex -> XmlRegex
 mkRep 0 e                       = mkStar e
diff --git a/src/Text/XML/HXT/Arrow/XmlState.hs b/src/Text/XML/HXT/Arrow/XmlState.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/XmlState.hs
@@ -0,0 +1,157 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.XmlState
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   the interface for the basic state maipulation functions
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.XmlState
+    ( -- * Data Types
+      XIOState
+    , XIOSysState
+    , IOStateArrow
+    , IOSArrow
+    , SysConfig
+    , SysConfigList
+    ,
+      -- * User State Manipulation
+      getUserState
+    , setUserState
+    , changeUserState
+    , withExtendedUserState
+    , withOtherUserState
+    , withoutUserState
+    ,
+      -- * Run IO State arrows
+      runX
+    ,
+      -- * Global System State Configuration and Access
+      configSysVars
+    , setSysAttr
+    , unsetSysAttr
+    , getSysAttr
+    , getAllSysAttrs
+    , setSysAttrString
+    , setSysAttrInt
+    , getSysAttrInt
+    , getConfigAttr
+    ,
+      -- * Error Handling
+      clearErrStatus
+    , setErrStatus
+    , getErrStatus
+    , setErrMsgStatus
+    , setErrorMsgHandler
+    , errorMsgStderr
+    , errorMsgCollect
+    , errorMsgStderrAndCollect
+    , errorMsgIgnore
+    , getErrorMessages
+    , filterErrorMsg
+    , issueWarn
+    , issueErr
+    , issueFatal
+    , issueExc
+    , setDocumentStatus
+    , setDocumentStatusFromSystemState
+    , documentStatusOk
+
+    , -- * Tracing
+      setTraceLevel
+    , getTraceLevel
+    , withTraceLevel
+    , setTraceCmd
+    , getTraceCmd
+    , trace
+    , traceMsg
+    , traceValue
+    , traceString
+    , traceSource
+    , traceTree
+    , traceDoc
+
+    , -- * Document Base
+      setBaseURI
+    , getBaseURI
+    , changeBaseURI
+    , setDefaultBaseURI
+    , getDefaultBaseURI
+    , runInLocalURIContext
+
+    ,  -- * URI Manipulation
+      expandURIString
+    , expandURI
+    , mkAbsURI
+    , getFragmentFromURI
+    , getPathFromURI
+    , getPortFromURI
+    , getQueryFromURI
+    , getRegNameFromURI
+    , getSchemeFromURI
+    , getUserInfoFromURI
+
+    , -- * Mime Type Handling
+      getMimeTypeTable
+    , setMimeTypeTable
+    , setMimeTypeTableFromFile
+
+    , -- System Configuration and options
+      yes
+    , no
+
+    , withAcceptedMimeTypes
+    , withAddDefaultDTD
+    , withSysAttr
+    , withCanonicalize
+    , withCompression
+    , withCheckNamespaces
+    , withDefaultBaseURI
+    , withEncodingErrors
+    , withErrors
+    , withIgnoreNoneXmlContents
+    , withIndent
+    , withInputEncoding
+    , withInputOption
+    , withInputOptions
+    , withMimeTypeFile
+    , withNoEmptyElemFor
+    , withXmlPi
+    , withOutputEncoding
+    , withOutputXML
+    , withOutputHTML
+    , withOutputXHTML
+    , withOutputPLAIN
+    , withParseByMimeType
+    , withParseHTML
+    , withPreserveComment
+    , withProxy
+    , withRedirect
+    , withRemoveWS
+    , withShowHaskell
+    , withShowTree
+    , withStrictInput
+    , withTextMode
+    , withTrace
+    , withValidate
+    , withWarnings
+    )
+where
+
+import Text.XML.HXT.Arrow.XmlState.ErrorHandling
+import Text.XML.HXT.Arrow.XmlState.MimeTypeTable
+import Text.XML.HXT.Arrow.XmlState.RunIOStateArrow
+import Text.XML.HXT.Arrow.XmlState.SystemConfig
+import Text.XML.HXT.Arrow.XmlState.TraceHandling
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
+import Text.XML.HXT.Arrow.XmlState.URIHandling
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/XmlState/ErrorHandling.hs b/src/Text/XML/HXT/Arrow/XmlState/ErrorHandling.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/XmlState/ErrorHandling.hs
@@ -0,0 +1,252 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.XmlState.ErrorHandling
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   the basic state arrows for XML processing
+
+   A state is needed for global processing options,
+   like encoding options, document base URI, trace levels
+   and error message handling
+
+   The state is separated into a user defined state
+   and a system state. The system state contains variables
+   for error message handling, for tracing, for the document base
+   for accessing XML documents with relative references, e.g. DTDs,
+   and a global key value store. This assoc list has strings as keys
+   and lists of XmlTrees as values. It is used to store arbitrary
+   XML and text values, e.g. user defined global options.
+
+   The user defined part of the store is in the default case empty, defined as ().
+   It can be extended with an arbitray data type
+
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.XmlState.ErrorHandling
+where
+
+import Control.Arrow                            -- arrow classes
+import Control.Arrow.ArrowList
+import Control.Arrow.ArrowIf
+import Control.Arrow.ArrowTree
+import Control.Arrow.ArrowIO
+
+import Control.Exception                ( SomeException )
+
+import Data.Maybe
+
+import Text.XML.HXT.DOM.Interface
+
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
+
+import System.IO                        ( hPutStrLn
+                                        , hFlush
+                                        , stderr
+                                        )
+
+-- ------------------------------------------------------------
+
+changeErrorStatus       :: (Int -> Int -> Int) -> IOStateArrow s Int Int
+changeErrorStatus f     = chgSysVar theErrorStatus f
+
+-- | reset global error variable
+
+clearErrStatus          :: IOStateArrow s b b
+clearErrStatus          = configSysVar $ setS theErrorStatus 0
+
+-- | set global error variable
+
+setErrStatus            :: IOStateArrow s Int Int
+setErrStatus            = changeErrorStatus max
+
+-- | read current global error status
+
+getErrStatus            :: IOStateArrow s XmlTree Int
+getErrStatus            = getSysVar theErrorStatus
+
+-- ------------------------------------------------------------
+
+-- | raise the global error status level to that of the input tree
+
+setErrMsgStatus         :: IOStateArrow s XmlTree XmlTree
+setErrMsgStatus         = perform
+                          ( getErrorLevel >>> setErrStatus )
+
+-- | set the error message handler and the flag for collecting the errors
+
+setErrorMsgHandler      :: Bool -> (String -> IO ()) -> IOStateArrow s b b
+setErrorMsgHandler c f  = configSysVar $ setS (theErrorMsgCollect .&&&. theErrorMsgHandler) (c, f)
+
+-- | error message handler for output to stderr
+
+sysErrorMsg             :: IOStateArrow s XmlTree XmlTree
+sysErrorMsg             = perform
+                          ( getErrorLevel &&& getErrorMsg
+                            >>>
+                            arr formatErrorMsg
+                            >>>
+                            getSysVar theErrorMsgHandler &&& this
+                            >>>
+                            arrIO (\ (h, msg) -> h msg)
+                          )
+    where
+    formatErrorMsg (level, msg) = "\n" ++ errClass level ++ ": " ++ msg
+    errClass l          = fromMaybe "fatal error" . lookup l $ msgList
+        where
+        msgList         = [ (c_ok,      "no error")
+                          , (c_warn,    "warning")
+                          , (c_err,     "error")
+                          , (c_fatal,   "fatal error")
+                          ]
+
+
+-- | the default error message handler: error output to stderr
+
+errorMsgStderr          :: IOStateArrow s b b
+errorMsgStderr          = setErrorMsgHandler False (\ x ->
+                                                    do hPutStrLn stderr x
+                                                       hFlush    stderr
+                                                   )
+
+-- | error message handler for collecting errors
+
+errorMsgCollect         :: IOStateArrow s b b
+errorMsgCollect         = setErrorMsgHandler True (const $ return ())
+
+-- | error message handler for output to stderr and collecting
+
+errorMsgStderrAndCollect        :: IOStateArrow s b b
+errorMsgStderrAndCollect        = setErrorMsgHandler True (hPutStrLn stderr)
+
+-- | error message handler for ignoring errors
+
+errorMsgIgnore          :: IOStateArrow s b b
+errorMsgIgnore          = setErrorMsgHandler False (const $ return ())
+
+-- |
+-- if error messages are collected by the error handler for
+-- processing these messages by the calling application,
+-- this arrow reads the stored messages and clears the error message store
+
+getErrorMessages        :: IOStateArrow s b XmlTree
+getErrorMessages        = getSysVar theErrorMsgList
+                          >>>
+                          configSysVar (setS theErrorMsgList [])
+                          >>>
+                          arrL reverse
+
+addToErrorMsgList       :: IOStateArrow s XmlTree XmlTree
+addToErrorMsgList       = chgSysVar
+                          ( theErrorMsgCollect .&&&. theErrorMsgList )
+                          ( \ e (cs, es) -> (cs, if cs then e : es else es) )
+
+-- ------------------------------------------------------------
+
+-- |
+-- filter error messages from input trees and issue errors
+
+filterErrorMsg          :: IOStateArrow s XmlTree XmlTree
+filterErrorMsg          = ( setErrMsgStatus
+                            >>>
+                            sysErrorMsg
+                            >>>
+                            addToErrorMsgList
+                            >>>
+                            none
+                          )
+                          `when`
+                          isError
+
+-- | generate a warnig message
+
+issueWarn               :: String -> IOStateArrow s b b
+issueWarn msg           = perform (warn msg  >>> filterErrorMsg)
+
+-- | generate an error message
+issueErr                :: String -> IOStateArrow s b b
+issueErr msg            = perform (err msg   >>> filterErrorMsg)
+
+-- | generate a fatal error message, e.g. document not found
+
+issueFatal              :: String -> IOStateArrow s b b
+issueFatal msg          = perform (fatal msg >>> filterErrorMsg)
+
+-- | Default exception handler: issue a fatal error message and fail.
+--
+-- The parameter can be used to specify where the error occured
+
+issueExc                :: String -> IOStateArrow s SomeException b
+issueExc m              = ( issueFatal $< arr  ((msg ++) . show) )
+                          >>>
+                          none
+    where
+    msg | null m        = "Exception: "
+        | otherwise     = "Exception in " ++ m ++ ": "
+
+-- |
+-- add the error level and the module where the error occured
+-- to the attributes of a document root node and remove the children when level is greater or equal to 'c_err'.
+-- called by 'setDocumentStatusFromSystemState' when the system state indicates an error
+
+setDocumentStatus       :: Int -> String -> IOStateArrow s XmlTree XmlTree
+setDocumentStatus level msg
+                        = ( addAttrl ( sattr a_status (show level)
+                                       <+>
+                                       sattr a_module msg
+                                     )
+                            >>>
+                            ( if level >= c_err
+                              then setChildren []
+                              else this
+                            )
+                          )
+                      `when`
+                      isRoot
+
+-- |
+-- check whether the error level attribute in the system state
+-- is set to error, in this case the children of the document root are
+-- removed and the module name where the error occured and the error level are added as attributes with 'setDocumentStatus'
+-- else nothing is changed
+
+setDocumentStatusFromSystemState        :: String -> IOStateArrow s XmlTree XmlTree
+setDocumentStatusFromSystemState msg
+                                = setStatus $< getErrStatus
+    where
+    setStatus level
+        | level <= c_warn       = this
+        | otherwise             = setDocumentStatus level msg
+
+
+-- |
+-- check whether tree is a document root and the status attribute has a value less than 'c_err'
+
+documentStatusOk        :: ArrowXml a => a XmlTree XmlTree
+documentStatusOk        = isRoot
+                          >>>
+                          ( (getAttrValue a_status
+                             >>>
+                             isA (\ v -> null v || ((read v)::Int) <= c_warn)
+                            )
+                            `guards`
+                            this
+                          )
+
+-- ------------------------------------------------------------
+
+errorOutputToStderr     :: String -> IO ()
+errorOutputToStderr msg
+                        = do
+                          hPutStrLn stderr msg
+                          hFlush stderr
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/XmlState/MimeTypeTable.hs b/src/Text/XML/HXT/Arrow/XmlState/MimeTypeTable.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/XmlState/MimeTypeTable.hs
@@ -0,0 +1,60 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.XmlState.MimeTypeTable
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   the mime type configuration functions
+
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.XmlState.MimeTypeTable
+where
+
+import Control.Arrow                            -- arrow classes
+import Control.Arrow.ArrowList
+import Control.Arrow.ArrowIO
+
+import Text.XML.HXT.DOM.Interface
+
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
+
+-- ------------------------------------------------------------
+
+-- | set the table mapping of file extensions to mime types in the system state
+--
+-- Default table is defined in 'Text.XML.HXT.DOM.MimeTypeDefaults'.
+-- This table is used when reading loacl files, (file: protocol) to determine the mime type
+
+setMimeTypeTable                :: MimeTypeTable -> IOStateArrow s b b
+setMimeTypeTable mtt            = configSysVar $ setS (theMimeTypes .&&&. theMimeTypeFile) (mtt, "")
+
+-- | set the table mapping of file extensions to mime types by an external config file
+--
+-- The config file must follow the conventions of /etc/mime.types on a debian linux system,
+-- that means all empty lines and all lines starting with a # are ignored. The other lines
+-- must consist of a mime type followed by a possible empty list of extensions.
+-- The list of extenstions and mime types overwrites the default list in the system state
+-- of the IOStateArrow
+
+setMimeTypeTableFromFile        :: FilePath -> IOStateArrow s b b
+setMimeTypeTableFromFile file   = configSysVar $ setS theMimeTypeFile file
+
+-- | read the system mimetype table
+
+getMimeTypeTable                :: IOStateArrow s b MimeTypeTable
+getMimeTypeTable                = getMime $< getSysVar (theMimeTypes .&&&. theMimeTypeFile)
+    where
+    getMime (mtt, "")           = constA mtt
+    getMime (_,  mtf)           = perform (setMimeTypeTable $< arrIO0 ( readMimeTypeTable mtf))
+                                  >>>
+                                  getMimeTypeTable
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/XmlState/RunIOStateArrow.hs b/src/Text/XML/HXT/Arrow/XmlState/RunIOStateArrow.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/XmlState/RunIOStateArrow.hs
@@ -0,0 +1,218 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.XmlState.RunIOStateArrow
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   run an io state arrow
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.XmlState.RunIOStateArrow
+where
+
+import Control.Arrow                            -- arrow classes
+import Control.Arrow.IOStateListArrow
+
+import Text.XML.HXT.DOM.Interface
+
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.Arrow.XmlState.ErrorHandling
+import Text.XML.HXT.Arrow.XmlState.TraceHandling
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
+
+-- ------------------------------------------------------------
+
+-- |
+-- apply an 'IOSArrow' to an empty root node with 'initialState' () as initial state
+--
+-- the main entry point for running a state arrow with IO
+--
+-- when running @ runX f@ an empty XML root node is applied to @f@.
+-- usually @f@ will start with a constant arrow (ignoring the input), e.g. a 'Text.XML.HXT.Arrow.ReadDocument.readDocument' arrow.
+--
+-- for usage see examples with 'Text.XML.HXT.Arrow.WriteDocument.writeDocument'
+--
+-- if input has to be feed into the arrow use 'Control.Arrow.IOStateListArrow.runIOSLA' like in @ runIOSLA f emptyX inputDoc @
+
+runX            :: IOSArrow XmlTree c -> IO [c]
+runX            = runXIOState (initialState ())
+
+
+runXIOState     :: XIOState s -> IOStateArrow s XmlTree c -> IO [c]
+runXIOState s0 f
+    = do
+      (_finalState, res) <- runIOSLA (emptyRoot >>> f) s0 undefined
+      return res
+    where
+    emptyRoot    = root [] []
+
+
+-- | the default global state, used as initial state when running an 'IOSArrow' with 'runIOSLA' or
+-- 'runX'
+
+initialState    :: us -> XIOState us
+initialState s  = XIOState { xioSysState       = initialSysState
+                           , xioUserState      = s
+                           }
+
+-- ------------------------------------------------------------
+
+initialSysState                 :: XIOSysState
+initialSysState                 = XIOSys
+                                  { xioSysWriter         = initialSysWriter
+                                  , xioSysEnv            = initialSysEnv
+                                  }
+
+initialSysWriter                :: XIOSysWriter
+initialSysWriter                = XIOwrt
+                                  { xioErrorMsgList      = []
+                                  }
+
+initialSysEnv                   :: XIOSysEnv
+initialSysEnv                   = XIOEnv
+                                  { xioTraceLevel        = 0
+                                  , xioTraceCmd          = traceOutputToStderr
+                                  , xioErrorStatus       = c_ok
+                                  , xioErrorMsgHandler   = errorOutputToStderr
+                                  , xioErrorMsgCollect   = False
+                                  , xioBaseURI           = ""
+                                  , xioDefaultBaseURI    = ""
+                                  , xioAttrList          = []
+                                  , xioInputConfig       = initialInputConfig
+                                  , xioParseConfig       = initialParseConfig
+                                  , xioOutputConfig      = initialOutputConfig
+                                  , xioRelaxConfig       = initialRelaxConfig
+                                  , xioCacheConfig       = initialCacheConfig
+                                  }
+
+initialInputConfig              :: XIOInputConfig
+initialInputConfig              = XIOIcgf
+                                  { xioStrictInput       = False
+                                  , xioEncodingErrors    = True
+                                  , xioInputEncoding     = ""
+                                  , xioHttpHandler       = dummyHTTPHandler
+                                  , xioInputOptions      = []
+                                  , xioRedirect          = False
+                                  , xioProxy             = ""
+                                  }
+
+initialParseConfig              :: XIOParseConfig
+initialParseConfig              = XIOPcfg
+                                  { xioMimeTypes                = defaultMimeTypeTable
+                                  , xioMimeTypeFile             = ""
+                                  , xioAcceptedMimeTypes        = []
+                                  , xioWarnings                 = True
+                                  , xioRemoveWS                 = False
+                                  , xioParseByMimeType          = False
+                                  , xioParseHTML                = False
+                                  , xioLowerCaseNames           = False
+                                  , xioTagSoup                  = False
+                                  , xioPreserveComment          = False
+                                  , xioValidate                 = True
+                                  , xioCheckNamespaces          = False
+                                  , xioCanonicalize             = True
+                                  , xioIgnoreNoneXmlContents    = False
+                                  , xioTagSoupParser            = dummyTagSoupParser
+                                  }
+
+initialOutputConfig             :: XIOOutputConfig
+initialOutputConfig             = XIOOcfg
+                                  { xioIndent                   = False
+                                  , xioOutputEncoding           = ""
+                                  , xioOutputFmt                = XMLoutput
+                                  , xioXmlPi                    = True
+                                  , xioNoEmptyElemFor           = []
+                                  , xioAddDefaultDTD            = False
+                                  , xioTextMode                 = False
+                                  , xioShowTree                 = False
+                                  , xioShowHaskell              = False
+                                  }
+
+initialRelaxConfig              :: XIORelaxConfig
+initialRelaxConfig              = XIORxc
+                                  { xioRelaxValidate            = False
+                                  , xioRelaxSchema              = ""
+                                  , xioRelaxCheckRestr          = True
+                                  , xioRelaxValidateExtRef      = True
+                                  , xioRelaxValidateInclude     = True
+                                  , xioRelaxCollectErrors       = True
+                                  , xioRelaxNoOfErrors          = 0
+                                  , xioRelaxDefineId            = 0
+                                  , xioRelaxAttrList            = []
+                                  , xioRelaxValidator           = dummyRelaxValidator
+                                  }
+
+initialCacheConfig              :: XIOCacheConfig
+initialCacheConfig              = XIOCch
+                                   { xioBinaryCompression       = id
+                                   , xioBinaryDeCompression     = id
+                                   , xioWithCache               = False
+                                   , xioCacheDir                = ""
+                                   , xioDocumentAge             = 0
+                                   , xioCache404Err             = False
+                                   , xioCacheRead               = dummyCacheRead
+                                   }
+
+-- ------------------------------------------------------------
+
+dummyHTTPHandler        :: IOSArrow XmlTree XmlTree
+dummyHTTPHandler        = ( issueFatal $
+                            unlines $
+                            [ "HTTP handler not configured,"
+                            , "please install package hxt-curl and use 'withCurl' config option"
+                            , "or install package hxt-http and use 'withHTTP' config option"
+                            ]
+                          )
+                          >>>
+                          addAttr transferMessage "HTTP handler not configured"
+                          >>>
+                          addAttr transferStatus "999"
+
+
+dummyTagSoupParser      :: IOSArrow b b
+dummyTagSoupParser      =  issueFatal $
+                           unlines $
+                           [ "TagSoup parser not configured,"
+                           , "please install package hxt-tagsoup"
+                           , " and use 'withTagSoup' parser config option from this package"
+                           ]
+
+dummyRelaxValidator     :: IOSArrow b b
+dummyRelaxValidator     =  issueFatal $
+                           unlines $
+                           [ "RelaxNG validator not configured,"
+                           , "please install package hxt-relaxng"
+                           , " and use 'withRelaxNG' config option from this package"
+                           ]
+
+dummyCacheRead          :: String -> IOSArrow b b
+dummyCacheRead          = const $
+                          issueFatal $
+                          unlines $
+                          [ "Document cache not configured,"
+                          , "please install package hxt-cache and use 'withCache' config option"
+                          ]
+
+-- ------------------------------------------------------------
+
+getConfigAttr           :: String -> SysConfigList -> String
+getConfigAttr n c       = lookup1 n $ tl
+    where
+    s                   = (foldr (>>>) id c) initialSysState
+    tl                  = getS theAttrList s
+
+-- ----------------------------------------
+
+theSysConfigComp        :: Selector XIOSysState a -> Selector SysConfig a
+theSysConfigComp sel    = S { getS = \     cf -> getS sel      (cf initialSysState)
+                            , setS = \ val cf -> setS sel val . cf
+                            }
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/XmlState/SystemConfig.hs b/src/Text/XML/HXT/Arrow/XmlState/SystemConfig.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/XmlState/SystemConfig.hs
@@ -0,0 +1,234 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.XmlState.SystemConfig
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   system configuration and common options options
+
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.XmlState.SystemConfig
+where
+
+import Control.Arrow
+
+import Text.XML.HXT.DOM.Interface
+
+import Text.XML.HXT.Arrow.XmlState.ErrorHandling
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
+
+-- ------------------------------
+
+-- config options
+
+-- | @withTace level@ : system option, set the trace level, (0..4)
+
+withTrace                       :: Int -> SysConfig
+withTrace                       = setS theTraceLevel
+
+-- | @withSysAttr key value@ : store an arbitarty key value pair in system state
+
+withSysAttr                     :: String -> String -> SysConfig
+withSysAttr n v                 = chgS theAttrList (addEntry n v)
+
+withAcceptedMimeTypes           :: [String] -> SysConfig
+withAcceptedMimeTypes           = setS theAcceptedMimeTypes
+
+-- | @withMimeTypeFile filename@ : input option,
+-- set the mime type table for @file:@ documents by given file.
+-- The format of this config file must be in the syntax of a debian linux \"mime.types\" config file
+
+withMimeTypeFile                :: String -> SysConfig
+withMimeTypeFile                = setS theMimeTypeFile
+
+-- | @withWarnings yes/no@ : system option, issue warnings during reading, HTML parsing and processing,
+-- default is 'yes'
+
+withWarnings                    :: Bool -> SysConfig
+withWarnings                    = setS theWarnings
+
+-- | @withErrors yes/no@ : system option for suppressing error messages, default is 'no'
+
+withErrors                      :: Bool -> SysConfig
+withErrors b                    = setS theErrorMsgHandler h
+    where
+    h | b                       = errorOutputToStderr
+      | otherwise               = const $ return ()
+
+-- | @withRemoveWS yes/no@ : read and write option, remove all whitespace, used for document indentation, default is 'no'
+
+withRemoveWS                    :: Bool -> SysConfig
+withRemoveWS                    = setS theRemoveWS
+
+-- | @withPreserveComment yes/no@ : read option, preserve comments during canonicalization, default is 'no'
+
+withPreserveComment             :: Bool -> SysConfig
+withPreserveComment             = setS thePreserveComment
+
+-- | @withParseByMimeType yes/no@  : read option, select the parser by the mime type of the document
+-- (pulled out of the HTTP header).
+--
+-- When the mime type is set to \"text\/html\"
+-- the configured HTML parser is taken, when it\'s set to
+-- \"text\/xml\" or \"text\/xhtml\" the configured XML parser is taken.
+-- If the mime type is something else, no further processing is performed,
+-- the contents is given back to the application in form of a single text node.
+-- If the default document encoding is set to isoLatin1, this even enables processing
+-- of arbitray binary data.
+
+withParseByMimeType             :: Bool -> SysConfig
+withParseByMimeType             = setS theParseByMimeType
+
+-- | @withParseHTML yes/no@: read option, use HTML parser, default is 'no' (use XML parser)
+
+withParseHTML                   :: Bool -> SysConfig
+withParseHTML                   = setS theParseHTML
+
+-- | @withValidate yes/no@: read option, validate document againsd DTD, default is 'yes'
+
+withValidate                    :: Bool -> SysConfig
+withValidate                    = setS theValidate
+
+-- | @withCheckNamespaces yes/no@: read option, check namespaces, default is 'no'
+
+withCheckNamespaces             :: Bool -> SysConfig
+withCheckNamespaces             = setS theCheckNamespaces
+
+-- | @withCanonicalize yes/no@ : read option, canonicalize document, default is 'yes'
+
+withCanonicalize                :: Bool -> SysConfig
+withCanonicalize                = setS theCanonicalize
+
+-- | @withIgnoreNoneXmlContents yes\/no@ : input option, ignore document contents of none XML\/HTML documents.
+--
+-- This option can be useful for implementing crawler like applications, e.g. an URL checker.
+-- In those cases net traffic can be reduced.
+
+withIgnoreNoneXmlContents       :: Bool -> SysConfig
+withIgnoreNoneXmlContents       = setS theIgnoreNoneXmlContents
+
+-- ------------------------------------------------------------
+
+-- | @withStrictInput yes/no@ : input option, input of file and HTTP contents is read eagerly, default is 'no'
+
+withStrictInput                 :: Bool -> SysConfig
+withStrictInput                 = setS theStrictInput
+
+-- | @withEncodingErrors yes/no@ : input option, ignore all encoding errors, default is 'no'
+
+withEncodingErrors              :: Bool -> SysConfig
+withEncodingErrors              = setS theEncodingErrors
+
+-- | @withInputEncoding encodingName@ : input option
+--
+-- Set default document encoding ('utf8', 'isoLatin1', 'usAscii', 'iso8859_2', ... , 'iso8859_16', ...).
+-- Only XML, HTML and text documents are decoded,
+-- default decoding for XML\/HTML is utf8, for text iso latin1 (no decoding).
+
+withInputEncoding               :: String -> SysConfig
+withInputEncoding               = setS theInputEncoding
+
+-- | @withDefaultBaseURI URI@ , input option, set the default base URI
+--
+-- This option can be useful when parsing documents from stdin or contained in a string, and interpreting
+-- relative URIs within the document
+
+withDefaultBaseURI              :: String -> SysConfig
+withDefaultBaseURI              = setS theDefaultBaseURI
+
+withInputOption                 :: String -> String -> SysConfig
+withInputOption n v             = chgS theInputOptions (addEntry n v)
+
+withInputOptions                :: Attributes -> SysConfig
+withInputOptions                = foldr (>>>) id . map (uncurry withInputOption)
+
+-- | @withRedirect yes/no@ : input option, automatically follow redirected URIs, default is 'yes'
+
+withRedirect                    :: Bool -> SysConfig
+withRedirect                    = setS theRedirect
+
+-- | @withProxy \"host:port\"@ : input option, configure a proxy for HTTP access, e.g. www-cache:3128
+
+withProxy                       :: String -> SysConfig
+withProxy                       = setS theProxy
+
+-- ------------------------------------------------------------
+
+-- | @withIndent yes/no@ : output option, indent document before output, default is 'no'
+
+withIndent                      :: Bool -> SysConfig
+withIndent                      = setS theIndent
+
+-- | @withOutputEncoding encoding@ , output option,
+-- default is the default input encoding or utf8, if input encoding is not set
+
+withOutputEncoding              :: String -> SysConfig
+withOutputEncoding              = setS theOutputEncoding
+
+-- | @withOutputXML@ : output option, default writing
+--
+-- Default is writing XML: quote special XML chars \>,\<,\",\',& where neccessary,
+-- add XML processing instruction
+-- and encode document with respect to 'withOutputEncoding'
+
+withOutputXML                   :: SysConfig
+withOutputXML                   = setS theOutputFmt XMLoutput
+
+-- | Write XHTML: quote all special XML chars, use HTML entity refs or char refs for none ASCII chars
+
+withOutputHTML                  :: SysConfig
+withOutputHTML                  = setS theOutputFmt HTMLoutput
+
+-- | Write XML: quote only special XML chars, don't substitute chars by HTML entities, and don\'t generate empty elements for HTML elements,
+-- which may contain any contents, e.g. @<script src=...></script>@ instead of @<script src=... />@
+
+withOutputXHTML                 :: SysConfig
+withOutputXHTML                 = setS theOutputFmt XHTMLoutput
+
+-- | suppreses all char and entitiy substitution
+
+withOutputPLAIN                 :: SysConfig
+withOutputPLAIN                 = setS theOutputFmt PLAINoutput
+
+withXmlPi                       :: Bool -> SysConfig
+withXmlPi                       = setS theXmlPi
+
+withNoEmptyElemFor              :: [String] -> SysConfig
+withNoEmptyElemFor              = setS theNoEmptyElemFor
+
+withAddDefaultDTD               :: Bool -> SysConfig
+withAddDefaultDTD               = setS theAddDefaultDTD
+
+withTextMode                    :: Bool -> SysConfig
+withTextMode                    = setS theTextMode
+
+withShowTree                    :: Bool -> SysConfig
+withShowTree                    = setS theShowTree
+
+withShowHaskell                 :: Bool -> SysConfig
+withShowHaskell                 = setS theShowHaskell
+
+-- | Configure compression and decompression for binary serialization/deserialization.
+-- First component is the compression function applied after serialization,
+-- second the decompression applied before deserialization.
+
+withCompression                 :: (CompressionFct, DeCompressionFct) -> SysConfig
+withCompression                 = setS (theBinaryCompression .&&&. theBinaryDeCompression)
+
+-- ------------------------------------------------------------
+
+yes                             :: Bool
+yes                             = True
+
+no                              :: Bool
+no                              = False
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/XmlState/TraceHandling.hs b/src/Text/XML/HXT/Arrow/XmlState/TraceHandling.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/XmlState/TraceHandling.hs
@@ -0,0 +1,150 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.XmlState.TraceHandling
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   the trace arrows
+
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.XmlState.TraceHandling
+where
+
+import Control.Arrow                            -- arrow classes
+import Control.Arrow.ArrowList
+import Control.Arrow.ArrowIf
+import Control.Arrow.ArrowTree
+import Control.Arrow.ArrowIO
+
+import System.IO                        ( hPutStrLn
+                                        , hFlush
+                                        , stderr
+                                        )
+
+import Text.XML.HXT.DOM.Interface
+
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
+import Text.XML.HXT.Arrow.XmlState.SystemConfig
+
+import Text.XML.HXT.Arrow.Edit          ( addHeadlineToXmlDoc
+                                        , treeRepOfXmlDoc
+                                        , indentDoc
+                                        )
+
+-- ------------------------------------------------------------
+
+-- | set the global trace level
+
+setTraceLevel           :: Int -> IOStateArrow s b b
+setTraceLevel l         = configSysVar $ withTrace l
+
+-- | read the global trace level
+
+getTraceLevel           :: IOStateArrow s b Int
+getTraceLevel           = getSysVar theTraceLevel
+
+-- | set the global trace command. This command does the trace output
+
+setTraceCmd             :: (Int -> String -> IO ()) -> IOStateArrow s b b
+setTraceCmd c           = configSysVar $ setS theTraceCmd c
+
+-- | acces the command for trace output
+
+getTraceCmd             :: IOStateArrow a b (Int -> String -> IO ())
+getTraceCmd             = getSysVar theTraceCmd
+
+-- | run an arrow with a given trace level, the old trace level is restored after the arrow execution
+
+withTraceLevel          :: Int -> IOStateArrow s b c -> IOStateArrow s b c
+withTraceLevel level f  = localSysEnv $ setTraceLevel level >>> f
+
+-- | apply a trace arrow and issue message to stderr
+
+trace                   :: Int -> IOStateArrow s b String -> IOStateArrow s b b
+trace level trc         = perform ( trc
+                                    >>>
+                                    ( getTraceCmd &&& this )
+                                    >>>
+                                    arrIO (\ (cmd, msg) -> cmd level msg)
+                                  )
+                          `when` ( getTraceLevel
+                                   >>>
+                                   isA (>= level)
+                                 )
+
+-- | trace the current value transfered in a sequence of arrows.
+--
+-- The value is formated by a string conversion function. This is a substitute for
+-- the old and less general traceString function
+
+traceValue              :: Int -> (b -> String) -> IOStateArrow s b b
+traceValue level trc    = trace level (arr $ (('-' : "- (" ++ show level ++ ") ") ++) . trc)
+
+-- | an old alias for 'traceValue'
+
+traceString             :: Int -> (b -> String) -> IOStateArrow s b b
+traceString             = traceValue
+
+-- | issue a string message as trace
+
+traceMsg                :: Int -> String -> IOStateArrow s b b
+traceMsg level msg      = traceValue level (const msg)
+
+-- | issue the source representation of a document if trace level >= 3
+--
+-- for better readability the source is formated with indentDoc
+
+traceSource             :: IOStateArrow s XmlTree XmlTree
+traceSource             = trace 3 $
+                          xshow $
+                          choiceA [ isRoot :-> ( indentDoc
+                                                 >>>
+                                                 getChildren
+                                               )
+                                  , isElem :-> ( root [] [this]
+                                                 >>> indentDoc
+                                                 >>> getChildren
+                                                 >>> isElem
+                                               )
+                                  , this   :-> this
+                                  ]
+
+-- | issue the tree representation of a document if trace level >= 4
+traceTree               :: IOStateArrow s XmlTree XmlTree
+traceTree               = trace 4 $
+                          xshow $
+                          treeRepOfXmlDoc
+                          >>>
+                          addHeadlineToXmlDoc
+                          >>>
+                          getChildren
+
+-- | trace a main computation step
+-- issue a message when trace level >= 1, issue document source if level >= 3, issue tree when level is >= 4
+
+traceDoc                :: String -> IOStateArrow s XmlTree XmlTree
+traceDoc msg            = traceMsg 1 msg
+                          >>>
+                          traceSource
+                          >>>
+                          traceTree
+
+-- ----------------------------------------------------------
+
+traceOutputToStderr     :: Int -> String -> IO ()
+traceOutputToStderr _level msg
+                        = do
+                          hPutStrLn stderr msg
+                          hFlush stderr
+
+-- ----------------------------------------------------------
+
diff --git a/src/Text/XML/HXT/Arrow/XmlState/TypeDefs.hs b/src/Text/XML/HXT/Arrow/XmlState/TypeDefs.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/XmlState/TypeDefs.hs
@@ -0,0 +1,809 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.XmlState.TypeDefs
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   the basic state arrows for XML processing
+
+   A state is needed for global processing options,
+   like encoding options, document base URI, trace levels
+   and error message handling
+
+   The state is separated into a user defined state
+   and a system state. The system state contains variables
+   for error message handling, for tracing, for the document base
+   for accessing XML documents with relative references, e.g. DTDs,
+   and a global key value store. This assoc list has strings as keys
+   and lists of XmlTrees as values. It is used to store arbitrary
+   XML and text values, e.g. user defined global options.
+
+   The user defined part of the store is in the default case empty, defined as ().
+   It can be extended with an arbitray data type
+
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.XmlState.TypeDefs
+    ( module Text.XML.HXT.Arrow.XmlState.TypeDefs
+    , Selector(..)
+    , chgS
+    , idS
+    , (.&&&.)
+    )
+where
+
+import Control.Arrow                            -- arrow classes
+import Control.Arrow.ArrowList
+import Control.Arrow.IOStateListArrow
+import Control.DeepSeq
+
+import Data.ByteString.Lazy             ( ByteString )
+import Data.Char                        ( isDigit )
+import Data.Function.Selector           ( Selector(..)
+                                        , chgS
+                                        , idS
+                                        , (.&&&.)
+                                        )
+
+import Text.XML.HXT.DOM.Interface
+
+-- ------------------------------------------------------------
+{- datatypes -}
+
+-- |
+-- state datatype consists of a system state and a user state
+-- the user state is not fixed
+
+data XIOState us        = XIOState { xioSysState               :: ! XIOSysState
+                                   , xioUserState              :: ! us
+                                   }
+
+instance (NFData us) => NFData (XIOState us) where
+    rnf (XIOState sys usr)      = rnf sys `seq` rnf usr
+
+-- |
+-- The arrow type for stateful arrows
+
+type IOStateArrow s b c = IOSLA (XIOState s) b c
+
+-- |
+-- The arrow for stateful arrows with no user defined state
+
+type IOSArrow b c       = IOStateArrow () b c
+
+-- ------------------------------------------------------------
+
+-- user state functions
+
+-- | read the user defined part of the state
+
+getUserState    :: IOStateArrow s b s
+getUserState
+    = IOSLA $ \ s _ ->
+      return (s, [xioUserState s])
+
+-- | change the user defined part of the state
+
+changeUserState         :: (b -> s -> s) -> IOStateArrow s b b
+changeUserState cf
+    = IOSLA $ \ s v ->
+      let s' = s { xioUserState = cf v (xioUserState s) }
+      in return (s', [v])
+
+-- | set the user defined part of the state
+
+setUserState            :: IOStateArrow s s s
+setUserState
+    = changeUserState const
+
+-- | extend user state
+--
+-- Run an arrow with an extended user state component, The old component
+-- is stored together with a new one in a pair, the arrow is executed with this
+-- extended state, and the augmented state component is removed form the state
+-- when the arrow has finished its execution
+
+withExtendedUserState   :: s1 -> IOStateArrow (s1, s0) b c -> IOStateArrow s0 b c
+withExtendedUserState initS1 f
+    = IOSLA $ \ s0 x ->
+      do
+      ~(finalS, res) <- runIOSLA f ( XIOState { xioSysState  =          xioSysState  s0
+                                              , xioUserState = (initS1, xioUserState s0)
+                                              }
+                                   ) x
+      return ( XIOState { xioSysState  =      xioSysState  finalS
+                        , xioUserState = snd (xioUserState finalS)
+                        }
+             , res
+             )
+
+-- | change the type of user state
+--
+-- This conversion is useful, when running a state arrow with another
+-- structure of the user state, e.g. with () when executing some IO arrows
+
+withOtherUserState      :: s1 -> IOStateArrow s1 b c -> IOStateArrow s0 b c
+withOtherUserState s1 f
+    = IOSLA $ \ s x ->
+      do
+      (s', res) <- runIOSLA f ( XIOState { xioSysState  = xioSysState s
+                                         , xioUserState = s1
+                                         }
+                              ) x
+      return ( XIOState { xioSysState  = xioSysState  s'
+                        , xioUserState = xioUserState s
+                        }
+             , res
+             )
+
+withoutUserState      :: IOSArrow b c -> IOStateArrow s0 b c
+withoutUserState      = withOtherUserState ()
+
+-- ------------------------------------------------------------
+
+-- system state structure and acces functions
+
+-- |
+-- predefined system state data type with all components for the
+-- system functions, like trace, error handling, ...
+
+data XIOSysState        = XIOSys  { xioSysWriter                :: ! XIOSysWriter
+                                  , xioSysEnv                   :: ! XIOSysEnv
+                                  }
+
+instance NFData XIOSysState             -- all fields of interest are strict
+
+data XIOSysWriter       = XIOwrt  { xioErrorMsgList             :: ! XmlTrees
+                                  }
+
+data XIOSysEnv          = XIOEnv  { xioTraceLevel               :: ! Int
+                                  , xioTraceCmd                 ::   Int -> String -> IO ()
+                                  , xioErrorStatus              :: ! Int
+                                  , xioErrorMsgHandler          ::   String -> IO ()
+                                  , xioErrorMsgCollect          :: ! Bool
+                                  , xioBaseURI                  :: ! String
+                                  , xioDefaultBaseURI           :: ! String
+                                  , xioAttrList                 :: ! Attributes
+                                  , xioInputConfig              :: ! XIOInputConfig
+                                  , xioParseConfig              :: ! XIOParseConfig
+                                  , xioOutputConfig             :: ! XIOOutputConfig
+                                  , xioRelaxConfig              :: ! XIORelaxConfig
+                                  , xioCacheConfig              :: ! XIOCacheConfig
+                                  }
+
+data XIOInputConfig     = XIOIcgf { xioStrictInput              :: ! Bool
+                                  , xioEncodingErrors           :: ! Bool
+                                  , xioInputEncoding            ::   String
+                                  , xioHttpHandler              ::   IOSArrow XmlTree XmlTree
+                                  , xioInputOptions             :: ! Attributes
+                                  , xioRedirect                 :: ! Bool
+                                  , xioProxy                    ::   String
+                                  }
+
+data XIOParseConfig     = XIOPcfg { xioMimeTypes                ::   MimeTypeTable
+                                  , xioMimeTypeFile             ::   String
+                                  , xioAcceptedMimeTypes        ::   [String]
+                                  , xioWarnings                 :: ! Bool
+                                  , xioRemoveWS                 :: ! Bool
+                                  , xioParseByMimeType          :: ! Bool
+                                  , xioParseHTML                :: ! Bool
+                                  , xioLowerCaseNames           :: ! Bool
+                                  , xioPreserveComment          :: ! Bool
+                                  , xioValidate                 :: ! Bool
+                                  , xioCheckNamespaces          :: ! Bool
+                                  , xioCanonicalize             :: ! Bool
+                                  , xioIgnoreNoneXmlContents    :: ! Bool
+                                  , xioTagSoup                  :: ! Bool
+                                  , xioTagSoupParser            ::   IOSArrow XmlTree XmlTree
+                                  }
+
+data XIOOutputConfig    = XIOOcfg { xioIndent                   :: ! Bool
+                                  , xioOutputEncoding           :: ! String
+                                  , xioOutputFmt                :: ! XIOXoutConfig
+                                  , xioXmlPi                    :: ! Bool
+                                  , xioNoEmptyElemFor           :: ! [String]
+                                  , xioAddDefaultDTD            :: ! Bool
+                                  , xioTextMode                 :: ! Bool
+                                  , xioShowTree                 :: ! Bool
+                                  , xioShowHaskell              :: ! Bool
+                                  }
+data XIOXoutConfig      = XMLoutput | XHTMLoutput | HTMLoutput | PLAINoutput
+                          deriving (Eq)
+
+data XIORelaxConfig     = XIORxc  { xioRelaxValidate            :: ! Bool
+                                  , xioRelaxSchema              ::   String
+                                  , xioRelaxCheckRestr          :: ! Bool
+                                  , xioRelaxValidateExtRef      :: ! Bool
+                                  , xioRelaxValidateInclude     :: ! Bool
+                                  , xioRelaxCollectErrors       :: ! Bool
+                                  , xioRelaxNoOfErrors          :: ! Int
+                                  , xioRelaxDefineId            :: ! Int
+                                  , xioRelaxAttrList            ::   AssocList String XmlTrees
+				  , xioRelaxValidator           ::   IOSArrow XmlTree XmlTree
+                                  }
+
+data XIOCacheConfig     = XIOCch  { xioBinaryCompression        ::   CompressionFct
+                                  , xioBinaryDeCompression      ::   DeCompressionFct
+                                  , xioWithCache                :: ! Bool
+                                  , xioCacheDir                 :: ! String
+                                  , xioDocumentAge              :: ! Int
+                                  , xioCache404Err              :: ! Bool
+                                  , xioCacheRead                ::   String -> IOSArrow XmlTree XmlTree
+                                  }
+
+type CompressionFct     = ByteString -> ByteString
+type DeCompressionFct   = ByteString -> ByteString
+
+type SysConfig                  = XIOSysState -> XIOSysState
+type SysConfigList              = [SysConfig]
+
+-- ----------------------------------------
+
+theSysState                     :: Selector (XIOState us) XIOSysState
+theSysState                     = S { getS = xioSysState
+                                    , setS = \ x s -> s { xioSysState = x}
+                                    }
+
+theUserState                    :: Selector (XIOState us) us
+theUserState                    = S { getS = xioUserState
+                                    , setS = \ x s -> s { xioUserState = x}
+                                    }
+
+-- ----------------------------------------
+
+theSysWriter                    :: Selector XIOSysState XIOSysWriter
+theSysWriter                    = S { getS = xioSysWriter
+                                    , setS = \ x s -> s { xioSysWriter = x}
+                                    }
+
+theErrorMsgList                 :: Selector XIOSysState XmlTrees
+theErrorMsgList                 = theSysWriter
+                                  >>>
+                                  S { getS = xioErrorMsgList
+                                    , setS = \ x s -> s { xioErrorMsgList = x }
+                                    }
+
+-- ----------------------------------------
+
+theSysEnv                       :: Selector XIOSysState XIOSysEnv
+theSysEnv                       = S { getS = xioSysEnv
+                                    , setS = \ x s -> s { xioSysEnv = x}
+                                    }
+
+theInputConfig                  :: Selector XIOSysState XIOInputConfig
+theInputConfig                  = theSysEnv
+                                  >>>
+                                  S { getS = xioInputConfig
+                                    , setS = \ x s -> s { xioInputConfig = x}
+                                    }
+
+theStrictInput                  :: Selector XIOSysState Bool
+theStrictInput                  = theInputConfig
+                                  >>>
+                                  S { getS = xioStrictInput
+                                    , setS = \ x s -> s { xioStrictInput = x}
+                                    }
+
+theEncodingErrors               :: Selector XIOSysState Bool
+theEncodingErrors               = theInputConfig
+                                  >>>
+                                  S { getS = xioEncodingErrors
+                                    , setS = \ x s -> s { xioEncodingErrors = x}
+                                    }
+
+theInputEncoding                :: Selector XIOSysState String
+theInputEncoding                = theInputConfig
+                                  >>>
+                                  S { getS = xioInputEncoding
+                                    , setS = \ x s -> s { xioInputEncoding = x}
+                                    }
+
+theHttpHandler                  :: Selector XIOSysState (IOSArrow XmlTree XmlTree)
+theHttpHandler                  = theInputConfig
+                                  >>>
+                                  S { getS = xioHttpHandler
+                                    , setS = \ x s -> s { xioHttpHandler = x}
+                                    }
+
+theInputOptions                 :: Selector XIOSysState Attributes
+theInputOptions                 = theInputConfig
+                                  >>>
+                                  S { getS = xioInputOptions
+                                    , setS = \ x s -> s { xioInputOptions = x}
+                                    }
+
+theRedirect                     :: Selector XIOSysState Bool
+theRedirect                     = theInputConfig
+                                  >>>
+                                  S { getS = xioRedirect
+                                    , setS = \ x s -> s { xioRedirect = x}
+                                    }
+
+theProxy                        :: Selector XIOSysState String
+theProxy                        = theInputConfig
+                                  >>>
+                                  S { getS = xioProxy
+                                    , setS = \ x s -> s { xioProxy = x}
+                                    }
+
+-- ----------------------------------------
+
+theOutputConfig                 :: Selector XIOSysState XIOOutputConfig
+theOutputConfig                 = theSysEnv
+                                  >>>
+                                  S { getS = xioOutputConfig
+                                    , setS = \ x s -> s { xioOutputConfig = x}
+                                    }
+
+theIndent                       :: Selector XIOSysState Bool
+theIndent                       = theOutputConfig
+                                  >>>
+                                  S { getS = xioIndent
+                                    , setS = \ x s -> s { xioIndent = x}
+                                    }
+
+theOutputEncoding               :: Selector XIOSysState String
+theOutputEncoding               = theOutputConfig
+                                  >>>
+                                  S { getS = xioOutputEncoding
+                                    , setS = \ x s -> s { xioOutputEncoding = x}
+                                    }
+
+theOutputFmt                    :: Selector XIOSysState XIOXoutConfig
+theOutputFmt                    = theOutputConfig
+                                  >>>
+                                  S { getS = xioOutputFmt
+                                    , setS = \ x s -> s { xioOutputFmt = x}
+                                    }
+
+theXmlPi                        :: Selector XIOSysState Bool
+theXmlPi                        = theOutputConfig
+                                  >>>
+                                  S { getS = xioXmlPi
+                                    , setS = \ x s -> s { xioXmlPi = x}
+                                    }
+
+theNoEmptyElemFor               :: Selector XIOSysState [String]
+theNoEmptyElemFor               = theOutputConfig
+                                  >>>
+                                  S { getS = xioNoEmptyElemFor
+                                    , setS = \ x s -> s { xioNoEmptyElemFor = x}
+                                    }
+
+theAddDefaultDTD                :: Selector XIOSysState Bool
+theAddDefaultDTD                = theOutputConfig
+                                  >>>
+                                  S { getS = xioAddDefaultDTD
+                                    , setS = \ x s -> s { xioAddDefaultDTD = x}
+                                    }
+
+theTextMode                     :: Selector XIOSysState Bool
+theTextMode                     = theOutputConfig
+                                  >>>
+                                  S { getS = xioTextMode
+                                    , setS = \ x s -> s { xioTextMode = x}
+                                    }
+
+theShowTree                     :: Selector XIOSysState Bool
+theShowTree                     = theOutputConfig
+                                  >>>
+                                  S { getS = xioShowTree
+                                    , setS = \ x s -> s { xioShowTree = x}
+                                    }
+
+theShowHaskell                  :: Selector XIOSysState Bool
+theShowHaskell                  = theOutputConfig
+                                  >>>
+                                  S { getS = xioShowHaskell
+                                    , setS = \ x s -> s { xioShowHaskell = x}
+                                    }
+
+-- ----------------------------------------
+
+theRelaxConfig                  :: Selector XIOSysState XIORelaxConfig
+theRelaxConfig                  = theSysEnv
+                                  >>>
+                                  S { getS = xioRelaxConfig
+                                    , setS = \ x s -> s { xioRelaxConfig = x}
+                                    }
+
+theRelaxValidate                :: Selector XIOSysState Bool
+theRelaxValidate                = theRelaxConfig
+                                  >>>
+                                  S { getS = xioRelaxValidate
+                                    , setS = \ x s -> s { xioRelaxValidate = x}
+                                    }
+
+theRelaxSchema                  :: Selector XIOSysState String
+theRelaxSchema                  = theRelaxConfig
+                                  >>>
+                                  S { getS = xioRelaxSchema
+                                    , setS = \ x s -> s { xioRelaxSchema = x}
+                                    }
+
+theRelaxCheckRestr              :: Selector XIOSysState Bool
+theRelaxCheckRestr              = theRelaxConfig
+                                  >>>
+                                  S { getS = xioRelaxCheckRestr
+                                    , setS = \ x s -> s { xioRelaxCheckRestr = x}
+                                    }
+
+theRelaxValidateExtRef          :: Selector XIOSysState Bool
+theRelaxValidateExtRef          = theRelaxConfig
+                                  >>>
+                                  S { getS = xioRelaxValidateExtRef
+                                    , setS = \ x s -> s { xioRelaxValidateExtRef = x}
+                                    }
+
+theRelaxValidateInclude         :: Selector XIOSysState Bool
+theRelaxValidateInclude         = theRelaxConfig
+                                  >>>
+                                  S { getS = xioRelaxValidateInclude
+                                    , setS = \ x s -> s { xioRelaxValidateInclude = x}
+                                    }
+
+theRelaxCollectErrors           :: Selector XIOSysState Bool
+theRelaxCollectErrors           = theRelaxConfig
+                                  >>>
+                                  S { getS = xioRelaxCollectErrors
+                                    , setS = \ x s -> s { xioRelaxCollectErrors = x}
+                                    }
+
+theRelaxNoOfErrors              :: Selector XIOSysState Int
+theRelaxNoOfErrors              = theRelaxConfig
+                                  >>>
+                                  S { getS = xioRelaxNoOfErrors
+                                    , setS = \ x s -> s { xioRelaxNoOfErrors = x}
+                                    }
+
+theRelaxDefineId                :: Selector XIOSysState Int
+theRelaxDefineId                = theRelaxConfig
+                                  >>>
+                                  S { getS = xioRelaxDefineId
+                                    , setS = \ x s -> s { xioRelaxDefineId = x}
+                                    }
+
+theRelaxAttrList                :: Selector XIOSysState (AssocList String XmlTrees)
+theRelaxAttrList                = theRelaxConfig
+                                  >>>
+                                  S { getS = xioRelaxAttrList
+                                    , setS = \ x s -> s { xioRelaxAttrList = x}
+                                    }
+
+theRelaxValidator                :: Selector XIOSysState (IOSArrow XmlTree XmlTree)
+theRelaxValidator                = theRelaxConfig
+                                   >>>
+                                   S { getS = xioRelaxValidator
+                                     , setS = \ x s -> s { xioRelaxValidator = x}
+                                     }
+
+-- ----------------------------------------
+
+theParseConfig                  :: Selector XIOSysState XIOParseConfig
+theParseConfig                  = theSysEnv
+                                  >>>
+                                  S { getS = xioParseConfig
+                                    , setS = \ x s -> s { xioParseConfig = x}
+                                    }
+
+theErrorStatus                  :: Selector XIOSysState Int
+theErrorStatus                  = theSysEnv
+                                  >>>
+                                  S { getS = xioErrorStatus
+                                    , setS = \ x s -> s { xioErrorStatus = x }
+                                    }
+
+theErrorMsgHandler              :: Selector XIOSysState (String -> IO ())
+theErrorMsgHandler              = theSysEnv
+                                  >>>
+                                  S { getS = xioErrorMsgHandler
+                                    , setS = \ x s -> s { xioErrorMsgHandler = x }
+                                    }
+
+theErrorMsgCollect              :: Selector XIOSysState Bool
+theErrorMsgCollect              = theSysEnv
+                                  >>>
+                                  S { getS = xioErrorMsgCollect
+                                    , setS = \ x s -> s { xioErrorMsgCollect = x }
+                                    }
+
+theBaseURI                      :: Selector XIOSysState String
+theBaseURI                      = theSysEnv
+                                  >>>
+                                  S { getS = xioBaseURI
+                                    , setS = \ x s -> s { xioBaseURI = x }
+                                    }
+
+theDefaultBaseURI               :: Selector XIOSysState String
+theDefaultBaseURI               = theSysEnv
+                                  >>>
+                                  S { getS = xioDefaultBaseURI
+                                    , setS = \ x s -> s { xioDefaultBaseURI = x }
+                                    }
+
+theTraceLevel                   :: Selector XIOSysState Int
+theTraceLevel                   = theSysEnv
+                                  >>>
+                                  S { getS = xioTraceLevel
+                                    , setS = \ x s -> s { xioTraceLevel = x }
+                                    }
+
+theTraceCmd                     :: Selector XIOSysState (Int -> String -> IO ())
+theTraceCmd                     = theSysEnv
+                                  >>>
+                                  S { getS = xioTraceCmd
+                                    , setS = \ x s -> s { xioTraceCmd = x }
+                                    }
+
+theTrace                        :: Selector XIOSysState (Int, Int -> String -> IO ())
+theTrace                        = theTraceLevel .&&&. theTraceCmd
+
+theAttrList                     :: Selector XIOSysState Attributes
+theAttrList                     = theSysEnv
+                                  >>>
+                                  S { getS = xioAttrList
+                                    , setS = \ x s -> s { xioAttrList = x }
+                                    }
+
+theMimeTypes                    :: Selector XIOSysState MimeTypeTable
+theMimeTypes                    = theParseConfig
+                                  >>>
+                                  S { getS = xioMimeTypes
+                                    , setS = \ x s -> s { xioMimeTypes = x }
+                                    }
+
+theMimeTypeFile                 :: Selector XIOSysState String
+theMimeTypeFile                 = theParseConfig
+                                  >>>
+                                  S { getS = xioMimeTypeFile
+                                    , setS = \ x s -> s { xioMimeTypeFile = x }
+                                    }
+
+theAcceptedMimeTypes            :: Selector XIOSysState [String]
+theAcceptedMimeTypes            = theParseConfig
+                                  >>>
+                                  S { getS = xioAcceptedMimeTypes
+                                    , setS = \ x s -> s { xioAcceptedMimeTypes = x }
+                                    }
+
+theWarnings                     :: Selector XIOSysState Bool
+theWarnings                     = theParseConfig
+                                  >>>
+                                  S { getS = xioWarnings
+                                    , setS = \ x s -> s { xioWarnings = x }
+                                    }
+
+theRemoveWS                     :: Selector XIOSysState Bool
+theRemoveWS                     = theParseConfig
+                                  >>>
+                                  S { getS = xioRemoveWS
+                                    , setS = \ x s -> s { xioRemoveWS = x }
+                                    }
+
+thePreserveComment              :: Selector XIOSysState Bool
+thePreserveComment              = theParseConfig
+                                  >>>
+                                  S { getS = xioPreserveComment
+                                    , setS = \ x s -> s { xioPreserveComment = x }
+                                    }
+
+theParseByMimeType              :: Selector XIOSysState Bool
+theParseByMimeType              = theParseConfig
+                                  >>>
+                                  S { getS = xioParseByMimeType
+                                    , setS = \ x s -> s { xioParseByMimeType = x }
+                                    }
+
+theParseHTML                    :: Selector XIOSysState Bool
+theParseHTML                    = theParseConfig
+                                  >>>
+                                  S { getS = xioParseHTML
+                                    , setS = \ x s -> s { xioParseHTML = x }
+                                    }
+
+theLowerCaseNames               :: Selector XIOSysState Bool
+theLowerCaseNames               = theParseConfig
+                                  >>>
+                                  S { getS = xioLowerCaseNames
+                                    , setS = \ x s -> s { xioLowerCaseNames = x }
+                                    }
+
+theValidate                     :: Selector XIOSysState Bool
+theValidate                     = theParseConfig
+                                  >>>
+                                  S { getS = xioValidate
+                                    , setS = \ x s -> s { xioValidate = x }
+                                    }
+
+theCheckNamespaces              :: Selector XIOSysState Bool
+theCheckNamespaces              = theParseConfig
+                                  >>>
+                                  S { getS = xioCheckNamespaces
+                                    , setS = \ x s -> s { xioCheckNamespaces = x }
+                                    }
+
+theCanonicalize                 :: Selector XIOSysState Bool
+theCanonicalize                 = theParseConfig
+                                  >>>
+                                  S { getS = xioCanonicalize
+                                    , setS = \ x s -> s { xioCanonicalize = x }
+                                    }
+
+theIgnoreNoneXmlContents        :: Selector XIOSysState Bool
+theIgnoreNoneXmlContents        = theParseConfig
+                                  >>>
+                                  S { getS = xioIgnoreNoneXmlContents
+                                    , setS = \ x s -> s { xioIgnoreNoneXmlContents = x }
+                                    }
+
+theTagSoup                      :: Selector XIOSysState Bool
+theTagSoup                      = theParseConfig
+                                  >>>
+                                  S { getS = xioTagSoup
+                                    , setS = \ x s -> s { xioTagSoup = x }
+                                    }
+
+theTagSoupParser                :: Selector XIOSysState (IOSArrow XmlTree XmlTree)
+theTagSoupParser                = theParseConfig
+                                  >>>
+                                  S { getS = xioTagSoupParser
+                                    , setS = \ x s -> s { xioTagSoupParser = x }
+                                    }
+
+-- ----------------------------------------
+
+theCacheConfig                  :: Selector XIOSysState XIOCacheConfig
+theCacheConfig                  = theSysEnv
+                                  >>>
+                                  S { getS = xioCacheConfig
+                                    , setS = \ x s -> s { xioCacheConfig = x}
+                                    }
+
+theBinaryCompression            :: Selector XIOSysState (ByteString -> ByteString)
+theBinaryCompression            = theCacheConfig
+                                  >>>
+                                  S { getS = xioBinaryCompression
+                                    , setS = \ x s -> s { xioBinaryCompression = x}
+                                    }
+
+theBinaryDeCompression          :: Selector XIOSysState (ByteString -> ByteString)
+theBinaryDeCompression          = theCacheConfig
+                                  >>>
+                                  S { getS = xioBinaryDeCompression
+                                    , setS = \ x s -> s { xioBinaryDeCompression = x}
+                                    }
+
+theWithCache                    :: Selector XIOSysState Bool
+theWithCache                    = theCacheConfig
+                                  >>>
+                                  S { getS = xioWithCache
+                                    , setS = \ x s -> s { xioWithCache = x}
+                                    }
+
+theCacheDir                     :: Selector XIOSysState String
+theCacheDir                     = theCacheConfig
+                                  >>>
+                                  S { getS = xioCacheDir
+                                    , setS = \ x s -> s { xioCacheDir = x}
+                                    }
+
+theDocumentAge                  :: Selector XIOSysState Int
+theDocumentAge                  = theCacheConfig
+                                  >>>
+                                  S { getS = xioDocumentAge
+                                    , setS = \ x s -> s { xioDocumentAge = x}
+                                    }
+
+theCache404Err                  :: Selector XIOSysState Bool
+theCache404Err                  = theCacheConfig
+                                  >>>
+                                  S { getS = xioCache404Err
+                                    , setS = \ x s -> s { xioCache404Err = x}
+                                    }
+
+theCacheRead                    :: Selector XIOSysState (String -> IOSArrow XmlTree XmlTree)
+theCacheRead                    = theCacheConfig
+                                  >>>
+                                  S { getS = xioCacheRead
+                                    , setS = \ x s -> s { xioCacheRead = x}
+                                    }
+
+-- ------------------------------------------------------------
+
+getSysVar                       :: Selector XIOSysState c -> IOStateArrow s b c
+getSysVar sel                   = IOSLA $ \ s _x ->
+                                  return (s, (:[]) . getS (theSysState >>> sel) $ s)
+
+setSysVar                       :: Selector XIOSysState c -> IOStateArrow s c c
+setSysVar sel                   = (\ v -> configSysVar $ setS sel v) $< this
+
+chgSysVar                       :: Selector XIOSysState c -> (b -> c -> c) -> IOStateArrow s b b
+chgSysVar sel op                = (\ v -> configSysVar $ chgS sel (op v)) $< this
+
+configSysVar                    :: SysConfig -> IOStateArrow s c c
+configSysVar cf                 = IOSLA $ \ s v ->
+                                  return (chgS theSysState cf s, [v])
+
+configSysVars                   :: SysConfigList -> IOStateArrow s c c
+configSysVars cfs               = configSysVar $ foldr (>>>) id $ cfs
+
+localSysVar                     :: Selector XIOSysState c -> IOStateArrow s a b -> IOStateArrow s a b
+localSysVar sel f               = IOSLA $ \ s0 v ->
+                                  let sel' = theSysState >>> sel in
+                                  let c0   = getS sel' s0 in
+                                  do
+                                  (s1, res) <- runIOSLA f s0 v
+                                  return (setS sel' c0 s1, res)
+
+localSysEnv                     :: IOStateArrow s a b -> IOStateArrow s a b
+localSysEnv                     = localSysVar theSysEnv
+
+incrSysVar                      :: Selector XIOSysState Int -> IOStateArrow s a Int
+incrSysVar cnt                  = getSysVar cnt
+                                  >>>
+                                  arr (+1)
+                                  >>>
+                                  setSysVar cnt
+                                  >>>
+                                  arr (\ x -> x - 1)
+
+-- ------------------------------
+
+-- | store a string in global state under a given attribute name
+
+setSysAttr              :: String -> IOStateArrow s String String
+setSysAttr n            = chgSysVar theAttrList (addEntry n)
+
+-- | remove an entry in global state, arrow input remains unchanged
+
+unsetSysAttr            :: String -> IOStateArrow s b b
+unsetSysAttr n            = configSysVar $ chgS theAttrList (delEntry n)
+
+-- | read an attribute value from global state
+
+getSysAttr                :: String -> IOStateArrow s b String
+getSysAttr n              = getSysVar theAttrList
+                          >>^
+                          lookup1 n
+
+-- | read all attributes from global state
+
+getAllSysAttrs            :: IOStateArrow s b Attributes
+getAllSysAttrs            = getSysVar theAttrList
+
+
+setSysAttrString        :: String -> String -> IOStateArrow s b b
+setSysAttrString n v    = perform ( constA v
+                                    >>>
+                                    setSysAttr n
+                                  )
+
+-- | store an int value in global state
+
+setSysAttrInt           :: String -> Int -> IOStateArrow s b b
+setSysAttrInt n v       = setSysAttrString n (show v)
+
+-- | read an int value from global state
+--
+-- > getSysAttrInt 0 myIntAttr
+
+getSysAttrInt           :: Int -> String -> IOStateArrow s b Int
+getSysAttrInt def n     = getSysAttr n
+                          >>^
+                          toInt def
+
+toInt                   :: Int -> String -> Int
+toInt def s
+        | not (null s)
+          &&
+          all isDigit s = read s
+        | otherwise     = def
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Arrow/XmlState/URIHandling.hs b/src/Text/XML/HXT/Arrow/XmlState/URIHandling.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Arrow/XmlState/URIHandling.hs
@@ -0,0 +1,239 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Arrow.XmlState.URIHandling
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   the basic state arrows for URI handling
+
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Arrow.XmlState.URIHandling
+where
+
+import Control.Arrow                            -- arrow classes
+import Control.Arrow.ArrowList
+import Control.Arrow.ArrowIf
+
+import Control.Arrow.ArrowIO
+
+import Control.Monad                    ( mzero
+                                        , mplus )
+
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.Arrow.XmlState.TypeDefs
+import Text.XML.HXT.Arrow.XmlState.TraceHandling
+
+import Data.Maybe
+
+import Network.URI                      ( URI
+                                        , escapeURIChar
+                                        , isUnescapedInURI
+                                        , nonStrictRelativeTo
+                                        , parseURIReference
+                                        , uriAuthority
+                                        , uriFragment
+                                        , uriPath
+                                        , uriPort
+                                        , uriQuery
+                                        , uriRegName
+                                        , uriScheme
+                                        , uriUserInfo
+                                        )
+
+import System.Directory                 ( getCurrentDirectory )
+
+-- ------------------------------------------------------------
+
+-- | set the base URI of a document, used e.g. for reading includes, e.g. external entities,
+-- the input must be an absolute URI
+
+setBaseURI              :: IOStateArrow s String String
+setBaseURI              = setSysVar theBaseURI
+                          >>>
+                          traceValue 2 (("setBaseURI: new base URI is " ++) . show)
+
+-- | read the base URI from the globale state
+
+getBaseURI              :: IOStateArrow s b String
+getBaseURI              = getSysVar theBaseURI
+                          >>>
+                          ( ( getDefaultBaseURI
+                              >>>
+                              setBaseURI
+                              >>>
+                              getBaseURI
+                            )
+                            `when`
+                            isA null                                -- set and get it, if not yet done
+                          )
+
+-- | change the base URI with a possibly relative URI, can be used for
+-- evaluating the xml:base attribute. Returns the new absolute base URI.
+-- Fails, if input is not parsable with parseURIReference
+--
+-- see also: 'setBaseURI', 'mkAbsURI'
+
+changeBaseURI           :: IOStateArrow s String String
+changeBaseURI           = mkAbsURI >>> setBaseURI
+
+-- | set the default base URI, if parameter is null, the system base (@ file:\/\/\/\<cwd\>\/ @) is used,
+-- else the parameter, must be called before any document is read
+
+setDefaultBaseURI       :: String -> IOStateArrow s b String
+setDefaultBaseURI base  = ( if null base
+                            then arrIO getDir
+                            else constA base
+                          )
+                          >>>
+                          setSysVar theDefaultBaseURI
+                          >>>
+                          traceValue 2 (("setDefaultBaseURI: new default base URI is " ++) . show)
+    where
+    getDir _            = do
+                          cwd <- getCurrentDirectory
+                          return ("file://" ++ normalize cwd ++ "/")
+
+    -- under Windows getCurrentDirectory returns something like: "c:\path\to\file"
+    -- backslaches are not allowed in URIs and paths must start with a /
+    -- so this is transformed into "/c:/path/to/file"
+
+    normalize wd'@(d : ':' : _)
+        | d `elem` ['A'..'Z']
+          ||
+          d `elem` ['a'..'z']
+                        = '/' : concatMap win32ToUriChar wd'
+    normalize wd'       = concatMap escapeNonUriChar wd'
+
+    win32ToUriChar '\\' = "/"
+    win32ToUriChar c    = escapeNonUriChar c
+
+    escapeNonUriChar c  = escapeURIChar isUnescapedInURI c   -- from Network.URI
+
+
+-- | get the default base URI
+
+getDefaultBaseURI       :: IOStateArrow s b String
+getDefaultBaseURI       = getSysVar theDefaultBaseURI            -- read default uri in system  state
+                          >>>
+                          ( ( setDefaultBaseURI ""                  -- set the default uri in system state
+                              >>>
+                              getDefaultBaseURI
+                            )
+                            `when` isA null
+                          )                                         -- when uri not yet set
+
+-- ------------------------------------------------------------
+
+-- | remember base uri, run an arrow and restore the base URI, used with external entity substitution
+
+runInLocalURIContext    :: IOStateArrow s b c -> IOStateArrow s b c
+runInLocalURIContext f  = localSysVar theBaseURI f
+
+-- ----------------------------------------------------------
+
+-- | parse a URI reference, in case of a failure,
+-- try to escape unescaped chars, convert backslashes to slashes for windows paths,
+-- and try parsing again
+
+parseURIReference'      :: String -> Maybe URI
+parseURIReference' uri
+    = parseURIReference uri
+      `mplus`
+      ( if unesc
+        then parseURIReference uri'
+        else mzero
+      )
+    where
+    unesc       = not . all isUnescapedInURI $ uri
+
+    escape '\\' = "/"
+    escape c    = escapeURIChar isUnescapedInURI c
+
+    uri'        = concatMap escape uri
+
+-- | compute the absolut URI for a given URI and a base URI
+
+expandURIString :: String -> String -> Maybe String
+expandURIString uri base
+    = do
+      base' <- parseURIReference' base
+      uri'  <- parseURIReference' uri
+      abs'  <- nonStrictRelativeTo uri' base'
+      return $ show abs'
+
+-- | arrow variant of 'expandURIString', fails if 'expandURIString' returns Nothing
+
+expandURI               :: ArrowXml a => a (String, String) String
+expandURI
+    = arrL (maybeToList . uncurry expandURIString)
+
+-- | arrow for expanding an input URI into an absolute URI using global base URI, fails if input is not a legal URI
+
+mkAbsURI                :: IOStateArrow s String String
+mkAbsURI
+    = ( this &&& getBaseURI ) >>> expandURI
+
+-- | arrow for selecting the scheme (protocol) of the URI, fails if input is not a legal URI.
+--
+-- See Network.URI for URI components
+
+getSchemeFromURI        :: ArrowList a => a String String
+getSchemeFromURI        = getPartFromURI scheme
+    where
+    scheme = init . uriScheme
+
+-- | arrow for selecting the registered name (host) of the URI, fails if input is not a legal URI
+
+getRegNameFromURI       :: ArrowList a => a String String
+getRegNameFromURI       = getPartFromURI host
+    where
+    host = maybe "" uriRegName . uriAuthority
+
+-- | arrow for selecting the port number of the URI without leading \':\', fails if input is not a legal URI
+
+getPortFromURI          :: ArrowList a => a String String
+getPortFromURI          = getPartFromURI port
+    where
+    port = dropWhile (==':') . maybe "" uriPort . uriAuthority
+
+-- | arrow for selecting the user info of the URI without trailing \'\@\', fails if input is not a legal URI
+
+getUserInfoFromURI              :: ArrowList a => a String String
+getUserInfoFromURI              = getPartFromURI ui
+    where
+    ui = reverse . dropWhile (=='@') . reverse . maybe "" uriUserInfo . uriAuthority
+
+-- | arrow for computing the path component of an URI, fails if input is not a legal URI
+
+getPathFromURI          :: ArrowList a => a String String
+getPathFromURI          = getPartFromURI uriPath
+
+-- | arrow for computing the query component of an URI, fails if input is not a legal URI
+
+getQueryFromURI         :: ArrowList a => a String String
+getQueryFromURI         = getPartFromURI uriQuery
+
+-- | arrow for computing the fragment component of an URI, fails if input is not a legal URI
+
+getFragmentFromURI      :: ArrowList a => a String String
+getFragmentFromURI      = getPartFromURI uriFragment
+
+-- | arrow for computing the path component of an URI, fails if input is not a legal URI
+
+getPartFromURI          :: ArrowList a => (URI -> String) -> a String String
+getPartFromURI sel
+    = arrL (maybeToList . getPart)
+      where
+      getPart s = do
+                  uri <- parseURIReference' s
+                  return (sel uri)
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Core.hs b/src/Text/XML/HXT/Core.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/Core.hs
@@ -0,0 +1,69 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.Core
+   Copyright  : Copyright (C) 2006-2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   The HXT arrow interface
+
+   The application programming interface to the arrow modules of the Haskell XML Toolbox.
+   This module exports all important arrows for input, output, parsing, validating and transforming XML.
+   It also exports all basic datatypes and functions of the toolbox.
+
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.Core
+    ( module Control.Arrow.ListArrows
+
+    , module Text.XML.HXT.DOM.Interface
+
+    , module Text.XML.HXT.Arrow.XmlArrow
+    , module Text.XML.HXT.Arrow.XmlState
+
+    , module Text.XML.HXT.Arrow.DocumentInput
+    , module Text.XML.HXT.Arrow.DocumentOutput
+    , module Text.XML.HXT.Arrow.Edit
+    , module Text.XML.HXT.Arrow.GeneralEntitySubstitution
+    , module Text.XML.HXT.Arrow.Namespace
+    , module Text.XML.HXT.Arrow.Pickle
+    , module Text.XML.HXT.Arrow.ProcessDocument
+    , module Text.XML.HXT.Arrow.ReadDocument
+    , module Text.XML.HXT.Arrow.WriteDocument
+    , module Text.XML.HXT.Arrow.Binary
+    , module Text.XML.HXT.Arrow.XmlOptions
+
+    , module Text.XML.HXT.Version
+    )
+where
+
+import Control.Arrow.ListArrows                 -- arrow classes
+
+import Data.Atom ()                             -- import this explicitly
+
+import Text.XML.HXT.DOM.Interface
+
+import Text.XML.HXT.Arrow.DocumentInput
+import Text.XML.HXT.Arrow.DocumentOutput
+import Text.XML.HXT.Arrow.Edit
+import Text.XML.HXT.Arrow.GeneralEntitySubstitution
+import Text.XML.HXT.Arrow.Namespace
+import Text.XML.HXT.Arrow.Pickle
+import Text.XML.HXT.Arrow.ProcessDocument
+import Text.XML.HXT.Arrow.ReadDocument
+import Text.XML.HXT.Arrow.WriteDocument
+import Text.XML.HXT.Arrow.XmlArrow
+import Text.XML.HXT.Arrow.XmlOptions
+import Text.XML.HXT.Arrow.XmlState
+import Text.XML.HXT.Arrow.XmlRegex ()           -- import this explicitly
+import Text.XML.HXT.Arrow.Binary
+
+import Text.XML.HXT.Version
+
+-- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/DOM/Interface.hs b/src/Text/XML/HXT/DOM/Interface.hs
--- a/src/Text/XML/HXT/DOM/Interface.hs
+++ b/src/Text/XML/HXT/DOM/Interface.hs
@@ -21,16 +21,15 @@
     ( module Text.XML.HXT.DOM.XmlKeywords
     , module Text.XML.HXT.DOM.TypeDefs
     , module Text.XML.HXT.DOM.Util
-    , module Text.XML.HXT.DOM.XmlOptions
     , module Text.XML.HXT.DOM.MimeTypes
+    , module Data.String.EncodingNames
     )
 where
 
 import Text.XML.HXT.DOM.XmlKeywords             -- constants
 import Text.XML.HXT.DOM.TypeDefs                -- XML Tree types
 import Text.XML.HXT.DOM.Util
-import Text.XML.HXT.DOM.XmlOptions              -- predefined options
 import Text.XML.HXT.DOM.MimeTypes               -- mime types related stuff
-
+import Data.String.EncodingNames                -- char encoding names for readDocument
 
 -- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/DOM/IsoLatinTables.hs b/src/Text/XML/HXT/DOM/IsoLatinTables.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/DOM/IsoLatinTables.hs
+++ /dev/null
@@ -1,719 +0,0 @@
-module Text.XML.HXT.DOM.IsoLatinTables
-where
-
-iso_8859_2      :: [(Char, Char)]
-iso_8859_2
-    = [ ('\161', '\260' )
-      , ('\162', '\728' )
-      , ('\163', '\321' )
-      , ('\165', '\317' )
-      , ('\166', '\346' )
-      , ('\169', '\352' )
-      , ('\170', '\350' )
-      , ('\171', '\356' )
-      , ('\172', '\377' )
-      , ('\174', '\381' )
-      , ('\175', '\379' )
-      , ('\177', '\261' )
-      , ('\178', '\731' )
-      , ('\179', '\322' )
-      , ('\181', '\318' )
-      , ('\182', '\347' )
-      , ('\183', '\711' )
-      , ('\185', '\353' )
-      , ('\186', '\351' )
-      , ('\187', '\357' )
-      , ('\188', '\378' )
-      , ('\189', '\733' )
-      , ('\190', '\382' )
-      , ('\191', '\380' )
-      , ('\192', '\340' )
-      , ('\195', '\258' )
-      , ('\197', '\313' )
-      , ('\198', '\262' )
-      , ('\200', '\268' )
-      , ('\202', '\280' )
-      , ('\204', '\282' )
-      , ('\207', '\270' )
-      , ('\208', '\272' )
-      , ('\209', '\323' )
-      , ('\210', '\327' )
-      , ('\213', '\336' )
-      , ('\216', '\344' )
-      , ('\217', '\366' )
-      , ('\219', '\368' )
-      , ('\222', '\354' )
-      , ('\224', '\341' )
-      , ('\227', '\259' )
-      , ('\229', '\314' )
-      , ('\230', '\263' )
-      , ('\232', '\269' )
-      , ('\234', '\281' )
-      , ('\236', '\283' )
-      , ('\239', '\271' )
-      , ('\240', '\273' )
-      , ('\241', '\324' )
-      , ('\242', '\328' )
-      , ('\245', '\337' )
-      , ('\248', '\345' )
-      , ('\249', '\367' )
-      , ('\251', '\369' )
-      , ('\254', '\355' )
-      , ('\255', '\729' )
-      ]
-
-iso_8859_3      :: [(Char, Char)]
-iso_8859_3
-    = [ ('\161', '\294' )
-      , ('\162', '\728' )
-      , ('\166', '\292' )
-      , ('\169', '\304' )
-      , ('\170', '\350' )
-      , ('\171', '\286' )
-      , ('\172', '\308' )
-      , ('\175', '\379' )
-      , ('\177', '\295' )
-      , ('\182', '\293' )
-      , ('\185', '\305' )
-      , ('\186', '\351' )
-      , ('\187', '\287' )
-      , ('\188', '\309' )
-      , ('\191', '\380' )
-      , ('\197', '\266' )
-      , ('\198', '\264' )
-      , ('\213', '\288' )
-      , ('\216', '\284' )
-      , ('\221', '\364' )
-      , ('\222', '\348' )
-      , ('\229', '\267' )
-      , ('\230', '\265' )
-      , ('\245', '\289' )
-      , ('\248', '\285' )
-      , ('\253', '\365' )
-      , ('\254', '\349' )
-      , ('\255', '\729' )
-      ]
-
-iso_8859_4      :: [(Char, Char)]
-iso_8859_4
-    = [ ('\161', '\260' )
-      , ('\162', '\312' )
-      , ('\163', '\342' )
-      , ('\165', '\296' )
-      , ('\166', '\315' )
-      , ('\169', '\352' )
-      , ('\170', '\274' )
-      , ('\171', '\290' )
-      , ('\172', '\358' )
-      , ('\174', '\381' )
-      , ('\177', '\261' )
-      , ('\178', '\731' )
-      , ('\179', '\343' )
-      , ('\181', '\297' )
-      , ('\182', '\316' )
-      , ('\183', '\711' )
-      , ('\185', '\353' )
-      , ('\186', '\275' )
-      , ('\187', '\291' )
-      , ('\188', '\359' )
-      , ('\189', '\330' )
-      , ('\190', '\382' )
-      , ('\191', '\331' )
-      , ('\192', '\256' )
-      , ('\199', '\302' )
-      , ('\200', '\268' )
-      , ('\202', '\280' )
-      , ('\204', '\278' )
-      , ('\207', '\298' )
-      , ('\208', '\272' )
-      , ('\209', '\325' )
-      , ('\210', '\332' )
-      , ('\211', '\310' )
-      , ('\217', '\370' )
-      , ('\221', '\360' )
-      , ('\222', '\362' )
-      , ('\224', '\257' )
-      , ('\231', '\303' )
-      , ('\232', '\269' )
-      , ('\234', '\281' )
-      , ('\236', '\279' )
-      , ('\239', '\299' )
-      , ('\240', '\273' )
-      , ('\241', '\326' )
-      , ('\242', '\333' )
-      , ('\243', '\311' )
-      , ('\249', '\371' )
-      , ('\253', '\361' )
-      , ('\254', '\363' )
-      , ('\255', '\729' )
-      ]
-
-iso_8859_5      :: [(Char, Char)]
-iso_8859_5
-    = [ ('\161', '\1025' )
-      , ('\162', '\1026' )
-      , ('\163', '\1027' )
-      , ('\164', '\1028' )
-      , ('\165', '\1029' )
-      , ('\166', '\1030' )
-      , ('\167', '\1031' )
-      , ('\168', '\1032' )
-      , ('\169', '\1033' )
-      , ('\170', '\1034' )
-      , ('\171', '\1035' )
-      , ('\172', '\1036' )
-      , ('\174', '\1038' )
-      , ('\175', '\1039' )
-      , ('\176', '\1040' )
-      , ('\177', '\1041' )
-      , ('\178', '\1042' )
-      , ('\179', '\1043' )
-      , ('\180', '\1044' )
-      , ('\181', '\1045' )
-      , ('\182', '\1046' )
-      , ('\183', '\1047' )
-      , ('\184', '\1048' )
-      , ('\185', '\1049' )
-      , ('\186', '\1050' )
-      , ('\187', '\1051' )
-      , ('\188', '\1052' )
-      , ('\189', '\1053' )
-      , ('\190', '\1054' )
-      , ('\191', '\1055' )
-      , ('\192', '\1056' )
-      , ('\193', '\1057' )
-      , ('\194', '\1058' )
-      , ('\195', '\1059' )
-      , ('\196', '\1060' )
-      , ('\197', '\1061' )
-      , ('\198', '\1062' )
-      , ('\199', '\1063' )
-      , ('\200', '\1064' )
-      , ('\201', '\1065' )
-      , ('\202', '\1066' )
-      , ('\203', '\1067' )
-      , ('\204', '\1068' )
-      , ('\205', '\1069' )
-      , ('\206', '\1070' )
-      , ('\207', '\1071' )
-      , ('\208', '\1072' )
-      , ('\209', '\1073' )
-      , ('\210', '\1074' )
-      , ('\211', '\1075' )
-      , ('\212', '\1076' )
-      , ('\213', '\1077' )
-      , ('\214', '\1078' )
-      , ('\215', '\1079' )
-      , ('\216', '\1080' )
-      , ('\217', '\1081' )
-      , ('\218', '\1082' )
-      , ('\219', '\1083' )
-      , ('\220', '\1084' )
-      , ('\221', '\1085' )
-      , ('\222', '\1086' )
-      , ('\223', '\1087' )
-      , ('\224', '\1088' )
-      , ('\225', '\1089' )
-      , ('\226', '\1090' )
-      , ('\227', '\1091' )
-      , ('\228', '\1092' )
-      , ('\229', '\1093' )
-      , ('\230', '\1094' )
-      , ('\231', '\1095' )
-      , ('\232', '\1096' )
-      , ('\233', '\1097' )
-      , ('\234', '\1098' )
-      , ('\235', '\1099' )
-      , ('\236', '\1100' )
-      , ('\237', '\1101' )
-      , ('\238', '\1102' )
-      , ('\239', '\1103' )
-      , ('\240', '\8470' )
-      , ('\241', '\1105' )
-      , ('\242', '\1106' )
-      , ('\243', '\1107' )
-      , ('\244', '\1108' )
-      , ('\245', '\1109' )
-      , ('\246', '\1110' )
-      , ('\247', '\1111' )
-      , ('\248', '\1112' )
-      , ('\249', '\1113' )
-      , ('\250', '\1114' )
-      , ('\251', '\1115' )
-      , ('\252', '\1116' )
-      , ('\253', '\167' )
-      , ('\254', '\1118' )
-      , ('\255', '\1119' )
-      ]
-
-iso_8859_6      :: [(Char, Char)]
-iso_8859_6
-    = [ ('\172', '\1548' )
-      , ('\187', '\1563' )
-      , ('\191', '\1567' )
-      , ('\193', '\1569' )
-      , ('\194', '\1570' )
-      , ('\195', '\1571' )
-      , ('\196', '\1572' )
-      , ('\197', '\1573' )
-      , ('\198', '\1574' )
-      , ('\199', '\1575' )
-      , ('\200', '\1576' )
-      , ('\201', '\1577' )
-      , ('\202', '\1578' )
-      , ('\203', '\1579' )
-      , ('\204', '\1580' )
-      , ('\205', '\1581' )
-      , ('\206', '\1582' )
-      , ('\207', '\1583' )
-      , ('\208', '\1584' )
-      , ('\209', '\1585' )
-      , ('\210', '\1586' )
-      , ('\211', '\1587' )
-      , ('\212', '\1588' )
-      , ('\213', '\1589' )
-      , ('\214', '\1590' )
-      , ('\215', '\1591' )
-      , ('\216', '\1592' )
-      , ('\217', '\1593' )
-      , ('\218', '\1594' )
-      , ('\224', '\1600' )
-      , ('\225', '\1601' )
-      , ('\226', '\1602' )
-      , ('\227', '\1603' )
-      , ('\228', '\1604' )
-      , ('\229', '\1605' )
-      , ('\230', '\1606' )
-      , ('\231', '\1607' )
-      , ('\232', '\1608' )
-      , ('\233', '\1609' )
-      , ('\234', '\1610' )
-      , ('\235', '\1611' )
-      , ('\236', '\1612' )
-      , ('\237', '\1613' )
-      , ('\238', '\1614' )
-      , ('\239', '\1615' )
-      , ('\240', '\1616' )
-      , ('\241', '\1617' )
-      , ('\242', '\1618' )
-      ]
-
-iso_8859_7      :: [(Char, Char)]
-iso_8859_7
-    = [ ('\161', '\8216' )
-      , ('\162', '\8217' )
-      , ('\164', '\8364' )
-      , ('\165', '\8367' )
-      , ('\170', '\890' )
-      , ('\175', '\8213' )
-      , ('\180', '\900' )
-      , ('\181', '\901' )
-      , ('\182', '\902' )
-      , ('\184', '\904' )
-      , ('\185', '\905' )
-      , ('\186', '\906' )
-      , ('\188', '\908' )
-      , ('\190', '\910' )
-      , ('\191', '\911' )
-      , ('\192', '\912' )
-      , ('\193', '\913' )
-      , ('\194', '\914' )
-      , ('\195', '\915' )
-      , ('\196', '\916' )
-      , ('\197', '\917' )
-      , ('\198', '\918' )
-      , ('\199', '\919' )
-      , ('\200', '\920' )
-      , ('\201', '\921' )
-      , ('\202', '\922' )
-      , ('\203', '\923' )
-      , ('\204', '\924' )
-      , ('\205', '\925' )
-      , ('\206', '\926' )
-      , ('\207', '\927' )
-      , ('\208', '\928' )
-      , ('\209', '\929' )
-      , ('\211', '\931' )
-      , ('\212', '\932' )
-      , ('\213', '\933' )
-      , ('\214', '\934' )
-      , ('\215', '\935' )
-      , ('\216', '\936' )
-      , ('\217', '\937' )
-      , ('\218', '\938' )
-      , ('\219', '\939' )
-      , ('\220', '\940' )
-      , ('\221', '\941' )
-      , ('\222', '\942' )
-      , ('\223', '\943' )
-      , ('\224', '\944' )
-      , ('\225', '\945' )
-      , ('\226', '\946' )
-      , ('\227', '\947' )
-      , ('\228', '\948' )
-      , ('\229', '\949' )
-      , ('\230', '\950' )
-      , ('\231', '\951' )
-      , ('\232', '\952' )
-      , ('\233', '\953' )
-      , ('\234', '\954' )
-      , ('\235', '\955' )
-      , ('\236', '\956' )
-      , ('\237', '\957' )
-      , ('\238', '\958' )
-      , ('\239', '\959' )
-      , ('\240', '\960' )
-      , ('\241', '\961' )
-      , ('\242', '\962' )
-      , ('\243', '\963' )
-      , ('\244', '\964' )
-      , ('\245', '\965' )
-      , ('\246', '\966' )
-      , ('\247', '\967' )
-      , ('\248', '\968' )
-      , ('\249', '\969' )
-      , ('\250', '\970' )
-      , ('\251', '\971' )
-      , ('\252', '\972' )
-      , ('\253', '\973' )
-      , ('\254', '\974' )
-      ]
-
-iso_8859_8      :: [(Char, Char)]
-iso_8859_8
-    = [ ('\170', '\215' )
-      , ('\186', '\247' )
-      , ('\223', '\8215' )
-      , ('\224', '\1488' )
-      , ('\225', '\1489' )
-      , ('\226', '\1490' )
-      , ('\227', '\1491' )
-      , ('\228', '\1492' )
-      , ('\229', '\1493' )
-      , ('\230', '\1494' )
-      , ('\231', '\1495' )
-      , ('\232', '\1496' )
-      , ('\233', '\1497' )
-      , ('\234', '\1498' )
-      , ('\235', '\1499' )
-      , ('\236', '\1500' )
-      , ('\237', '\1501' )
-      , ('\238', '\1502' )
-      , ('\239', '\1503' )
-      , ('\240', '\1504' )
-      , ('\241', '\1505' )
-      , ('\242', '\1506' )
-      , ('\243', '\1507' )
-      , ('\244', '\1508' )
-      , ('\245', '\1509' )
-      , ('\246', '\1510' )
-      , ('\247', '\1511' )
-      , ('\248', '\1512' )
-      , ('\249', '\1513' )
-      , ('\250', '\1514' )
-      , ('\253', '\8206' )
-      , ('\254', '\8207' )
-      ]
-
-iso_8859_9      :: [(Char, Char)]
-iso_8859_9
-    = [ ('\208', '\286' )
-      , ('\221', '\304' )
-      , ('\222', '\350' )
-      , ('\240', '\287' )
-      , ('\253', '\305' )
-      , ('\254', '\351' )
-      ]
-
-iso_8859_10     :: [(Char, Char)]
-iso_8859_10
-    = [ ('\161', '\260' )
-      , ('\162', '\274' )
-      , ('\163', '\290' )
-      , ('\164', '\298' )
-      , ('\165', '\296' )
-      , ('\166', '\310' )
-      , ('\168', '\315' )
-      , ('\169', '\272' )
-      , ('\170', '\352' )
-      , ('\171', '\358' )
-      , ('\172', '\381' )
-      , ('\174', '\362' )
-      , ('\175', '\330' )
-      , ('\177', '\261' )
-      , ('\178', '\275' )
-      , ('\179', '\291' )
-      , ('\180', '\299' )
-      , ('\181', '\297' )
-      , ('\182', '\311' )
-      , ('\184', '\316' )
-      , ('\185', '\273' )
-      , ('\186', '\353' )
-      , ('\187', '\359' )
-      , ('\188', '\382' )
-      , ('\189', '\8213' )
-      , ('\190', '\363' )
-      , ('\191', '\331' )
-      , ('\192', '\256' )
-      , ('\199', '\302' )
-      , ('\200', '\268' )
-      , ('\202', '\280' )
-      , ('\204', '\278' )
-      , ('\209', '\325' )
-      , ('\210', '\332' )
-      , ('\215', '\360' )
-      , ('\217', '\370' )
-      , ('\224', '\257' )
-      , ('\231', '\303' )
-      , ('\232', '\269' )
-      , ('\234', '\281' )
-      , ('\236', '\279' )
-      , ('\241', '\326' )
-      , ('\242', '\333' )
-      , ('\247', '\361' )
-      , ('\249', '\371' )
-      , ('\255', '\312' )
-      ]
-
-iso_8859_11     :: [(Char, Char)]
-iso_8859_11
-    = [ ('\161', '\3585' )
-      , ('\162', '\3586' )
-      , ('\163', '\3587' )
-      , ('\164', '\3588' )
-      , ('\165', '\3589' )
-      , ('\166', '\3590' )
-      , ('\167', '\3591' )
-      , ('\168', '\3592' )
-      , ('\169', '\3593' )
-      , ('\170', '\3594' )
-      , ('\171', '\3595' )
-      , ('\172', '\3596' )
-      , ('\173', '\3597' )
-      , ('\174', '\3598' )
-      , ('\175', '\3599' )
-      , ('\176', '\3600' )
-      , ('\177', '\3601' )
-      , ('\178', '\3602' )
-      , ('\179', '\3603' )
-      , ('\180', '\3604' )
-      , ('\181', '\3605' )
-      , ('\182', '\3606' )
-      , ('\183', '\3607' )
-      , ('\184', '\3608' )
-      , ('\185', '\3609' )
-      , ('\186', '\3610' )
-      , ('\187', '\3611' )
-      , ('\188', '\3612' )
-      , ('\189', '\3613' )
-      , ('\190', '\3614' )
-      , ('\191', '\3615' )
-      , ('\192', '\3616' )
-      , ('\193', '\3617' )
-      , ('\194', '\3618' )
-      , ('\195', '\3619' )
-      , ('\196', '\3620' )
-      , ('\197', '\3621' )
-      , ('\198', '\3622' )
-      , ('\199', '\3623' )
-      , ('\200', '\3624' )
-      , ('\201', '\3625' )
-      , ('\202', '\3626' )
-      , ('\203', '\3627' )
-      , ('\204', '\3628' )
-      , ('\205', '\3629' )
-      , ('\206', '\3630' )
-      , ('\207', '\3631' )
-      , ('\208', '\3632' )
-      , ('\209', '\3633' )
-      , ('\210', '\3634' )
-      , ('\211', '\3635' )
-      , ('\212', '\3636' )
-      , ('\213', '\3637' )
-      , ('\214', '\3638' )
-      , ('\215', '\3639' )
-      , ('\216', '\3640' )
-      , ('\217', '\3641' )
-      , ('\218', '\3642' )
-      , ('\223', '\3647' )
-      , ('\224', '\3648' )
-      , ('\225', '\3649' )
-      , ('\226', '\3650' )
-      , ('\227', '\3651' )
-      , ('\228', '\3652' )
-      , ('\229', '\3653' )
-      , ('\230', '\3654' )
-      , ('\231', '\3655' )
-      , ('\232', '\3656' )
-      , ('\233', '\3657' )
-      , ('\234', '\3658' )
-      , ('\235', '\3659' )
-      , ('\236', '\3660' )
-      , ('\237', '\3661' )
-      , ('\238', '\3662' )
-      , ('\239', '\3663' )
-      , ('\240', '\3664' )
-      , ('\241', '\3665' )
-      , ('\242', '\3666' )
-      , ('\243', '\3667' )
-      , ('\244', '\3668' )
-      , ('\245', '\3669' )
-      , ('\246', '\3670' )
-      , ('\247', '\3671' )
-      , ('\248', '\3672' )
-      , ('\249', '\3673' )
-      , ('\250', '\3674' )
-      , ('\251', '\3675' )
-      ]
-
-iso_8859_13     :: [(Char, Char)]
-iso_8859_13
-    = [ ('\161', '\8221' )
-      , ('\165', '\8222' )
-      , ('\168', '\216' )
-      , ('\170', '\342' )
-      , ('\175', '\198' )
-      , ('\180', '\8220' )
-      , ('\184', '\248' )
-      , ('\186', '\343' )
-      , ('\191', '\230' )
-      , ('\192', '\260' )
-      , ('\193', '\302' )
-      , ('\194', '\256' )
-      , ('\195', '\262' )
-      , ('\198', '\280' )
-      , ('\199', '\274' )
-      , ('\200', '\268' )
-      , ('\202', '\377' )
-      , ('\203', '\278' )
-      , ('\204', '\290' )
-      , ('\205', '\310' )
-      , ('\206', '\298' )
-      , ('\207', '\315' )
-      , ('\208', '\352' )
-      , ('\209', '\323' )
-      , ('\210', '\325' )
-      , ('\212', '\332' )
-      , ('\216', '\370' )
-      , ('\217', '\321' )
-      , ('\218', '\346' )
-      , ('\219', '\362' )
-      , ('\221', '\379' )
-      , ('\222', '\381' )
-      , ('\224', '\261' )
-      , ('\225', '\303' )
-      , ('\226', '\257' )
-      , ('\227', '\263' )
-      , ('\230', '\281' )
-      , ('\231', '\275' )
-      , ('\232', '\269' )
-      , ('\234', '\378' )
-      , ('\235', '\279' )
-      , ('\236', '\291' )
-      , ('\237', '\311' )
-      , ('\238', '\299' )
-      , ('\239', '\316' )
-      , ('\240', '\353' )
-      , ('\241', '\324' )
-      , ('\242', '\326' )
-      , ('\244', '\333' )
-      , ('\248', '\371' )
-      , ('\249', '\322' )
-      , ('\250', '\347' )
-      , ('\251', '\363' )
-      , ('\253', '\380' )
-      , ('\254', '\382' )
-      , ('\255', '\8217' )
-      ]
-
-iso_8859_14     :: [(Char, Char)]
-iso_8859_14
-    = [ ('\161', '\7682' )
-      , ('\162', '\7683' )
-      , ('\164', '\266' )
-      , ('\165', '\267' )
-      , ('\166', '\7690' )
-      , ('\168', '\7808' )
-      , ('\170', '\7810' )
-      , ('\171', '\7691' )
-      , ('\172', '\7922' )
-      , ('\175', '\376' )
-      , ('\176', '\7710' )
-      , ('\177', '\7711' )
-      , ('\178', '\288' )
-      , ('\179', '\289' )
-      , ('\180', '\7744' )
-      , ('\181', '\7745' )
-      , ('\183', '\7766' )
-      , ('\184', '\7809' )
-      , ('\185', '\7767' )
-      , ('\186', '\7811' )
-      , ('\187', '\7776' )
-      , ('\188', '\7923' )
-      , ('\189', '\7812' )
-      , ('\190', '\7813' )
-      , ('\191', '\7777' )
-      , ('\208', '\372' )
-      , ('\215', '\7786' )
-      , ('\222', '\374' )
-      , ('\240', '\373' )
-      , ('\247', '\7787' )
-      , ('\254', '\375' )
-      ]
-
-iso_8859_15     :: [(Char, Char)]
-iso_8859_15
-    = [ ('\164', '\8364' )
-      , ('\166', '\352' )
-      , ('\168', '\353' )
-      , ('\180', '\381' )
-      , ('\184', '\382' )
-      , ('\188', '\338' )
-      , ('\189', '\339' )
-      , ('\190', '\376' )
-      ]
-
-iso_8859_16     :: [(Char, Char)]
-iso_8859_16
-    = [ ('\161', '\260' )
-      , ('\162', '\261' )
-      , ('\163', '\321' )
-      , ('\164', '\8364' )
-      , ('\165', '\8222' )
-      , ('\166', '\352' )
-      , ('\168', '\353' )
-      , ('\170', '\536' )
-      , ('\172', '\377' )
-      , ('\174', '\378' )
-      , ('\175', '\379' )
-      , ('\178', '\268' )
-      , ('\179', '\322' )
-      , ('\180', '\381' )
-      , ('\181', '\8221' )
-      , ('\184', '\382' )
-      , ('\185', '\269' )
-      , ('\186', '\537' )
-      , ('\188', '\338' )
-      , ('\189', '\339' )
-      , ('\190', '\376' )
-      , ('\191', '\380' )
-      , ('\195', '\258' )
-      , ('\197', '\262' )
-      , ('\208', '\272' )
-      , ('\209', '\323' )
-      , ('\213', '\336' )
-      , ('\215', '\346' )
-      , ('\216', '\368' )
-      , ('\221', '\280' )
-      , ('\222', '\538' )
-      , ('\227', '\259' )
-      , ('\229', '\263' )
-      , ('\240', '\273' )
-      , ('\241', '\324' )
-      , ('\245', '\337' )
-      , ('\247', '\347' )
-      , ('\248', '\369' )
-      , ('\253', '\281' )
-      , ('\254', '\539' )
-      ]
-
diff --git a/src/Text/XML/HXT/DOM/QualifiedName.hs b/src/Text/XML/HXT/DOM/QualifiedName.hs
--- a/src/Text/XML/HXT/DOM/QualifiedName.hs
+++ b/src/Text/XML/HXT/DOM/QualifiedName.hs
@@ -86,6 +86,7 @@
 import           Control.DeepSeq
 
 import           Data.AssocList
+import           Data.Binary
 import           Data.Char                      ( toLower )
 import           Data.List                      ( isPrefixOf )
 import qualified Data.Map               as M
@@ -99,7 +100,7 @@
                                                 , xmlnsNamespace
                                                 )
 
-import           Text.XML.HXT.DOM.Unicode       ( isXmlNCNameStartChar
+import Data.Char.Properties.XMLCharProps        ( isXmlNCNameStartChar
                                                 , isXmlNCNameChar
                                                 )
 
@@ -150,6 +151,19 @@
 -- and does things like "mkName("x:y") == mkPrefixLocalPart("x","y")
 
 instance NFData QName where
+
+instance Binary QName where
+    put qn              = let
+                          px = namePrefix   qn
+                          lp = localPart    qn
+                          ns = namespaceUri qn
+                          in
+                          put px >> put lp >> put ns
+    get                 = do
+                          px <- get
+                          lp <- get
+                          ns <- get
+                          return $ mkQName px lp ns
 
 -- -----------------------------------------------------------------------------
 
diff --git a/src/Text/XML/HXT/DOM/TypeDefs.hs b/src/Text/XML/HXT/DOM/TypeDefs.hs
--- a/src/Text/XML/HXT/DOM/TypeDefs.hs
+++ b/src/Text/XML/HXT/DOM/TypeDefs.hs
@@ -28,6 +28,7 @@
 import Control.DeepSeq
 
 import Data.AssocList
+import Data.Binary
 import Data.Tree.NTree.TypeDefs
 import Data.Typeable
 
@@ -78,6 +79,41 @@
     rnf (XAttr qn)              = rnf qn
     rnf (XError n e)            = rnf n  `seq` rnf e
 
+instance Binary XNode where
+    put (XText s)               = put (0::Word8) >> put s
+    put (XCharRef i)            = put (1::Word8) >> put i
+    put (XEntityRef n)          = put (2::Word8) >> put n
+    put (XCmt c)                = put (3::Word8) >> put c
+    put (XCdata s)              = put (4::Word8) >> put s
+    put (XPi qn ts)             = put (5::Word8) >> put qn >> put ts
+    put (XTag qn cs)            = put (6::Word8) >> put qn >> put cs
+    put (XDTD de al)            = put (7::Word8) >> put de >> put al
+    put (XAttr qn)              = put (8::Word8) >> put qn
+    put (XError n e)            = put (9::Word8) >> put n  >> put e
+
+    get                         = do
+                                  tag <- getWord8
+                                  case tag of
+                                    0 -> get >>= return . XText
+                                    1 -> get >>= return . XCharRef
+                                    2 -> get >>= return . XEntityRef
+                                    3 -> get >>= return . XCmt
+                                    4 -> get >>= return . XCdata
+                                    5 -> do
+                                         qn <- get
+                                         get >>= return . XPi qn
+                                    6 -> do
+                                         qn <- get
+                                         get >>= return . XTag qn
+                                    7 -> do
+                                         de <- get
+                                         get >>= return . XDTD de
+                                    8 -> get >>= return . XAttr
+                                    9 -> do
+                                         n <- get
+                                         get >>= return . XError n
+                                    _ -> error "XNode.get: error while decoding XNode"
+
 -- -----------------------------------------------------------------------------
 --
 -- DTDElem
@@ -120,6 +156,22 @@
                   deriving (Eq, Ord, Enum, Show, Read, Typeable)
 
 instance NFData DTDElem
+
+instance Binary DTDElem where
+    put de                      = put ((toEnum . fromEnum $ de)::Word8)         -- DTDElem is not yet instance of Enum
+    get                         = do
+                                  tag <- getWord8
+                                  return . toEnum . fromEnum $ tag
+{-
+    put de                      = let
+                                  i = fromJust . elemIndex de $ dtdElems
+                                  in
+                                  put ((toEnum i)::Word8)
+
+    get                         = do
+                                  tag <- getWord8
+                                  return $ dtdElems !! (fromEnum tag)
+-}
 
 -- -----------------------------------------------------------------------------
 
diff --git a/src/Text/XML/HXT/DOM/UTF8Decoding.hs b/src/Text/XML/HXT/DOM/UTF8Decoding.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/DOM/UTF8Decoding.hs
+++ /dev/null
@@ -1,52 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.DOM.UTF8Decoding
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : stable
-   Portability: portable
-
-   Interface for Data.Char.UTF8 funtions
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.DOM.UTF8Decoding (
-   decodeUtf8,
-   decodeUtf8EmbedErrors,
-   decodeUtf8IgnoreErrors,
-   )
-where
-
-import qualified Data.Char.UTF8 as UTF8
-import Data.Word (Word8)
-
--- | calls 'Data.Char.UTF8.decode' for parsing and decoding UTF-8
-
-decodeUtf8      :: String -> (String, [String])
-decodeUtf8 str
-    = (res, map (uncurry toErrStr) errs)
-    where
-    (res, errs) = UTF8.decode . stringToByteString $ str
-
-decodeUtf8IgnoreErrors  :: String -> String
-decodeUtf8IgnoreErrors
-    = fst . decodeUtf8
-
-decodeUtf8EmbedErrors   :: String -> [Either String Char]
-decodeUtf8EmbedErrors str
-    = map (either (Left . uncurry toErrStr) Right) $
-      UTF8.decodeEmbedErrors $ stringToByteString $ str
-
-stringToByteString :: String -> [Word8]
-stringToByteString = map (toEnum . fromEnum)
-
-toErrStr :: UTF8.Error -> Int -> String
-toErrStr err pos
-        = " at input position " ++ show pos ++ ": " ++ show err
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/DOM/Unicode.hs b/src/Text/XML/HXT/DOM/Unicode.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/DOM/Unicode.hs
+++ /dev/null
@@ -1,1105 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.DOM.Unicode
-   Copyright  : Copyright (C) 2005-2008 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
-   Portability: portable
-
-   Unicode and UTF-8 Conversion Functions
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.DOM.Unicode
-    (
-     -- * Unicode Type declarations
-     Unicode,
-     UString,
-     UTF8Char,
-     UTF8String,
-     UStringWithErrors,
-     DecodingFct,
-     DecodingFctEmbedErrors,
-
-      -- * XML char predicates
-
-      isXmlChar
-    , isXmlLatin1Char
-    , isXmlSpaceChar
-    , isXml11SpaceChar
-    , isXmlNameChar
-    , isXmlNameStartChar
-    , isXmlNCNameChar
-    , isXmlNCNameStartChar
-    , isXmlPubidChar
-    , isXmlLetter
-    , isXmlBaseChar
-    , isXmlIdeographicChar
-    , isXmlCombiningChar
-    , isXmlDigit
-    , isXmlExtender
-    , isXmlControlOrPermanentlyUndefined
-
-      -- * UTF-8 and Unicode conversion functions
-    , utf8ToUnicode
-    , utf8ToUnicodeEmbedErrors
-    , latin1ToUnicode
-    , ucs2ToUnicode
-    , ucs2BigEndianToUnicode
-    , ucs2LittleEndianToUnicode
-    , utf16beToUnicode
-    , utf16leToUnicode
-
-    , unicodeCharToUtf8
-
-    , unicodeToUtf8
-    , unicodeToXmlEntity
-    , unicodeToLatin1
-    , unicodeRemoveNoneAscii
-    , unicodeRemoveNoneLatin1
-
-    , intToCharRef
-    , intToCharRefHex
-
-    , getDecodingFct
-    , getDecodingFctEmbedErrors
-    , getOutputEncodingFct
-
-    , normalizeNL
-    , guessEncoding
-    )
-where
-
-import Data.Char( toUpper )
-
-import Text.XML.HXT.DOM.Util ( swap, partitionEither )
-
-import Text.XML.HXT.DOM.IsoLatinTables
-import Text.XML.HXT.DOM.UTF8Decoding    ( decodeUtf8, decodeUtf8EmbedErrors )
-import Text.XML.HXT.DOM.Util            ( intToHexString )
-import Text.XML.HXT.DOM.XmlKeywords
-
--- ------------------------------------------------------------
-
--- | Unicode is represented as the Char type
---   Precondition for this is the support of Unicode character range
---   in the compiler (e.g. ghc but not hugs)
-
-type Unicode    = Char
-
--- | the type for Unicode strings
-
-type UString    = [Unicode]
-
--- | UTF-8 charachters are represented by the Char type
-
-type UTF8Char   = Char
-
--- | UTF-8 strings are implemented as Haskell strings
-
-type UTF8String = String
-
--- | Decoding function with a pair containing the result string and a list of decoding errors as result
-
-type DecodingFct = String -> (UString, [String])
-
-type UStringWithErrors = [Either String Char]
-
--- | Decoding function where decoding errors are interleaved with decoded characters
-
-type DecodingFctEmbedErrors = String -> UStringWithErrors
-
--- ------------------------------------------------------------
---
--- Unicode predicates
-
--- |
--- test for a legal 1 byte XML char
-
-is1ByteXmlChar          :: Unicode -> Bool
-is1ByteXmlChar c
-    = c < '\x80'
-      && ( c >= ' '
-           ||
-           c == '\n'
-           ||
-           c == '\t'
-           ||
-           c == '\r'
-         )
-
--- |
--- test for a legal latin1 XML char
-
-isXmlLatin1Char         :: Unicode -> Bool
-isXmlLatin1Char i
-    = is1ByteXmlChar i
-      ||
-      (i >= '\x80' && i <= '\xff')
-
--- ------------------------------------------------------------
-
--- |
--- conversion from Unicode strings (UString) to UTF8 encoded strings.
-
-unicodeToUtf8           :: UString -> UTF8String
-unicodeToUtf8           = concatMap unicodeCharToUtf8
-
--- |
--- conversion from Unicode (Char) to a UTF8 encoded string.
-
-unicodeCharToUtf8       :: Unicode -> UTF8String
-unicodeCharToUtf8 c
-    | i >= 0          && i <= 0x0000007F        -- 1 byte UTF8 (7 bits)
-        = [ toEnum i ]
-    | i >= 0x00000080 && i <= 0x000007FF        -- 2 byte UTF8 (5 + 6 bits)
-        = [ toEnum (0xC0 + i `div` 0x40)
-          , toEnum (0x80 + i                  `mod` 0x40)
-          ]
-    | i >= 0x00000800 && i <= 0x0000FFFF        -- 3 byte UTF8 (4 + 6 + 6 bits)
-        = [ toEnum (0xE0 +  i `div`   0x1000)
-          , toEnum (0x80 + (i `div`     0x40) `mod` 0x40)
-          , toEnum (0x80 +  i                 `mod` 0x40)
-          ]
-    | i >= 0x00010000 && i <= 0x001FFFFF        -- 4 byte UTF8 (3 + 6 + 6 + 6 bits)
-        = [ toEnum (0xF0 +  i `div`    0x40000)
-          , toEnum (0x80 + (i `div`     0x1000) `mod` 0x40)
-          , toEnum (0x80 + (i `div`       0x40) `mod` 0x40)
-          , toEnum (0x80 +  i                   `mod` 0x40)
-          ]
-    | i >= 0x00200000 && i <= 0x03FFFFFF        -- 5 byte UTF8 (2 + 6 + 6 + 6 + 6 bits)
-        = [ toEnum (0xF8 +  i `div`  0x1000000)
-          , toEnum (0x80 + (i `div`    0x40000) `mod` 0x40)
-          , toEnum (0x80 + (i `div`     0x1000) `mod` 0x40)
-          , toEnum (0x80 + (i `div`       0x40) `mod` 0x40)
-          , toEnum (0x80 +  i                   `mod` 0x40)
-          ]
-    | i >= 0x04000000 && i <= 0x7FFFFFFF        -- 6 byte UTF8 (1 + 6 + 6 + 6 + 6 + 6 bits)
-        = [ toEnum (0xFC +  i `div` 0x40000000)
-          , toEnum (0x80 + (i `div`  0x1000000) `mod` 0x40)
-          , toEnum (0x80 + (i `div`    0x40000) `mod` 0x40)
-          , toEnum (0x80 + (i `div`     0x1000) `mod` 0x40)
-          , toEnum (0x80 + (i `div`       0x40) `mod` 0x40)
-          , toEnum (0x80 +  i                   `mod` 0x40)
-          ]
-    | otherwise                                 -- other values not supported
-        = error ("unicodeCharToUtf8: illegal integer argument " ++ show i)
-    where
-    i = fromEnum c
-
--- ------------------------------------------------------------
-
--- |
--- checking for valid XML characters
-
-isXmlChar               :: Unicode -> Bool
-isXmlChar c
-    = isInList c
-      [ ('\x0009', '\x000A')
-      , ('\x000D', '\x000D')
-      , ('\x0020', '\xD7FF')
-      , ('\xE000', '\xFFFD')
-      , ('\x10000', '\x10FFFF')
-      ]
-
--- |
--- checking for XML space character: \\\n, \\\r, \\\t and \" \"
-
-isXmlSpaceChar          :: Unicode -> Bool
-isXmlSpaceChar c
-    = c `elem` ['\x20', '\x09', '\x0D', '\x0A']
-
--- |
--- checking for XML1.1 space character: additional space 0x85 and 0x2028
---
--- see also : 'isXmlSpaceChar'
-
-isXml11SpaceChar                :: Unicode -> Bool
-isXml11SpaceChar c
-    = c `elem` ['\x20', '\x09', '\x0D', '\x0A', '\x85', '\x2028']
-
--- |
--- checking for XML name character
-
-isXmlNameChar           :: Unicode -> Bool
-isXmlNameChar c
-    = isXmlLetter c
-      ||
-      isXmlDigit c
-      ||
-      (c == '\x2D' || c == '\x2E')              -- '-' | '.'
-      ||
-      (c == '\x3A' || c == '\x5F')              -- Letter | ':' | '_'
-      ||
-      isXmlCombiningChar c
-      ||
-      isXmlExtender c
-
--- |
--- checking for XML name start character
---
--- see also : 'isXmlNameChar'
-
-isXmlNameStartChar              :: Unicode -> Bool
-isXmlNameStartChar c
-    = isXmlLetter c
-      ||
-      (c == '\x3A' || c == '\x5F')              -- Letter | ':' | '_'
-
--- |
--- checking for XML NCName character: no \":\" allowed
---
--- see also : 'isXmlNameChar'
-
-isXmlNCNameChar                 :: Unicode -> Bool
-isXmlNCNameChar c
-    = c /= '\x3A'
-      &&
-      isXmlNameChar c
-
--- |
--- checking for XML NCName start character: no \":\" allowed
---
--- see also : 'isXmlNameChar', 'isXmlNCNameChar'
-
-isXmlNCNameStartChar            :: Unicode -> Bool
-isXmlNCNameStartChar c
-    = c /= '\x3A'
-      &&
-      isXmlNameStartChar c
-
--- |
--- checking for XML public id character
-
-isXmlPubidChar          :: Unicode -> Bool
-isXmlPubidChar c
-    = isInList c [ ('0', '9')
-                 , ('A', 'Z')
-                 , ('a', 'z')
-                 ]
-      ||
-      ( c `elem` " \r\n-'()+,./:=?;!*#@$_%" )
-
--- |
--- checking for XML letter
-
-isXmlLetter             :: Unicode -> Bool
-isXmlLetter c
-    = isXmlBaseChar c
-      ||
-      isXmlIdeographicChar c
-
--- |
--- checking for XML base charater
-
-isXmlBaseChar           :: Unicode -> Bool
-isXmlBaseChar c
-    = isInList c
-      [ ('\x0041', '\x005A')
-      , ('\x0061', '\x007A')
-      , ('\x00C0', '\x00D6')
-      , ('\x00D8', '\x00F6')
-      , ('\x00F8', '\x0131')
-      , ('\x0134', '\x013E')
-      , ('\x0141', '\x0148')
-      , ('\x014A', '\x017E')
-      , ('\x0180', '\x01C3')
-      , ('\x01CD', '\x01F0')
-      , ('\x01F4', '\x01F5')
-      , ('\x01FA', '\x0217')
-      , ('\x0250', '\x02A8')
-      , ('\x02BB', '\x02C1')
-      , ('\x0386', '\x0386')
-      , ('\x0388', '\x038A')
-      , ('\x038C', '\x038C')
-      , ('\x038E', '\x03A1')
-      , ('\x03A3', '\x03CE')
-      , ('\x03D0', '\x03D6')
-      , ('\x03DA', '\x03DA')
-      , ('\x03DC', '\x03DC')
-      , ('\x03DE', '\x03DE')
-      , ('\x03E0', '\x03E0')
-      , ('\x03E2', '\x03F3')
-      , ('\x0401', '\x040C')
-      , ('\x040E', '\x044F')
-      , ('\x0451', '\x045C')
-      , ('\x045E', '\x0481')
-      , ('\x0490', '\x04C4')
-      , ('\x04C7', '\x04C8')
-      , ('\x04CB', '\x04CC')
-      , ('\x04D0', '\x04EB')
-      , ('\x04EE', '\x04F5')
-      , ('\x04F8', '\x04F9')
-      , ('\x0531', '\x0556')
-      , ('\x0559', '\x0559')
-      , ('\x0561', '\x0586')
-      , ('\x05D0', '\x05EA')
-      , ('\x05F0', '\x05F2')
-      , ('\x0621', '\x063A')
-      , ('\x0641', '\x064A')
-      , ('\x0671', '\x06B7')
-      , ('\x06BA', '\x06BE')
-      , ('\x06C0', '\x06CE')
-      , ('\x06D0', '\x06D3')
-      , ('\x06D5', '\x06D5')
-      , ('\x06E5', '\x06E6')
-      , ('\x0905', '\x0939')
-      , ('\x093D', '\x093D')
-      , ('\x0958', '\x0961')
-      , ('\x0985', '\x098C')
-      , ('\x098F', '\x0990')
-      , ('\x0993', '\x09A8')
-      , ('\x09AA', '\x09B0')
-      , ('\x09B2', '\x09B2')
-      , ('\x09B6', '\x09B9')
-      , ('\x09DC', '\x09DD')
-      , ('\x09DF', '\x09E1')
-      , ('\x09F0', '\x09F1')
-      , ('\x0A05', '\x0A0A')
-      , ('\x0A0F', '\x0A10')
-      , ('\x0A13', '\x0A28')
-      , ('\x0A2A', '\x0A30')
-      , ('\x0A32', '\x0A33')
-      , ('\x0A35', '\x0A36')
-      , ('\x0A38', '\x0A39')
-      , ('\x0A59', '\x0A5C')
-      , ('\x0A5E', '\x0A5E')
-      , ('\x0A72', '\x0A74')
-      , ('\x0A85', '\x0A8B')
-      , ('\x0A8D', '\x0A8D')
-      , ('\x0A8F', '\x0A91')
-      , ('\x0A93', '\x0AA8')
-      , ('\x0AAA', '\x0AB0')
-      , ('\x0AB2', '\x0AB3')
-      , ('\x0AB5', '\x0AB9')
-      , ('\x0ABD', '\x0ABD')
-      , ('\x0AE0', '\x0AE0')
-      , ('\x0B05', '\x0B0C')
-      , ('\x0B0F', '\x0B10')
-      , ('\x0B13', '\x0B28')
-      , ('\x0B2A', '\x0B30')
-      , ('\x0B32', '\x0B33')
-      , ('\x0B36', '\x0B39')
-      , ('\x0B3D', '\x0B3D')
-      , ('\x0B5C', '\x0B5D')
-      , ('\x0B5F', '\x0B61')
-      , ('\x0B85', '\x0B8A')
-      , ('\x0B8E', '\x0B90')
-      , ('\x0B92', '\x0B95')
-      , ('\x0B99', '\x0B9A')
-      , ('\x0B9C', '\x0B9C')
-      , ('\x0B9E', '\x0B9F')
-      , ('\x0BA3', '\x0BA4')
-      , ('\x0BA8', '\x0BAA')
-      , ('\x0BAE', '\x0BB5')
-      , ('\x0BB7', '\x0BB9')
-      , ('\x0C05', '\x0C0C')
-      , ('\x0C0E', '\x0C10')
-      , ('\x0C12', '\x0C28')
-      , ('\x0C2A', '\x0C33')
-      , ('\x0C35', '\x0C39')
-      , ('\x0C60', '\x0C61')
-      , ('\x0C85', '\x0C8C')
-      , ('\x0C8E', '\x0C90')
-      , ('\x0C92', '\x0CA8')
-      , ('\x0CAA', '\x0CB3')
-      , ('\x0CB5', '\x0CB9')
-      , ('\x0CDE', '\x0CDE')
-      , ('\x0CE0', '\x0CE1')
-      , ('\x0D05', '\x0D0C')
-      , ('\x0D0E', '\x0D10')
-      , ('\x0D12', '\x0D28')
-      , ('\x0D2A', '\x0D39')
-      , ('\x0D60', '\x0D61')
-      , ('\x0E01', '\x0E2E')
-      , ('\x0E30', '\x0E30')
-      , ('\x0E32', '\x0E33')
-      , ('\x0E40', '\x0E45')
-      , ('\x0E81', '\x0E82')
-      , ('\x0E84', '\x0E84')
-      , ('\x0E87', '\x0E88')
-      , ('\x0E8A', '\x0E8A')
-      , ('\x0E8D', '\x0E8D')
-      , ('\x0E94', '\x0E97')
-      , ('\x0E99', '\x0E9F')
-      , ('\x0EA1', '\x0EA3')
-      , ('\x0EA5', '\x0EA5')
-      , ('\x0EA7', '\x0EA7')
-      , ('\x0EAA', '\x0EAB')
-      , ('\x0EAD', '\x0EAE')
-      , ('\x0EB0', '\x0EB0')
-      , ('\x0EB2', '\x0EB3')
-      , ('\x0EBD', '\x0EBD')
-      , ('\x0EC0', '\x0EC4')
-      , ('\x0F40', '\x0F47')
-      , ('\x0F49', '\x0F69')
-      , ('\x10A0', '\x10C5')
-      , ('\x10D0', '\x10F6')
-      , ('\x1100', '\x1100')
-      , ('\x1102', '\x1103')
-      , ('\x1105', '\x1107')
-      , ('\x1109', '\x1109')
-      , ('\x110B', '\x110C')
-      , ('\x110E', '\x1112')
-      , ('\x113C', '\x113C')
-      , ('\x113E', '\x113E')
-      , ('\x1140', '\x1140')
-      , ('\x114C', '\x114C')
-      , ('\x114E', '\x114E')
-      , ('\x1150', '\x1150')
-      , ('\x1154', '\x1155')
-      , ('\x1159', '\x1159')
-      , ('\x115F', '\x1161')
-      , ('\x1163', '\x1163')
-      , ('\x1165', '\x1165')
-      , ('\x1167', '\x1167')
-      , ('\x1169', '\x1169')
-      , ('\x116D', '\x116E')
-      , ('\x1172', '\x1173')
-      , ('\x1175', '\x1175')
-      , ('\x119E', '\x119E')
-      , ('\x11A8', '\x11A8')
-      , ('\x11AB', '\x11AB')
-      , ('\x11AE', '\x11AF')
-      , ('\x11B7', '\x11B8')
-      , ('\x11BA', '\x11BA')
-      , ('\x11BC', '\x11C2')
-      , ('\x11EB', '\x11EB')
-      , ('\x11F0', '\x11F0')
-      , ('\x11F9', '\x11F9')
-      , ('\x1E00', '\x1E9B')
-      , ('\x1EA0', '\x1EF9')
-      , ('\x1F00', '\x1F15')
-      , ('\x1F18', '\x1F1D')
-      , ('\x1F20', '\x1F45')
-      , ('\x1F48', '\x1F4D')
-      , ('\x1F50', '\x1F57')
-      , ('\x1F59', '\x1F59')
-      , ('\x1F5B', '\x1F5B')
-      , ('\x1F5D', '\x1F5D')
-      , ('\x1F5F', '\x1F7D')
-      , ('\x1F80', '\x1FB4')
-      , ('\x1FB6', '\x1FBC')
-      , ('\x1FBE', '\x1FBE')
-      , ('\x1FC2', '\x1FC4')
-      , ('\x1FC6', '\x1FCC')
-      , ('\x1FD0', '\x1FD3')
-      , ('\x1FD6', '\x1FDB')
-      , ('\x1FE0', '\x1FEC')
-      , ('\x1FF2', '\x1FF4')
-      , ('\x1FF6', '\x1FFC')
-      , ('\x2126', '\x2126')
-      , ('\x212A', '\x212B')
-      , ('\x212E', '\x212E')
-      , ('\x2180', '\x2182')
-      , ('\x3041', '\x3094')
-      , ('\x30A1', '\x30FA')
-      , ('\x3105', '\x312C')
-      , ('\xAC00', '\xD7A3')
-      ]
-
--- |
--- checking for XML ideographic charater
-
-isXmlIdeographicChar    :: Unicode -> Bool
-isXmlIdeographicChar c
-    = isInList c
-      [ ('\x3007', '\x3007')
-      , ('\x3021', '\x3029')
-      , ('\x4E00', '\x9FA5')
-      ]
-
--- |
--- checking for XML combining charater
-
-isXmlCombiningChar      :: Unicode -> Bool
-isXmlCombiningChar c
-    = isInList c
-      [ ('\x0300', '\x0345')
-      , ('\x0360', '\x0361')
-      , ('\x0483', '\x0486')
-      , ('\x0591', '\x05A1')
-      , ('\x05A3', '\x05B9')
-      , ('\x05BB', '\x05BD')
-      , ('\x05BF', '\x05BF')
-      , ('\x05C1', '\x05C2')
-      , ('\x05C4', '\x05C4')
-      , ('\x064B', '\x0652')
-      , ('\x0670', '\x0670')
-      , ('\x06D6', '\x06DC')
-      , ('\x06DD', '\x06DF')
-      , ('\x06E0', '\x06E4')
-      , ('\x06E7', '\x06E8')
-      , ('\x06EA', '\x06ED')
-      , ('\x0901', '\x0903')
-      , ('\x093C', '\x093C')
-      , ('\x093E', '\x094C')
-      , ('\x094D', '\x094D')
-      , ('\x0951', '\x0954')
-      , ('\x0962', '\x0963')
-      , ('\x0981', '\x0983')
-      , ('\x09BC', '\x09BC')
-      , ('\x09BE', '\x09BE')
-      , ('\x09BF', '\x09BF')
-      , ('\x09C0', '\x09C4')
-      , ('\x09C7', '\x09C8')
-      , ('\x09CB', '\x09CD')
-      , ('\x09D7', '\x09D7')
-      , ('\x09E2', '\x09E3')
-      , ('\x0A02', '\x0A02')
-      , ('\x0A3C', '\x0A3C')
-      , ('\x0A3E', '\x0A3E')
-      , ('\x0A3F', '\x0A3F')
-      , ('\x0A40', '\x0A42')
-      , ('\x0A47', '\x0A48')
-      , ('\x0A4B', '\x0A4D')
-      , ('\x0A70', '\x0A71')
-      , ('\x0A81', '\x0A83')
-      , ('\x0ABC', '\x0ABC')
-      , ('\x0ABE', '\x0AC5')
-      , ('\x0AC7', '\x0AC9')
-      , ('\x0ACB', '\x0ACD')
-      , ('\x0B01', '\x0B03')
-      , ('\x0B3C', '\x0B3C')
-      , ('\x0B3E', '\x0B43')
-      , ('\x0B47', '\x0B48')
-      , ('\x0B4B', '\x0B4D')
-      , ('\x0B56', '\x0B57')
-      , ('\x0B82', '\x0B83')
-      , ('\x0BBE', '\x0BC2')
-      , ('\x0BC6', '\x0BC8')
-      , ('\x0BCA', '\x0BCD')
-      , ('\x0BD7', '\x0BD7')
-      , ('\x0C01', '\x0C03')
-      , ('\x0C3E', '\x0C44')
-      , ('\x0C46', '\x0C48')
-      , ('\x0C4A', '\x0C4D')
-      , ('\x0C55', '\x0C56')
-      , ('\x0C82', '\x0C83')
-      , ('\x0CBE', '\x0CC4')
-      , ('\x0CC6', '\x0CC8')
-      , ('\x0CCA', '\x0CCD')
-      , ('\x0CD5', '\x0CD6')
-      , ('\x0D02', '\x0D03')
-      , ('\x0D3E', '\x0D43')
-      , ('\x0D46', '\x0D48')
-      , ('\x0D4A', '\x0D4D')
-      , ('\x0D57', '\x0D57')
-      , ('\x0E31', '\x0E31')
-      , ('\x0E34', '\x0E3A')
-      , ('\x0E47', '\x0E4E')
-      , ('\x0EB1', '\x0EB1')
-      , ('\x0EB4', '\x0EB9')
-      , ('\x0EBB', '\x0EBC')
-      , ('\x0EC8', '\x0ECD')
-      , ('\x0F18', '\x0F19')
-      , ('\x0F35', '\x0F35')
-      , ('\x0F37', '\x0F37')
-      , ('\x0F39', '\x0F39')
-      , ('\x0F3E', '\x0F3E')
-      , ('\x0F3F', '\x0F3F')
-      , ('\x0F71', '\x0F84')
-      , ('\x0F86', '\x0F8B')
-      , ('\x0F90', '\x0F95')
-      , ('\x0F97', '\x0F97')
-      , ('\x0F99', '\x0FAD')
-      , ('\x0FB1', '\x0FB7')
-      , ('\x0FB9', '\x0FB9')
-      , ('\x20D0', '\x20DC')
-      , ('\x20E1', '\x20E1')
-      , ('\x302A', '\x302F')
-      , ('\x3099', '\x3099')
-      , ('\x309A', '\x309A')
-      ]
-
--- |
--- checking for XML digit
-
-isXmlDigit              :: Unicode -> Bool
-isXmlDigit c
-    = isInList c
-      [ ('\x0030', '\x0039')
-      , ('\x0660', '\x0669')
-      , ('\x06F0', '\x06F9')
-      , ('\x0966', '\x096F')
-      , ('\x09E6', '\x09EF')
-      , ('\x0A66', '\x0A6F')
-      , ('\x0AE6', '\x0AEF')
-      , ('\x0B66', '\x0B6F')
-      , ('\x0BE7', '\x0BEF')
-      , ('\x0C66', '\x0C6F')
-      , ('\x0CE6', '\x0CEF')
-      , ('\x0D66', '\x0D6F')
-      , ('\x0E50', '\x0E59')
-      , ('\x0ED0', '\x0ED9')
-      , ('\x0F20', '\x0F29')
-      ]
-
--- |
--- checking for XML extender
-
-isXmlExtender           :: Unicode -> Bool
-isXmlExtender c
-    = isInList c
-      [ ('\x00B7', '\x00B7')
-      , ('\x02D0', '\x02D0')
-      , ('\x02D1', '\x02D1')
-      , ('\x0387', '\x0387')
-      , ('\x0640', '\x0640')
-      , ('\x0E46', '\x0E46')
-      , ('\x0EC6', '\x0EC6')
-      , ('\x3005', '\x3005')
-      , ('\x3031', '\x3035')
-      , ('\x309D', '\x309E')
-      , ('\x30FC', '\x30FE')
-      ]
-
--- |
--- checking for XML control or permanently discouraged char
---
--- see Errata to XML1.0 (http:\/\/www.w3.org\/XML\/xml-V10-2e-errata) No 46
---
--- Document authors are encouraged to avoid "compatibility characters",
--- as defined in section 6.8 of [Unicode] (see also D21 in section 3.6 of [Unicode3]).
--- The characters defined in the following ranges are also discouraged.
--- They are either control characters or permanently undefined Unicode characters:
-
-
-isXmlControlOrPermanentlyUndefined      :: Unicode -> Bool
-isXmlControlOrPermanentlyUndefined c
-    = isInList c
-      [ ('\x7F', '\x84')
-      , ('\x86', '\x9F')
-      , ('\xFDD0', '\xFDDF')
-      , ('\x1FFFE', '\x1FFFF')
-      , ('\x2FFFE', '\x2FFFF')
-      , ('\x3FFFE', '\x3FFFF')
-      , ('\x4FFFE', '\x4FFFF')
-      , ('\x5FFFE', '\x5FFFF')
-      , ('\x6FFFE', '\x6FFFF')
-      , ('\x7FFFE', '\x7FFFF')
-      , ('\x8FFFE', '\x8FFFF')
-      , ('\x9FFFE', '\x9FFFF')
-      , ('\xAFFFE', '\xAFFFF')
-      , ('\xBFFFE', '\xBFFFF')
-      , ('\xCFFFE', '\xCFFFF')
-      , ('\xDFFFE', '\xDFFFF')
-      , ('\xEFFFE', '\xEFFFF')
-      , ('\xFFFFE', '\xFFFFF')
-      , ('\x10FFFE', '\x10FFFF')
-      ]
-
--- ------------------------------------------------------------
-
-isInList        :: Unicode -> [(Unicode, Unicode)] -> Bool
-isInList i =
-   foldr (\(lb, ub) b -> i >= lb && (i <= ub || b)) False
-   {- The expression (i>=lb && i<=ub) || b would work more generally,
-      but in a sorted list, the above one aborts the computation as early as possible. -}
-
-{-
-isInList'       :: Unicode -> [(Unicode, Unicode)] -> Bool
-isInList' i ((lb, ub) : l)
-    | i <  lb   = False
-    | i <= ub   = True
-    | otherwise = isInList' i l
-
-isInList' _ []
-    = False
-
-{- works, but is not so fast -}
-isInList''      :: Unicode -> [(Unicode, Unicode)] -> Bool
-isInList'' i = any (flip isInRange i)
-
--- move to an Utility module?
-isInRange       :: Ord a => (a,a) -> a -> Bool
-isInRange (l,r) x = l<=x && x<=r
-
-propIsInList :: Bool
-propIsInList =
-   all
-     (\c -> let dict = [ ('\x0041', '\x005A'), ('\x0061', '\x007A') ]
-                b0 = isInList c dict
-                b1 = isInList' c dict
-                b2 = isInList'' c dict
-            in  b0 == b1 && b0 == b2)
-     ['\x00'..'\x100']
--}
-
--- ------------------------------------------------------------
-
--- |
--- code conversion from latin1 to Unicode
-
-latin1ToUnicode :: String -> UString
-latin1ToUnicode = id
-
-latinToUnicode  :: [(Char, Char)] -> String -> UString
-latinToUnicode tt
-    = map charToUni
-    where
-    charToUni c =
-       foldr (\(src,dst) r ->
-          case compare c src of
-             EQ -> dst
-             LT -> c {- not found in table -}
-             GT -> r) c tt
-
--- | conversion from ASCII to unicode with check for legal ASCII char set
---
--- Structure of decoding function copied from 'Data.Char.UTF8.decode'.
-
-decodeAscii     :: DecodingFct
-decodeAscii
-    = swap . partitionEither . decodeAsciiEmbedErrors
-
-decodeAsciiEmbedErrors  :: String -> UStringWithErrors
-decodeAsciiEmbedErrors str
-    = map (\(c,pos) -> if isValid c
-                         then Right c
-                         else Left (toErrStr c pos)) posStr
-    where
-    posStr = zip str [(0::Int)..]
-    toErrStr errChr pos
-        = " at input position " ++ show pos ++ ": none ASCII char " ++ show errChr
-    isValid x = x < '\x80'
-
--- |
--- UCS-2 big endian to Unicode conversion
-
-ucs2BigEndianToUnicode  :: String -> UString
-
-ucs2BigEndianToUnicode (b : l : r)
-    = toEnum (fromEnum b * 256 + fromEnum l) : ucs2BigEndianToUnicode r
-
-ucs2BigEndianToUnicode []
-    = []
-
-ucs2BigEndianToUnicode _
-    = []                                -- error "illegal UCS-2 byte input sequence with odd length"
-                                        -- is ignored (garbage in, garbage out)
-
--- ------------------------------------------------------------
-
--- |
--- UCS-2 little endian to Unicode conversion
-
-ucs2LittleEndianToUnicode       :: String -> UString
-
-ucs2LittleEndianToUnicode (l : b : r)
-    = toEnum (fromEnum b * 256 + fromEnum l) : ucs2LittleEndianToUnicode r
-
-ucs2LittleEndianToUnicode []
-    = []
-
-ucs2LittleEndianToUnicode [_]
-    = []                                -- error "illegal UCS-2 byte input sequence with odd length"
-                                        -- is ignored
-
--- ------------------------------------------------------------
-
--- |
--- UCS-2 to UTF-8 conversion with byte order mark analysis
-
-ucs2ToUnicode           :: String -> UString
-
-ucs2ToUnicode ('\xFE':'\xFF':s)         -- 2 byte mark for big endian encoding
-    = ucs2BigEndianToUnicode s
-
-ucs2ToUnicode ('\xFF':'\xFE':s)         -- 2 byte mark for little endian encoding
-    = ucs2LittleEndianToUnicode s
-
-ucs2ToUnicode s
-    = ucs2BigEndianToUnicode s          -- default: big endian
-
--- ------------------------------------------------------------
-
--- |
--- UTF-8 to Unicode conversion with deletion of leading byte order mark, as described in XML standard F.1
-
-utf8ToUnicode           :: DecodingFct
-
-utf8ToUnicode ('\xEF':'\xBB':'\xBF':s)  -- remove byte order mark ( XML standard F.1 )
-    = decodeUtf8 s
-
-utf8ToUnicode s
-    = decodeUtf8 s
-
-utf8ToUnicodeEmbedErrors        :: DecodingFctEmbedErrors
-
-utf8ToUnicodeEmbedErrors ('\xEF':'\xBB':'\xBF':s)       -- remove byte order mark ( XML standard F.1 )
-    = decodeUtf8EmbedErrors s
-
-utf8ToUnicodeEmbedErrors s
-    = decodeUtf8EmbedErrors s
-
--- ------------------------------------------------------------
-
--- |
--- UTF-16 big endian to UTF-8 conversion with removal of byte order mark
-
-utf16beToUnicode                :: String -> UString
-
-utf16beToUnicode ('\xFE':'\xFF':s)              -- remove byte order mark
-    = ucs2BigEndianToUnicode s
-
-utf16beToUnicode s
-    = ucs2BigEndianToUnicode s
-
--- ------------------------------------------------------------
-
--- |
--- UTF-16 little endian to UTF-8 conversion with removal of byte order mark
-
-utf16leToUnicode                :: String -> UString
-
-utf16leToUnicode ('\xFF':'\xFE':s)              -- remove byte order mark
-    = ucs2LittleEndianToUnicode s
-
-utf16leToUnicode s
-    = ucs2LittleEndianToUnicode s
-
-
--- ------------------------------------------------------------
-
--- |
--- substitute all Unicode characters, that are not legal 1-byte
--- UTF-8 XML characters by a character reference.
---
--- This function can be used to translate all text nodes and
--- attribute values into pure ascii.
---
--- see also : 'unicodeToLatin1'
-
-unicodeToXmlEntity      :: UString -> String
-unicodeToXmlEntity
-    = escape is1ByteXmlChar (intToCharRef . fromEnum)
-
--- |
--- substitute all Unicode characters, that are not legal latin1
--- UTF-8 XML characters by a character reference.
---
--- This function can be used to translate all text nodes and
--- attribute values into ISO latin1.
---
--- see also : 'unicodeToXmlEntity'
-
-unicodeToLatin1 :: UString -> String
-unicodeToLatin1
-    = escape isXmlLatin1Char (intToCharRef . fromEnum)
-
-
--- |
--- substitute selected characters
--- The @check@ function returns 'True' whenever a character needs to substitution
--- The function @esc@ computes a substitute.
-escape :: (Unicode -> Bool) -> (Unicode -> String) -> UString -> String
-escape check esc =
-    concatMap (\uc -> if check uc then [uc] else esc uc)
-
--- |
--- removes all non ascii chars, may be used to transform
--- a document into a pure ascii representation by removing
--- all non ascii chars from tag and attibute names
---
--- see also : 'unicodeRemoveNoneLatin1', 'unicodeToXmlEntity'
-
-unicodeRemoveNoneAscii  :: UString -> String
-unicodeRemoveNoneAscii
-    = filter is1ByteXmlChar
-
--- |
--- removes all non latin1 chars, may be used to transform
--- a document into a pure ascii representation by removing
--- all non ascii chars from tag and attibute names
---
--- see also : 'unicodeRemoveNoneAscii', 'unicodeToLatin1'
-
-unicodeRemoveNoneLatin1 :: UString -> String
-unicodeRemoveNoneLatin1
-    = filter isXmlLatin1Char
-
--- ------------------------------------------------------------
-
--- |
--- convert an Unicode into a XML character reference.
---
--- see also : 'intToCharRefHex'
-
-intToCharRef            :: Int -> String
-intToCharRef i
-    = "&#" ++ show i ++ ";"
-
--- |
--- convert an Unicode into a XML hexadecimal character reference.
---
--- see also: 'intToCharRef'
-
-intToCharRefHex         :: Int -> String
-intToCharRefHex i
-    = "&#x" ++ h2 ++ ";"
-      where
-      h1 = intToHexString i
-      h2 = if length h1 `mod` 2 == 1
-           then '0': h1
-           else h1
-
--- ------------------------------------------------------------
---
--- | White Space (XML Standard 2.3) and
--- end of line handling (2.11)
---
--- \#x0D and \#x0D\#x0A are mapped to \#x0A
-
-normalizeNL     :: String -> String
-normalizeNL ('\r' : '\n' : rest)        = '\n' : normalizeNL rest
-normalizeNL ('\r' : rest)               = '\n' : normalizeNL rest
-normalizeNL (c : rest)                  = c    : normalizeNL rest
-normalizeNL []                          = []
-
-
--- ------------------------------------------------------------
-
--- |
--- the table of supported character encoding schemes and the associated
--- conversion functions into Unicode:q
-
-{-
-This table could be derived from decodingTableEither,
-but this way it is certainly more efficient.
--}
-
-decodingTable   :: [(String, DecodingFct)]
-decodingTable
-    = [ (utf8,          utf8ToUnicode                           )
-      , (isoLatin1,     liftDecFct latin1ToUnicode              )
-      , (usAscii,       decodeAscii                             )
-      , (ucs2,          liftDecFct ucs2ToUnicode                )
-      , (utf16,         liftDecFct ucs2ToUnicode                )
-      , (utf16be,       liftDecFct utf16beToUnicode             )
-      , (utf16le,       liftDecFct utf16leToUnicode             )
-      , (iso8859_2,     liftDecFct (latinToUnicode iso_8859_2)  )
-      , (iso8859_3,     liftDecFct (latinToUnicode iso_8859_3)  )
-      , (iso8859_4,     liftDecFct (latinToUnicode iso_8859_4)  )
-      , (iso8859_5,     liftDecFct (latinToUnicode iso_8859_5)  )
-      , (iso8859_6,     liftDecFct (latinToUnicode iso_8859_6)  )
-      , (iso8859_7,     liftDecFct (latinToUnicode iso_8859_7)  )
-      , (iso8859_8,     liftDecFct (latinToUnicode iso_8859_8)  )
-      , (iso8859_9,     liftDecFct (latinToUnicode iso_8859_9)  )
-      , (iso8859_10,    liftDecFct (latinToUnicode iso_8859_10) )
-      , (iso8859_11,    liftDecFct (latinToUnicode iso_8859_11) )
-      , (iso8859_13,    liftDecFct (latinToUnicode iso_8859_13) )
-      , (iso8859_14,    liftDecFct (latinToUnicode iso_8859_14) )
-      , (iso8859_15,    liftDecFct (latinToUnicode iso_8859_15) )
-      , (iso8859_16,    liftDecFct (latinToUnicode iso_8859_16) )
-      , (unicodeString, liftDecFct id                           )
-      , ("",            liftDecFct id                           )       -- default
-      ]
-    where
-    liftDecFct df = \ s -> (df s, [])
-
--- |
--- the lookup function for selecting the decoding function
-
-getDecodingFct          :: String -> Maybe DecodingFct
-getDecodingFct enc
-    = lookup (map toUpper enc) decodingTable
-
-
--- |
--- Similar to 'decodingTable' but it embeds errors
--- in the string of decoded characters.
-
-decodingTableEmbedErrors        :: [(String, DecodingFctEmbedErrors)]
-decodingTableEmbedErrors
-    = [ (utf8,          utf8ToUnicodeEmbedErrors                )
-      , (isoLatin1,     liftDecFct latin1ToUnicode              )
-      , (usAscii,       decodeAsciiEmbedErrors                  )
-      , (ucs2,          liftDecFct ucs2ToUnicode                )
-      , (utf16,         liftDecFct ucs2ToUnicode                )
-      , (utf16be,       liftDecFct utf16beToUnicode             )
-      , (utf16le,       liftDecFct utf16leToUnicode             )
-      , (iso8859_2,     liftDecFct (latinToUnicode iso_8859_2)  )
-      , (iso8859_3,     liftDecFct (latinToUnicode iso_8859_3)  )
-      , (iso8859_4,     liftDecFct (latinToUnicode iso_8859_4)  )
-      , (iso8859_5,     liftDecFct (latinToUnicode iso_8859_5)  )
-      , (iso8859_6,     liftDecFct (latinToUnicode iso_8859_6)  )
-      , (iso8859_7,     liftDecFct (latinToUnicode iso_8859_7)  )
-      , (iso8859_8,     liftDecFct (latinToUnicode iso_8859_8)  )
-      , (iso8859_9,     liftDecFct (latinToUnicode iso_8859_9)  )
-      , (iso8859_10,    liftDecFct (latinToUnicode iso_8859_10) )
-      , (iso8859_11,    liftDecFct (latinToUnicode iso_8859_11) )
-      , (iso8859_13,    liftDecFct (latinToUnicode iso_8859_13) )
-      , (iso8859_14,    liftDecFct (latinToUnicode iso_8859_14) )
-      , (iso8859_15,    liftDecFct (latinToUnicode iso_8859_15) )
-      , (iso8859_16,    liftDecFct (latinToUnicode iso_8859_16) )
-      , (unicodeString, liftDecFct id                           )
-      , ("",            liftDecFct id                           )       -- default
-      ]
-    where
-    liftDecFct df = map Right . df
-
--- |
--- the lookup function for selecting the decoding function
-
-getDecodingFctEmbedErrors       :: String -> Maybe DecodingFctEmbedErrors
-getDecodingFctEmbedErrors enc
-    = lookup (map toUpper enc) decodingTableEmbedErrors
-
-
-
--- |
--- the table of supported output encoding schemes and the associated
--- conversion functions from Unicode
-
-outputEncodingTable     :: [(String, (UString -> String))]
-outputEncodingTable
-    = [ (utf8,          unicodeToUtf8           )
-      , (isoLatin1,     unicodeToLatin1         )
-      , (usAscii,       unicodeToXmlEntity      )
-      , (ucs2,          ucs2ToUnicode           )
-      , (unicodeString, id                      )
-      , ("",            unicodeToUtf8           )       -- default
-      ]
-
--- |
--- the lookup function for selecting the encoding function
-
-getOutputEncodingFct            :: String -> Maybe (String -> UString)
-getOutputEncodingFct enc
-    = lookup (map toUpper enc) outputEncodingTable
-
--- ------------------------------------------------------------
---
-
-guessEncoding           :: String -> String
-
-guessEncoding ('\xFF':'\xFE':'\x00':'\x00':_)   = "UCS-4LE"             -- with byte order mark
-guessEncoding ('\xFF':'\xFE':_)                 = "UTF-16LE"            -- with byte order mark
-
-guessEncoding ('\xFE':'\xFF':'\x00':'\x00':_)   = "UCS-4-3421"          -- with byte order mark
-guessEncoding ('\xFE':'\xFF':_)                 = "UTF-16BE"            -- with byte order mark
-
-guessEncoding ('\xEF':'\xBB':'\xBF':_)          = utf8                  -- with byte order mark
-
-guessEncoding ('\x00':'\x00':'\xFE':'\xFF':_)   = "UCS-4BE"             -- with byte order mark
-guessEncoding ('\x00':'\x00':'\xFF':'\xFE':_)   = "UCS-4-2143"          -- with byte order mark
-
-guessEncoding ('\x00':'\x00':'\x00':'\x3C':_)   = "UCS-4BE"             -- "<" of "<?xml"
-guessEncoding ('\x3C':'\x00':'\x00':'\x00':_)   = "UCS-4LE"             -- "<" of "<?xml"
-guessEncoding ('\x00':'\x00':'\x3C':'\x00':_)   = "UCS-4-2143"          -- "<" of "<?xml"
-guessEncoding ('\x00':'\x3C':'\x00':'\x00':_)   = "UCS-4-3412"          -- "<" of "<?xml"
-
-guessEncoding ('\x00':'\x3C':'\x00':'\x3F':_)   = "UTF-16BE"            -- "<?" of "<?xml"
-guessEncoding ('\x3C':'\x00':'\x3F':'\x00':_)   = "UTF-16LE"            -- "<?" of "<?xml"
-
-guessEncoding ('\x4C':'\x6F':'\xA7':'\x94':_)   = "EBCDIC"              -- "<?xm" of "<?xml"
-
-guessEncoding _                                 = ""                    -- no guess
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/DOM/XmlKeywords.hs b/src/Text/XML/HXT/DOM/XmlKeywords.hs
--- a/src/Text/XML/HXT/DOM/XmlKeywords.hs
+++ b/src/Text/XML/HXT/DOM/XmlKeywords.hs
@@ -26,73 +26,23 @@
 t_xml,                          -- tag names
  t_root         :: String
 
-a_accept_mimetypes,
- a_add_default_dtd,
- a_canonicalize,
- a_default,                     -- attribute names
- a_check_namespaces,
+a_default,                     -- attribute names
  a_contentLength,
- a_collect_errors,
  a_column,
- a_default_baseuri,
- a_do_not_canonicalize,
- a_do_not_check_namespaces,
- a_do_not_issue_errors,
- a_do_not_issue_warnings,
- a_do_not_preserve_comment,
- a_do_not_remove_whitespace,
- a_do_not_use_curl,
- a_do_not_validate,
  a_encoding,
- a_error,
- a_error_log,
- a_help,
- a_if_modified_since,
- a_ignore_encoding_errors,
- a_ignore_none_xml_contents,
- a_indent,
- a_issue_errors,
- a_issue_warnings,
  a_kind,
  a_line,
- a_mime_types,
  a_module,
  a_modifier,
  a_name,
- a_no_empty_elements,
- a_no_empty_elem_for,
- a_no_redirect,
- a_no_xml_pi,
- a_options_curl,
  a_output_encoding,
- a_output_file,
- a_output_xml,
- a_output_html,
- a_output_xhtml,
- a_parse_by_mimetype,
- a_parse_html,
- a_parse_xml,
  a_peref,
- a_preserve_comment,
- a_propagate_errors,
- a_proxy,
- a_remove_whitespace,
- a_redirect,
- a_show_haskell,
- a_show_tree,
  a_source,
  a_status,
  a_standalone,
- a_strict_input,
- a_tagsoup,
- a_text_mode,
- a_trace,
  a_type,
- a_use_curl,
  a_url,
- a_validate,
  a_value,
- a_verbose,
  a_version,
  a_xml,
  a_xmlns        :: String
@@ -143,73 +93,23 @@
 t_xml           = "xml"
 t_root          = "/"           -- name of root node tag
 
-a_accept_mimetypes              = "accept-mimetypes"
-a_add_default_dtd               = "add-default-dtd"
-a_canonicalize                  = "canonicalize"
-a_check_namespaces              = "check-namespaces"
-a_collect_errors                = "collect-errors"
 a_column                        = "column"
 a_contentLength                 = "Content-Length"
 a_default                       = "default"
-a_default_baseuri               = "default-base-URI"
-a_do_not_canonicalize           = "do-not-canonicalize"
-a_do_not_check_namespaces       = "do-not-check-namespaces"
-a_do_not_issue_errors           = "do-not-issue-errors"
-a_do_not_issue_warnings         = "do-not-issue-warnings"
-a_do_not_preserve_comment       = "do-not-preserve-comment"
-a_do_not_remove_whitespace      = "do-not-remove-whitespace"
-a_do_not_use_curl               = "do-not-use-curl"
-a_do_not_validate               = "do-not-validate"
 a_encoding                      = "encoding"
-a_error                         = "error"
-a_error_log                     = "errorLog"
-a_help                          = "help"
-a_if_modified_since             = "if-modified-since"
-a_ignore_encoding_errors        = "ignore-encoding-errors"
-a_ignore_none_xml_contents      = "ignore-none-xml-contents"
-a_indent                        = "indent"
-a_issue_warnings                = "issue-warnings"
-a_issue_errors                  = "issue-errors"
 a_kind                          = "kind"
 a_line                          = "line"
-a_mime_types                    = "mimetypes"
 a_module                        = "module"
 a_modifier                      = "modifier"
 a_name                          = "name"
-a_no_empty_elements             = "no-empty-elements"
-a_no_empty_elem_for             = "no-empty-elem-for"
-a_no_redirect                   = "no-redirect"
-a_no_xml_pi                     = "no-xml-pi"
-a_options_curl                  = "options-curl"
-a_output_file                   = "output-file"
 a_output_encoding               = "output-encoding"
-a_output_html                   = "output-html"
-a_output_xhtml                  = "output-xhtml"
-a_output_xml                    = "output-xml"
-a_parse_by_mimetype             = "parse-by-mimetype"
-a_parse_html                    = "parse-html"
-a_parse_xml                     = "parse-xml"
 a_peref                         = k_peref
-a_preserve_comment              = "preserve-comment"
-a_propagate_errors              = "propagate-errors"
-a_proxy                         = "proxy"
-a_redirect                      = "redirect"
-a_remove_whitespace             = "remove-whitespace"
-a_show_haskell                  = "show-haskell"
-a_show_tree                     = "show-tree"
 a_source                        = "source"
 a_standalone                    = "standalone"
 a_status                        = "status"
-a_strict_input                  = "strict-input"
-a_tagsoup                       = "tagsoup"
-a_text_mode                     = "text-mode"
-a_trace                         = "trace"
 a_type                          = "type"
 a_url                           = "url"
-a_use_curl                      = "use-curl"
-a_validate                      = "validate"
 a_value                         = "value"
-a_verbose                       = "verbose"
 a_version                       = "version"
 a_xml                           = "xml"
 a_xmlns                         = "xmlns"
@@ -301,40 +201,6 @@
 
 -- ------------------------------------------------------------
 --
--- encoding names
-
-isoLatin1
-  , iso8859_1, iso8859_2, iso8859_3, iso8859_4, iso8859_5
-  , iso8859_6, iso8859_7, iso8859_8, iso8859_9, iso8859_10
-  , iso8859_11, iso8859_13, iso8859_14, iso8859_15, iso8859_16
-  , usAscii, ucs2, utf8, utf16, utf16be, utf16le, unicodeString :: String
-
-isoLatin1       = iso8859_1
-iso8859_1       = "ISO-8859-1"
-iso8859_2       = "ISO-8859-2"
-iso8859_3       = "ISO-8859-3"
-iso8859_4       = "ISO-8859-4"
-iso8859_5       = "ISO-8859-5"
-iso8859_6       = "ISO-8859-6"
-iso8859_7       = "ISO-8859-7"
-iso8859_8       = "ISO-8859-8"
-iso8859_9       = "ISO-8859-9"
-iso8859_10      = "ISO-8859-10"
-iso8859_11      = "ISO-8859-11"
-iso8859_13      = "ISO-8859-13"
-iso8859_14      = "ISO-8859-14"
-iso8859_15      = "ISO-8859-15"
-iso8859_16      = "ISO-8859-16"
-usAscii         = "US-ASCII"
-ucs2            = "ISO-10646-UCS-2"
-utf8            = "UTF-8"
-utf16           = "UTF-16"
-utf16be         = "UTF-16BE"
-utf16le         = "UTF-16LE"
-unicodeString   = "UNICODE"
-
--- ------------------------------------------------------------
---
 -- known namespaces
 
 -- |
@@ -352,28 +218,5 @@
 -- | Relax NG namespace
 relaxNamespace  :: String
 relaxNamespace  = "http://relaxng.org/ns/structure/1.0"
-
--- ------------------------------------------------------------
--- option for Relax NG
-
-a_relax_schema,
- a_do_not_check_restrictions,
- a_check_restrictions,
- a_do_not_validate_externalRef,
- a_validate_externalRef,
- a_do_not_validate_include,
- a_validate_include,
- a_output_changes,
- a_do_not_collect_errors :: String
-
-a_relax_schema                = "relax-schema"
-a_do_not_check_restrictions   = "do-not-check-restrictions"
-a_check_restrictions          = "check-restrictions"
-a_do_not_validate_externalRef = "do-not-validate-externalRef"
-a_validate_externalRef        = "validate-externalRef"
-a_do_not_validate_include     = "do-not-validate-include"
-a_validate_include            = "validate-include"
-a_output_changes              = "output-pattern-transformations"
-a_do_not_collect_errors       = "do-not-collect-errors"
 
 -- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/DOM/XmlOptions.hs b/src/Text/XML/HXT/DOM/XmlOptions.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/DOM/XmlOptions.hs
+++ /dev/null
@@ -1,188 +0,0 @@
--- |
--- Common useful options
---
--- Version : $Id: XmlOptions.hs,v 1.1 2006/11/09 20:27:42 hxml Exp $
---
---
-
-module Text.XML.HXT.DOM.XmlOptions
-    ( inputOptions
-    , relaxOptions
-    , outputOptions
-    , generalOptions
-    , versionOptions
-    , showOptions
-
-    , selectOptions
-    , removeOptions
-    , optionIsSet
-    , isTrueValue
-    )
-where
-
-import Text.XML.HXT.DOM.XmlKeywords
-import Text.XML.HXT.DOM.TypeDefs
-
-import Data.Maybe
-
-import System.Console.GetOpt
-
--- ------------------------------------------------------------
---
-
--- |
--- commonly useful options for XML input
---
--- can be used for option definition with haskell getopt
---
--- defines options: 'a_trace', 'a_proxy', 'a_use_curl', 'a_do_not_use_curl', 'a_options_curl', 'a_encoding',
--- 'a_issue_errors', 'a_do_not_issue_errors', 'a_parse_html', 'a_parse_by_mimetype', 'a_tagsoup' 'a_issue_warnings', 'a_do_not_issue_warnings',
--- 'a_parse_xml', 'a_validate', 'a_do_not_validate', 'a_canonicalize', 'a_do_not_canonicalize',
---- 'a_preserve_comment', 'a_do_not_preserve_comment', 'a_check_namespaces', 'a_do_not_check_namespaces',
--- 'a_remove_whitespace', 'a_do_not_remove_whitespace'
-
-inputOptions    :: [OptDescr (String, String)]
-inputOptions
-    = [ Option "t"      [a_trace]                       (OptArg trc "LEVEL")                    "trace level (0-4), default 1"
-      , Option "p"      [a_proxy]                       (ReqArg (att a_proxy)         "PROXY")  "proxy for http access (e.g. \"www-cache:3128\")"
-      , Option ""       [a_redirect]                    (NoArg  (att a_redirect          v_1))  "automatically follow redirected URIs"
-      , Option ""       [a_no_redirect]                 (NoArg  (att a_redirect          v_0))  "switch off following redirected URIs"
-      , Option ""       [a_use_curl]                    (NoArg  (att a_use_curl          v_1))  "obsolete, since hxt-8.1 HTTP access is always done with curl bindings"
-      , Option ""       [a_do_not_use_curl]             (NoArg  (att a_use_curl          v_0))  "obsolete, since hxt-8.1 HTTP access is always done with curl bindings"
-      , Option ""       [a_options_curl]                (ReqArg (att a_options_curl)    "STR")  "additional curl options, e.g. for timeout, ..."
-      , Option ""       [a_default_baseuri]             (ReqArg (att transferURI)       "URI")  "default base URI, default: \"file:///<cwd>/\""
-      , Option "e"      [a_encoding]                    (ReqArg (att a_encoding)    "CHARSET")  ( "default document encoding (" ++ utf8 ++ ", " ++ isoLatin1 ++ ", " ++ usAscii ++ ", ...)" )
-      , Option ""       [a_mime_types]                  (ReqArg (att a_mime_types)     "FILE")  "set mime type configuration file, e.g. \"/etc/mime.types\""
-      , Option ""       [a_issue_errors]                (NoArg  (att a_issue_errors      v_1))  "issue all errorr messages on stderr (default)"
-      , Option ""       [a_do_not_issue_errors]         (NoArg  (att a_issue_errors      v_0))  "ignore all error messages"
-      , Option ""       [a_ignore_encoding_errors]      (NoArg  (att a_ignore_encoding_errors v_1))   "ignore encoding errors"
-      , Option ""       [a_ignore_none_xml_contents]    (NoArg  (att a_ignore_none_xml_contents v_1)) "discards all contents of none XML/HTML documents, only the meta info remains in the doc tree"
-      , Option ""       [a_accept_mimetypes]            (ReqArg (att a_accept_mimetypes) "MIMETYPES") "only accept documents matching the given list of mimetype specs"
-      , Option "H"      [a_parse_html]                  (NoArg  (att a_parse_html        v_1))  "parse input as HTML, try to interprete everything as HTML, no validation"
-      , Option "M"      [a_parse_by_mimetype]           (NoArg  (att a_parse_by_mimetype v_1))  "parse dependent on mime type: text/html as HTML, text/xml and text/xhtml and others as XML, else no parse"
-      , Option ""       [a_parse_xml]                   (NoArg  (att a_parse_html        v_0))  "parse input as XML, (default)"
-      , Option ""       [a_strict_input]                (NoArg  (att a_strict_input      v_1))  "read input files strictly, this ensures closing the files correctly even if not read completely"
-      , Option "T"      [a_tagsoup]                     (NoArg  (att a_tagsoup           v_1))  "lazy tagsoup parser, for HTML and XML, no DTD, no validation, no PIs, only XHTML entityrefs"
-      , Option ""       [a_issue_warnings]              (NoArg  (att a_issue_warnings    v_1))  "issue warnings, when parsing HTML (default)"
-      , Option "Q"      [a_do_not_issue_warnings]       (NoArg  (att a_issue_warnings    v_0))  "ignore warnings, when parsing HTML"
-      , Option ""       [a_validate]                    (NoArg  (att a_validate          v_1))  "document validation when parsing XML (default)"
-      , Option "w"      [a_do_not_validate]             (NoArg  (att a_validate          v_0))  "only wellformed check, no validation"
-      , Option ""       [a_canonicalize]                (NoArg  (att a_canonicalize      v_1))  "canonicalize document, remove DTD, comment, transform CDATA, CharRef's, ... (default)"
-      , Option "c"      [a_do_not_canonicalize]         (NoArg  (att a_canonicalize      v_0))  "do not canonicalize document, don't remove DTD, comment, don't transform CDATA, CharRef's, ..."
-      , Option "C"      [a_preserve_comment]            (NoArg  (att a_preserve_comment  v_1))  "don't remove comments during canonicalisation"
-      , Option ""       [a_do_not_preserve_comment]     (NoArg  (att a_preserve_comment  v_0))  "remove comments during canonicalisation (default)"
-      , Option "n"      [a_check_namespaces]            (NoArg  (att a_check_namespaces  v_1))  "tag tree with namespace information and check namespaces"
-      , Option ""       [a_do_not_check_namespaces]     (NoArg  (att a_check_namespaces  v_0))  "ignore namespaces (default)"
-      , Option "r"      [a_remove_whitespace]           (NoArg  (att a_remove_whitespace v_1))  "remove redundant whitespace, simplifies tree and processing"
-      , Option ""       [a_do_not_remove_whitespace]    (NoArg  (att a_remove_whitespace v_0))  "don't remove redundant whitespace (default)"
-      ]
-    where
-    att n v     = (n, v)
-    trc = att a_trace . show . max 0 . min 9 . (read :: String -> Int) . ('0':) . filter (`elem` "0123456789") . fromMaybe v_1
-
-
--- | available Relax NG validation options
---
--- defines options
--- 'a_check_restrictions', 'a_validate_externalRef', 'a_validate_include', 'a_do_not_check_restrictions',
--- 'a_do_not_validate_externalRef', 'a_do_not_validate_include'
-
-relaxOptions :: [OptDescr (String, String)]
-relaxOptions
-    = [ Option "X" [a_relax_schema]                     (ReqArg (att a_relax_schema) "SCHEMA")  "validation with Relax NG, SCHEMA is the URI for the Relax NG schema"
-      , Option ""  [a_check_restrictions]               (NoArg (a_check_restrictions,    v_1))  "check Relax NG schema restrictions during schema simplification (default)"
-      , Option ""  [a_do_not_check_restrictions]        (NoArg (a_check_restrictions,    v_0))  "do not check Relax NG schema restrictions"
-      , Option ""  [a_validate_externalRef]             (NoArg (a_validate_externalRef,  v_1))  "validate a Relax NG schema referenced by a externalRef-Pattern (default)"
-      , Option ""  [a_do_not_validate_externalRef]      (NoArg (a_validate_externalRef,  v_0))  "do not validate a Relax NG schema referenced by an externalRef-Pattern"
-      , Option ""  [a_validate_include]                 (NoArg (a_validate_include,      v_1))  "validate a Relax NG schema referenced by an include-Pattern (default)"
-      , Option ""  [a_do_not_validate_include]          (NoArg (a_validate_include,      v_0))   "do not validate a Relax NG schema referenced by an include-Pattern"
-        {-
-      , Option ""  [a_output_changes]                   (NoArg (a_output_changes,        v_1))  "output Pattern transformations in case of an error"
-      , Option ""  [a_do_not_collect_errors]            (NoArg (a_do_not_collect_errors, v_1))  "stop Relax NG simplification after the first error has occurred"
-        -}
-      ]
-    where
-    att n v     = (n, v)
-
--- |
--- commonly useful options for XML output
---
--- defines options: 'a_indent', 'a_output_encoding', 'a_output_file', 'a_output_html'
-
-outputOptions   :: [OptDescr (String, String)]
-outputOptions
-    = [ Option "i"      [a_indent]              (NoArg  (att a_indent                v_1))      "indent XML output for readability"
-      , Option "o"      [a_output_encoding]     (ReqArg (att a_output_encoding) "CHARSET")      ( "encoding of output (" ++ utf8 ++ ", " ++ isoLatin1 ++ ", " ++ usAscii ++ ")" )
-      , Option "f"      [a_output_file]         (ReqArg (att a_output_file)        "FILE")      "output file for resulting document (default: stdout)"
-      , Option ""       [a_output_html]         (NoArg  (att a_output_html           v_1))      "output of none ASCII chars as HTMl entity references"
-      , Option ""       [a_no_xml_pi]           (NoArg  (att a_no_xml_pi             v_1))      ("output without <?xml ...?> processing instruction, useful in combination with --" ++ show a_output_html)
-      , Option ""       [a_output_xhtml]        (NoArg  (att a_output_xhtml          v_1))      "output of HTML elements with empty content (script, ...) done in format <elem...></elem> instead of <elem/>"
-      , Option ""       [a_no_empty_elem_for]   (ReqArg (att a_no_empty_elem_for) "NAMES")      "output of empty elements done in format <elem...></elem> only for given list of element names"
-      , Option ""       [a_no_empty_elements]   (NoArg  (att a_no_empty_elements     v_1))      "output of empty elements done in format <elem...></elem> instead of <elem/>"
-      , Option ""       [a_add_default_dtd]     (NoArg  (att a_add_default_dtd       v_1))      "add the document type declaration given in the input document"
-      , Option ""       [a_text_mode]           (NoArg  (att a_text_mode             v_1))      "output in text mode"
-      ]
-    where
-    att n v     = (n, v)
-
--- |
--- commonly useful options
---
--- defines options: 'a_verbose', 'a_help'
-
-generalOptions  :: [OptDescr (String, String)]
-generalOptions
-    = [ Option "v"      [a_verbose]             (NoArg  (a_verbose, v_1))               "verbose output"
-      , Option "h?"     [a_help]                (NoArg  (a_help,    v_1))               "this message"
-      ]
-
--- |
--- defines 'a_version' option
-
-versionOptions  :: [OptDescr (String, String)]
-versionOptions
-    = [ Option "V"      [a_version]             (NoArg  (a_version, v_1))               "show program version"
-      ]
-
--- |
--- debug output options
-
-showOptions     :: [OptDescr (String, String)]
-showOptions
-    = [ Option ""       [a_show_tree]           (NoArg  (a_show_tree,    v_1))          "output tree representation instead of document source"
-      , Option ""       [a_show_haskell]        (NoArg  (a_show_haskell, v_1))          "output internal Haskell representation instead of document source"
-      ]
-
--- ------------------------------------------------------------
-
--- |
--- select options from a predefined list of option desciptions
-
-selectOptions   :: [String] -> [OptDescr (String, String)] -> [OptDescr (String, String)]
-selectOptions ol os
-    = concat . map (\ on -> filter (\ (Option _ ons _ _) -> on `elem` ons) os) $ ol
-
-removeOptions   :: [String] -> [OptDescr (String, String)] -> [OptDescr (String, String)]
-removeOptions ol os
-    = filter (\ (Option _ ons _ _) -> not . any (`elem` ol) $ ons ) os
-
--- |
--- check whether an option is set
---
--- reads the value of an attribute, usually applied to a document root node,
--- and checks if the value represents True. The following strings are interpreted
--- as true: \"1\", \"True\", \"true\", \"yes\", \"Yes\".
-
-optionIsSet     :: String -> Attributes -> Bool
-optionIsSet n   = isTrueValue . lookupDef "" n
-
--- | check whether a string represents True
---
--- definition:
---
--- > isTrueValue        = (`elem` ["1", "True", "true", "Yes", "yes"])
-
-isTrueValue     :: String -> Bool
-isTrueValue     = (`elem` ["1", "True", "true", "Yes", "yes"])
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/DTDValidation/DocTransformation.hs b/src/Text/XML/HXT/DTDValidation/DocTransformation.hs
--- a/src/Text/XML/HXT/DTDValidation/DocTransformation.hs
+++ b/src/Text/XML/HXT/DTDValidation/DocTransformation.hs
@@ -42,6 +42,7 @@
 import Data.Maybe
 import Data.List
 import Data.Ord
+import qualified Data.Map as M
 
 -- ------------------------------------------------------------
 
@@ -49,8 +50,7 @@
 -- Lookup-table which maps element names to their transformation functions. The
 -- transformation functions are XmlArrows.
 
-type TransEnvTable      = [TransEnv]
-type TransEnv           = (ElemName, TransFct)
+type TransEnvTable      = M.Map ElemName TransFct
 type ElemName           = String
 type TransFct           = XmlArrow
 
@@ -81,18 +81,15 @@
 
 traverseTree :: TransEnvTable -> XmlArrow
 traverseTree transEnv
-    = processTopDown
-      ( ( (transFct $< getName)
-          >>>
-          processChildren (traverseTree transEnv)
-        )
-       `when`
-       isElem
-      )
+    = processTopDown ( (transFct $< getName)
+		       `when`
+		       isElem
+		     )
     where
     transFct            :: String -> XmlArrow
-    transFct name       = fromMaybe this . lookup name $ transEnv
+    transFct name       = fromMaybe this . M.lookup name $ transEnv
 
+
 -- |
 -- Build all transformation functions.
 --
@@ -102,7 +99,8 @@
 
 buildAllTransformationFunctions :: XmlTrees -> TransEnvTable
 buildAllTransformationFunctions dtdNodes
-    = (t_root, this)
+    = M.fromList $
+      (t_root, this)
       :
       concatMap (buildTransformationFunctions dtdNodes) dtdNodes
 
@@ -116,7 +114,7 @@
 --
 --    - returns : entry for the lookup-table
 
-buildTransformationFunctions :: XmlTrees -> XmlTree -> [TransEnv]
+buildTransformationFunctions :: XmlTrees -> XmlTree -> [(ElemName, TransFct)]
 
 buildTransformationFunctions dtdPart dn
     | isDTDElementNode dn       = [(name, transFct)]
diff --git a/src/Text/XML/HXT/IO/GetHTTPLibCurl.hs b/src/Text/XML/HXT/IO/GetHTTPLibCurl.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/IO/GetHTTPLibCurl.hs
+++ /dev/null
@@ -1,310 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.IO.GetHTTPLibCurl
-   Copyright  : Copyright (C) 2008 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : stable
-   Portability: portable
-
-   GET for http access with libcurl
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.IO.GetHTTPLibCurl
-    ( getCont
-    )
-
-where
-
-import Control.Arrow                    ( first
-                                        , (>>>)
-                                        )
-import Control.Concurrent.MVar
-import Control.Monad                    ( when )
-
-import qualified Data.ByteString        as B
-import qualified Data.ByteString.Char8  as C
-
-import Data.Char                        ( isDigit
-                                        , isSpace
-                                        )
-import Data.List                        ( isPrefixOf )
-
-import Network.Curl
-
-import System.IO
-import System.IO.Unsafe                 ( unsafePerformIO )
-
-import Text.ParserCombinators.Parsec    ( parse )
-
-import Text.XML.HXT.DOM.Util            ( stringToLower )
-import Text.XML.HXT.DOM.XmlKeywords
-import Text.XML.HXT.DOM.XmlOptions      ( isTrueValue )
-
-import Text.XML.HXT.Parser.ProtocolHandlerUtil
-                                        ( parseContentType )
-import Text.XML.HXT.Version
-
--- ------------------------------------------------------------
---
--- the global flag for initializing curl in the 1. call
-
-isInitCurl      :: MVar Bool
-isInitCurl      = unsafePerformIO $ newMVar False
-
-{-# NOINLINE isInitCurl #-}
-
-initCurl        :: IO ()
-initCurl
-    = do
-      i <- takeMVar isInitCurl
-      when (not i) ( do
-                     _ <- curl_global_init 3
-                     return ()
-                   )
-      putMVar isInitCurl True
-
--- ------------------------------------------------------------
-
--- The curl lib is not thread save
-
-curlResource    :: MVar ()
-curlResource    = unsafePerformIO $ newMVar ()
-
-{-# NOINLINE curlResource #-}
-
-requestCurl     :: IO ()
-requestCurl     = takeMVar curlResource
-
-releaseCurl     :: IO ()
-releaseCurl     = putMVar curlResource ()
-
--- ------------------------------------------------------------
-
---
--- the http protocol handler implemented by calling libcurl
--- (<http://curl.haxx.se/>)
--- via the curl binding
--- <http://hackage.haskell.org/cgi-bin/hackage-scripts/package/curl>
--- This function tries to support mostly all curl options concerning HTTP requests.
--- The naming convetion is as follows: A curl option must be prefixed by the string
--- \"curl\" and then written exactly as described in the curl man page
--- (<http://curl.haxx.se/docs/manpage.html>).
---
--- Example:
---
--- > getCont [("curl--user-agent","My first HXT app"),("curl-e","http://the.referer.url/")] "http://..."
---
--- will set the user agent and the referer URL for this request.
-
-getCont         :: [(String, String)] -> String -> IO (Either ([(String, String)], String)
-                                                              ([(String, String)], String))
-getCont options uri
-    = do
-      initCurl
-      requestCurl
-      resp <- curlGetResponse_ uri curlOptions
-      let resp' = evalResponse resp
-      resp' `seq`
-            releaseCurl
-      -- dumpResponse
-      return resp'
-    where
-    _dumpResponse r
-        = do
-          hPutStrLn stderr $ show $ respCurlCode   r
-          hPutStrLn stderr $ show $ respStatus     r
-          hPutStrLn stderr $        respStatusLine r
-          hPutStrLn stderr $ show $ respHeaders    r
-          hPutStrLn stderr $        respBody       r
-
-    curlOptions
-        = defaultOptions ++ concatMap (uncurry copt) options ++ standardOptions
-
-    defaultOptions                                              -- these options may be overwritten
-        = [ CurlUserAgent ("hxt/" ++ hxt_version ++ " via libcurl")
-          , CurlFollowLocation True
-          ]
-
-    standardOptions                                             -- these options can't be overwritten
-        = [ CurlFailOnError    False
-          , CurlHeader         False
-          , CurlNoProgress     True
-          ]
-    evalResponse r
-        | rc /= CurlOK
-            = Left ( [ mkH transferStatus    "999"
-                     , mkH transferMessage $ "curl library rc: " ++ show rc
-                     ]
-                   , "curl library error when requesting URI "
-                     ++ show uri
-                     ++ ": (curl return code=" ++ show rc ++ ") "
-                   )
-        | rs < 200 && rs >= 300
-            = Left ( contentT rsh ++ headers
-                   , "http error when accessing URI "
-                     ++ show uri
-                     ++ ": "
-                     ++ show rsl
-                   )
-        | otherwise
-            = B.length body
-              `seq`
-              Right ( contentT rsh ++ headers
-                    , C.unpack body
-                    )
-        where
-        body :: B.ByteString
-        body = respBody r
-
-        mkH x y = (x, dropWhile isSpace y)
-
-        headers
-            = map (\ (k, v) -> mkH (httpPrefix ++ stringToLower k) v) rsh
-              ++
-              statusLine (words rsl)
-
-        contentT
-            = map (first stringToLower)                 -- all header names to lowercase
-              >>>
-              filter ((== "content-type") . fst)        -- select content-type header
-              >>>
-              reverse                                   -- when libcurl is called with automatic redirects, there are more than one content-type headers
-              >>>
-              take 1                                    -- take the last one, (if at leat one is found)
-              >>>
-              map snd                                   -- select content-type value
-              >>>
-              map ( either (const []) id
-                    . parse parseContentType ""         -- parse the content-type for mimetype and charset
-                  )
-              >>>
-              concat
-
-        statusLine (vers : _code : msg)                 -- the status line of the curl response can be an old one, e.g. in the case of a redirect,
-            = [ mkH transferVersion   vers              -- so the return code is taken from the status field, which is contains the last status
-              , mkH transferMessage $ unwords msg
-              , mkH transferStatus  $ show rs
-              ]
-        statusLine _
-            = []
-
-        rc  = respCurlCode    r
-        rs  = respStatus      r
-        rsl = respStatusLine  r
-        rsh = respHeaders     r
-
--- ------------------------------------------------------------
-
-copt    :: String -> String -> [CurlOption]
-copt k v
-    | "curl" `isPrefixOf` k
-        = opt2copt (drop 4 k) v
-
-    | k `elem` [a_proxy, a_redirect]
-        = opt2copt k v
-
-    | k == a_options_curl
-        = curlOptionString v
-
-    | otherwise
-        = []
-
-opt2copt        :: String -> String -> [CurlOption]
-opt2copt k v
-    | k `elem` ["-A", "--user-agent"]   = [CurlUserAgent v]
-    | k `elem` ["-b", "--cookie"]       = [CurlCookie v]
-    | k == "--connect-timeout"
-      &&
-      isIntArg v                        = [CurlConnectTimeout      $ read    v]
-    | k == "--crlf"                     = [CurlCRLF                $ isTrue  v]
-    | k `elem` ["-d", "--data"]         = [CurlPostFields          $ lines   v]
-    | k `elem` ["-e", "--referer"]      = [CurlReferer                       v]
-    | k `elem` ["-H", "--header"]       = [CurlHttpHeaders         $ lines   v]
-    | k == "--ignore-content-length"    = [CurlIgnoreContentLength $ isTrue  v]
-    | k `elem` ["-I", "--head"]         = [CurlNoBody              $ isTrue  v]
-    | k `elem` ["-L", "--location", a_redirect]
-                                        = [CurlFollowLocation      $ isTrue  v]
-    | k == "--max-filesize"
-      &&
-      isIntArg v                        = [CurlMaxFileSizeLarge    $ read    v]
-    | k `elem` ["-m", "--max-time"]
-      &&
-      isIntArg v                        = [CurlTimeoutMS           $ read    v]
-    | k `elem` ["-n", "--netrc"]        = [CurlNetrcFile                     v]
-    | k `elem` ["--ssl-verify-peer"]    = [CurlSSLVerifyPeer $ read v]
-    | k `elem` ["-R", "--remote-time"]  = [CurlFiletime            $ isTrue  v]
-    | k `elem` ["-u", "--user"]         = [CurlUserPwd                       v]
-    | k `elem` ["-U", "--proxy-user"]   = [CurlProxyUserPwd                  v]
-    | k `elem` ["-x", "--proxy", a_proxy]
-                                        =  proxyOptions
-    | k `elem` ["-X", "--request"]      = [CurlCustomRequest                 v]
-    | k `elem` ["-y", "--speed-time"]
-      &&
-      isIntArg v                        = [CurlLowSpeedTime        $ read    v]
-    | k `elem` ["-Y", "--speed-limit"]
-      &&
-      isIntArg v                        = [CurlLowSpeed            $ read    v]
-    | k `elem` ["-z", "--time-cond", a_if_modified_since]
-                                        =  ifModifiedOptions
-
-    | k == a_if_modified_since          = [CurlHttpHeaders         $ ["If-Modified-Since: " ++ v] ]
-                                        -- CurlTimeValue seems to be buggy, therefore this workaround
-    | k == "--max-redirs"
-      &&
-      isIntArg v                        = [CurlMaxRedirs           $ read    v]
-    | k `elem` ["-0", "--http1.0"]      = [CurlHttpVersion       HttpVersion10]
-    | otherwise                         = []
-    where
-    ifModifiedOptions
-        | "-" `isPrefixOf` v
-          &&
-          isIntArg v'                   = [CurlTimeCondition TimeCondIfUnmodSince
-                                          ,CurlTimeValue           $ read   v'
-                                          ]
-        | isIntArg v                    = [CurlTimeCondition TimeCondIfModSince
-                                          ,CurlTimeValue           $ read   v'
-                                          ]
-        | otherwise                     = []
-        where
-        v' = tail v
-
-    proxyOptions
-        = [ CurlProxyPort pport
-          , CurlProxy     phost
-          ]
-        where
-        pport
-            | isIntArg ppp      = read v
-            | otherwise         = 1080
-        (phost, pp)             = span (/=':') v
-        ppp                     = drop 1 pp
-
-
-
-isTrue          :: String -> Bool
-isTrue s        = null s || isTrueValue s
-
-isIntArg        :: String -> Bool
-isIntArg s      = not (null s) && all isDigit s
-
-curlOptionString        :: String -> [CurlOption]
-curlOptionString
-    = concatMap (uncurry copt) . opts . words
-    where
-    opts l
-        | null l                        = []
-        | not ("-" `isPrefixOf` k)      = opts l1               -- k not an option: ignore
-        | null l1                       = opts (k:"":l1)        -- last option
-        | "-" `isPrefixOf` v            = (k, "") : opts (v:l)  -- k option without arg
-        | otherwise                     = (k, v) : opts l2      -- k with value
-        where
-        (k:l1) = l
-        (v:l2) = l1
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Parser/TagSoup.hs b/src/Text/XML/HXT/Parser/TagSoup.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/Parser/TagSoup.hs
+++ /dev/null
@@ -1,495 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.Parser.TagSoup
-   Copyright  : Copyright (C) 2005-2008 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
-   Portability: portable
-
-   lazy HTML and simpe XML parser implemented with tagsoup
-   parsing is done with a very simple monadic top down parser
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.Parser.TagSoup
-    ( parseHtmlTagSoup
-    )
-where
-
--- ------------------------------------------------------------
-
-import Data.Char (toLower)
-import Data.Maybe
-
-import Text.HTML.TagSoup
-import Text.HTML.TagSoup.Entity         ( lookupNumericEntity
-                                        )
-import Text.XML.HXT.DOM.Unicode         ( isXmlSpaceChar
-                                        )
-import Text.XML.HXT.Parser.HtmlParsec   ( isEmptyHtmlTag
-                                        , isInnerHtmlTagOf
-                                        , closesHtmlTag
-                                        )
-import Text.XML.HXT.Parser.XhtmlEntities
-import Text.XML.HXT.DOM.Interface       ( XmlTrees
-                                        , QName
-                                        , NsEnv
-                                        , toNsEnv
-                                        , newXName
-                                        , nullXName
-                                        , mkQName'
-                                        , mkName
-                                        , isWellformedQualifiedName
-                                        , c_warn
-                                        , a_xml
-                                        , a_xmlns
-                                        , xmlNamespace
-                                        , xmlnsNamespace
-                                        )
-import Text.XML.HXT.DOM.XmlNode         ( isElem
-                                        , mkError
-                                        , mkCmt
-                                        , mkText
-                                        , mkElement
-                                        , mkAttr
-                                        )
-
--- ----------------------------------------
-
--- The name table contains the id map. All element and attribute names are stored
--- the first time they are ecountered, and later always this name is used,
--- not a string built by the parser.
-
-type STag               = Tag String
-
-type Tags               = [STag]
-
-type Context            = ([String], NsEnv)
-
-type State              = Tags
-
-newtype Parser a        = P { parse :: State -> (a, State)}
-
-instance Monad Parser where
-    return x    = P $ \ ts -> (x, ts)
-    p >>= f     = P $ \ ts -> let
-                              (res, ts') = parse p ts
-                              in
-                              parse (f res) ts'
-
-runParser       :: Parser a -> Tags -> a
-runParser p ts  = fst . parse p $ ts
-
--- ----------------------------------------
-
-cond            :: Parser Bool -> Parser a -> Parser a -> Parser a
-cond c t e      = do
-                  p <- c
-                  if p then t else e
-
-lookAhead       :: (STag -> Bool) -> Parser Bool
-lookAhead p     = P $ \ s -> (not (null s) && p (head s), s)
-
--- ----------------------------------------
--- primitive look ahead tests
-
-isEof           :: Parser Bool
-isEof           = P $ \ s -> (null s, s)
-
-isText          :: Parser Bool
-isText          = lookAhead is
-                  where
-                  is (TagText _) = True
-                  is _           = False
-
-isCmt           :: Parser Bool
-isCmt           = lookAhead is
-                  where
-                  is (TagComment _) = True
-                  is _              = False
-
-isWarn          :: Parser Bool
-isWarn          = lookAhead is
-                  where
-                  is (TagWarning _) = True
-                  is _              = False
-
-isPos           :: Parser Bool
-isPos           = lookAhead is
-                  where
-                  is (TagPosition _ _) = True
-                  is _           = False
-
-isCls           :: Parser Bool
-isCls           = lookAhead is
-                  where
-                  is (TagClose _) = True
-                  is _            = False
-
-isOpn           :: Parser Bool
-isOpn           = lookAhead is
-                  where
-                  is (TagOpen _ _) = True
-                  is _             = False
-
--- ----------------------------------------
--- primitive symbol parsers
-
-getTag          :: Parser STag
-getTag          = P $ \ (t1:ts1) -> (t1, ts1)
-
-getSym          :: (STag -> a) -> Parser a
-getSym f        = do
-                  t <- getTag
-                  return (f t)
-
-getText         :: Parser String
-getText         = getSym sym
-                  where
-                  sym (TagText t)       = t
-                  sym _                 = undefined
-
-getCmt          :: Parser String
-getCmt          = getSym sym
-                  where
-                  sym (TagComment c)    = c
-                  sym _                 = undefined
-
-getWarn         :: Parser String
-getWarn         = getSym sym
-                  where
-                  sym (TagWarning w)    = w
-                  sym _                 = undefined
-
-getPos          :: Parser (Int, Int)
-getPos          = getSym sym
-                  where
-                  sym (TagPosition l c) = (l, c)
-                  sym _                 = undefined
-
-getCls          :: Parser String
-getCls          = getSym sym
-                  where
-                  sym (TagClose n)      = n
-                  sym _                 = undefined
-
-getOpn          :: Parser (String, [(String,String)])
-getOpn          = getSym sym
-                  where
-                  sym (TagOpen n al)    = (n, al)
-                  sym _                 = undefined
-
--- ----------------------------------------
--- pushback parsers for inserting missing tags
-
-pushBack        :: STag -> Parser ()
-pushBack t      = P $ \ ts -> ((), t:ts)
-
-insCls          :: String -> Parser ()
-insCls n        = pushBack (TagClose n)
-
-insOpn          :: String -> [(String, String)] -> Parser ()
-insOpn n al     = pushBack (TagOpen n al)
-
--- ----------------------------------------
-
-mkQN            :: Bool -> Bool -> NsEnv -> String -> Parser QName
-mkQN withNamespaces isAttr env s
-    | withNamespaces
-        = return qn1
-    | otherwise
-        = return qn0
-    where
-    qn1
-        | isAttr && isSimpleName        = s'
-        | isSimpleName                  = mkQName' nullXName (newXName s) (nsUri nullXName)
-        | isWellformedQualifiedName s   = mkQName' px'        lp'         (nsUri px')
-        | otherwise                     = s'
-    qn0                                 = s'
-
-    nsUri x                             = fromMaybe nullXName . lookup x $ env
-    isSimpleName                        = all (/= ':') s
-    (px, (_ : lp))                      = span(/= ':') s
-    px'                                 = newXName px
-    lp'                                 = newXName lp
-    s'                                  = mkName   s
-
-extendNsEnv     :: Bool -> [(String, String)] -> NsEnv -> NsEnv
-extendNsEnv withNamespaces al1 env
-    | withNamespaces
-        = toNsEnv (concatMap (uncurry addNs) al1) ++ env
-    | otherwise
-        = env
-    where
-    addNs n v
-        | px == a_xmlns
-          &&
-          (null lp || (not . null . tail $ lp))
-            = [(drop 1 lp, v)]
-        | otherwise
-            = []
-        where
-        (px, lp) = span (/= ':') n
-
--- ----------------------------------------
-
--- own entity lookup to prevent problems with &amp; and tagsoup hack for IE
-
-lookupEntity    :: Bool -> Bool -> (String, Bool) -> Tags
-lookupEntity withWarnings _asHtml (e0@('#':e), withSemicolon)
-    = case lookupNumericEntity e of
-      Just c  -> (TagText [c])
-		 : missingSemi
-      Nothing -> ( TagText $ "&" ++ e0 ++ [';' | withSemicolon])
-		 : if withWarnings
-                   then (TagWarning $ "illegal char reference: &" ++ e ++ ";")
-		        : missingSemi
-		   else []
-    where
-    missingSemi
-	| withWarnings
-	  &&
-	  not withSemicolon = [TagWarning $ "missing \";\" at end of char reference: &" ++ e]
-        | otherwise         = []
-
-lookupEntity withWarnings asHtml (e, withSemicolon)
-    = case (lookup e entities) of
-      Just x  -> (TagText [toEnum x])
-		 : missingSemi
-      Nothing -> (TagText $ "&" ++ e ++ [';' | withSemicolon])
-		 : if withWarnings
-                   then (TagWarning $ "Unknown entity reference: &" ++ e ++ ";")
-			: missingSemi
-		   else []
-    where
-    entities
-        | asHtml    = xhtmlEntities
-        | otherwise = xhtmlEntities -- xmlEntities (TODO: xhtml is xml and html)
-    missingSemi
-	| withWarnings
-	  &&
-	  not withSemicolon = [TagWarning $ "missing \";\" at end of entity reference: &" ++ e]
-        | otherwise         = []
-
-lookupEntityAttr        :: Bool -> Bool -> (String, Bool) -> (String, Tags)
-lookupEntityAttr withWarnings asHtml (e, b)
-    | null r    = (s,                   r)
-    | otherwise = ("&" ++ s ++ [';' | b], r)
-    where
-    (TagText s) : r = lookupEntity withWarnings asHtml (e, b)
-
--- ----------------------------------------
-{-
-        entityData x = case lookupEntity y of
-            Just y -> [TagText $ fromChar y]
-            Nothing -> [TagText $ fromString $ "&" ++ y ++ ";"
-                       ,TagWarning $ fromString $ "Unknown entity: " ++ y]
-            where y = toString x
-
-        entityAttrib (x,b) = case lookupEntity y of
-            Just y -> (fromChar y, [])
-            Nothing -> (fromString $ "&" ++ y ++ [';'|b], [TagWarning $ fromString $ "Unknown entity: " ++ y])
-            where y = toString x
--}
--- ----------------------------------------
-
--- |
--- Turns all element and attribute names to lower case
--- even !DOCTYPE stuff. But this is discarded when parsing the tagsoup
-
-lowerCaseNames :: Tags -> Tags
-lowerCaseNames
-    = map f
-    where
-    f (TagOpen name attrs)
-        = TagOpen (nameToLower name) (map attrToLower attrs)
-    f (TagClose name)
-        = TagClose (nameToLower name)
-    f a = a
-    nameToLower          = map toLower
-    attrToLower (an, av) = (nameToLower an, av)
-
--- ----------------------------------------
--- the main parser
-
-parseHtmlTagSoup        :: Bool -> Bool -> Bool -> Bool -> Bool -> String -> String -> XmlTrees
-parseHtmlTagSoup withNamespaces withWarnings withComment removeWhiteSpace asHtml doc
-    = ( docRootElem
-        . runParser (buildCont initContext)
-        . ( if asHtml
-            then lowerCaseNames
-            else id
-          )
-        . tagsoupParse
-      )
-    where
-    tagsoupParse        :: String -> Tags
-    tagsoupParse        = parseTagsOptions tagsoupOptions
-
-    tagsoupOptions      :: ParseOptions String
-    tagsoupOptions      = parseOptions' { optTagWarning   = withWarnings
-                                        , optEntityData   = lookupEntity     withWarnings asHtml
-                                        , optEntityAttrib = lookupEntityAttr withWarnings asHtml
-                                        }
-                          where
-                          parseOptions' :: ParseOptions String
-                          parseOptions' = parseOptions
-
-    -- This is essential for lazy parsing:
-    -- the call of "take 1" stops parsing, when the first element is detected
-    -- no check on end of input sequence is required to build this (0- or 1-element list)
-    -- so eof is never checked unneccessarily
-
-    docRootElem
-        = take 1 . filter isElem
-
-    initContext         = ( []
-                          , toNsEnv $
-                            [ (a_xml,   xmlNamespace)
-                            , (a_xmlns, xmlnsNamespace)
-                            ]
-                          )
-
-    wrap                = (:[])
-
-    warn
-        | withWarnings  = wrap . mkError c_warn . show . (doc ++) . (" " ++)
-        | otherwise     = const []
-    cmt
-        | withComment   = wrap . mkCmt
-        | otherwise     = const []
-    txt
-        | removeWhiteSpace
-                        = \ t ->
-                          if all isXmlSpaceChar t
-                          then []
-                          else wrap . mkText $ t
-        | otherwise     = wrap . mkText
-
-    isEmptyElem
-        | asHtml        = isEmptyHtmlTag
-        | otherwise     = const False
-
-    isInnerElem
-        | asHtml        = isInnerHtmlTagOf
-        | otherwise     = const (const False)
-
-    closesElem
-        | asHtml        = \ ns n1 ->
-                          not (null ns)
-                          &&
-                          n1 `closesHtmlTag` (head ns)
-        | otherwise     = const (const False)
-
-    buildCont   :: Context -> Parser XmlTrees
-    buildCont ns
-        = cond isText ( do
-                        t <- getText
-                        rl <- buildCont ns
-                        return (txt t ++ rl)
-                      )
-          ( cond isOpn ( do
-                         (n,al) <- getOpn
-                         openTag ns n al
-                       )
-            ( cond isCls ( do
-                           n <- getCls
-                           closeTag ns n
-                         )
-              ( cond isCmt ( do
-                             c <- getCmt
-                             rl <- buildCont ns
-                             return (cmt c ++ rl)
-                           )
-                ( cond isWarn ( do
-                                w <- getWarn
-                                rl <- buildCont ns
-                                return (warn w ++ rl)
-                              )
-                  ( cond isPos ( do
-                                 _ <- getPos
-                                 buildCont ns
-                               )
-                    ( cond isEof ( do
-                                   _ <- isEof
-                                   closeAll ns
-                                 )
-                      ( return (warn "parse error in tagsoup tree construction")
-                      )
-                    )
-                  )
-                )
-              )
-            )
-          )
-        where
-        closeTag                :: Context -> String -> Parser XmlTrees
-        closeTag ((n':_), _) n1
-            | n' == n1          = return []                     -- a normal closing tag
-                                                                -- all other cases try to repair wrong html
-        closeTag ns'@((n':_), _) n1                             -- n1 closes n implicitly
-            | n' `isInnerElem` n1                               -- e.g. <td>...</tr>
-                                = do
-                                  insCls n1                     -- pushback </n1>
-                                  insCls n'                     -- insert a </n'>
-                                  buildCont ns'                 -- try again
-        closeTag ns' n1
-            | isEmptyElem n1    = buildCont ns'                 -- ignore a redundant closing tag for empty element
-        closeTag ns'@((n':ns1'), _) n1                          -- insert a missing closing tag
-            | n1 `elem` ns1'    = do
-                                  insCls n1
-                                  insCls n'
-                                  rl <- buildCont ns'
-                                  return ( warn ("closing tag " ++ show n' ++
-                                                 " expected, but " ++ show n1 ++ " found")
-                                           ++ rl
-                                         )
-        closeTag ns' n1                                         -- ignore a wrong closing tag
-                                = do
-                                  rl <- buildCont ns'
-                                  return ( warn ("no opening tag for closing tag " ++ show n1)
-                                           ++ rl
-                                         )
-
-        openTag                 :: Context -> String -> [(String, String)] -> Parser XmlTrees
-        openTag cx'@(ns',env') n1 al1
-            | isPiDT n1         = buildCont cx'
-            | isEmptyElem n1
-                                = do
-                                  qn <- mkElemQN nenv n1
-                                  al <- mkAttrs al1
-                                  rl <- buildCont cx'
-                                  return (mkElement qn al [] : rl)
-            | closesElem ns' n1 = do
-                                  insOpn n1 al1
-                                  insCls (head ns')
-                                  buildCont cx'
-            | otherwise         = do
-                                  qn <- mkElemQN nenv n1
-                                  al <- mkAttrs al1
-                                  cs <- buildCont ((n1 : ns'), nenv)
-                                  rl <- buildCont cx'
-                                  return (mkElement qn al cs : rl)
-            where
-            nenv                = extendNsEnv withNamespaces al1 env'
-            mkElemQN            = mkQN withNamespaces False
-            mkAttrQN            = mkQN withNamespaces True
-            isPiDT ('?':_)      = True
-            isPiDT ('!':_)      = True
-            isPiDT _            = False
-            mkAttrs             = mapM (uncurry mkA)
-            mkA an av           = do
-                                  qan <- mkAttrQN nenv an
-                                  return (mkAttr qan (wrap . mkText $ av))
-
-        closeAll                :: ([String], NsEnv) -> Parser XmlTrees
-        closeAll (ns',_)        = return (concatMap wrn ns')
-                                  where
-                                  wrn = warn . ("insert missing closing tag " ++) . show
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Parser/XmlCharParser.hs b/src/Text/XML/HXT/Parser/XmlCharParser.hs
--- a/src/Text/XML/HXT/Parser/XmlCharParser.hs
+++ b/src/Text/XML/HXT/Parser/XmlCharParser.hs
@@ -1,8 +1,19 @@
--- |
--- UTF-8 character parser and simple XML token parsers
---
--- Version : $Id: XmlCharParser.hs,v 1.2 2005/05/31 16:01:12 hxml Exp $
+-- ------------------------------------------------------------
 
+{- |
+   Module     : Text.XML.HXT.Parser.XmlCharParser
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : stable
+   Portability: portable
+
+   UTF-8 character parser and simple XML token parsers
+-}
+
+-- ------------------------------------------------------------
+
 module Text.XML.HXT.Parser.XmlCharParser
     ( xmlChar                   -- xml char parsers
     , xmlNameChar
@@ -14,7 +25,17 @@
     )
 where
 
-import Text.XML.HXT.DOM.Unicode
+import Data.Char.Properties.XMLCharProps( isXmlChar
+                                        , isXmlNameChar
+                                        , isXmlNameStartChar
+                                        , isXmlNCNameChar
+                                        , isXmlNCNameStartChar
+                                        , isXmlLetter
+                                        , isXmlSpaceChar
+                                        )
+
+import Data.String.Unicode
+
 import Text.ParserCombinators.Parsec
 
 -- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/Parser/XmlDTDTokenParser.hs b/src/Text/XML/HXT/Parser/XmlDTDTokenParser.hs
--- a/src/Text/XML/HXT/Parser/XmlDTDTokenParser.hs
+++ b/src/Text/XML/HXT/Parser/XmlDTDTokenParser.hs
@@ -8,7 +8,6 @@
    Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id: XmlDTDTokenParser.hs,v 1.4 2005/09/02 17:09:39 hxml Exp $
 
    Parsec parser for tokenizing DTD declarations for ELEMENT, ATTLIST, ENTITY and NOTATION
 
diff --git a/src/Text/XML/HXT/Parser/XmlParsec.hs b/src/Text/XML/HXT/Parser/XmlParsec.hs
--- a/src/Text/XML/HXT/Parser/XmlParsec.hs
+++ b/src/Text/XML/HXT/Parser/XmlParsec.hs
@@ -8,7 +8,6 @@
    Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
    Stability  : experimental
    Portability: portable
-   Version    : $Id: XmlParsec.hs,v 1.14 2005/09/02 17:09:39 hxml Exp $
 
    Xml Parsec parser with pure filter interface
 
diff --git a/src/Text/XML/HXT/Parser/XmlTokenParser.hs b/src/Text/XML/HXT/Parser/XmlTokenParser.hs
--- a/src/Text/XML/HXT/Parser/XmlTokenParser.hs
+++ b/src/Text/XML/HXT/Parser/XmlTokenParser.hs
@@ -2,13 +2,12 @@
 
 {- |
    Module     : Text.XML.HXT.Parser.XmlTokenParser
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
+   Copyright  : Copyright (C) 2010 Uwe Schmidt
    License    : MIT
 
    Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
+   Stability  : stable
    Portability: portable
-   Version    : $Id: XmlTokenParser.hs,v 1.3 2005/09/02 17:09:39 hxml Exp $
 
    Parsec parser for XML tokens
 
@@ -79,23 +78,23 @@
     )
 where
 
+import Data.Char.Properties.XMLCharProps
+    ( isXmlChar
+    )
+import Data.String.Unicode
+    ( intToCharRef
+    , intToCharRefHex
+    )
+
 import Text.ParserCombinators.Parsec
 
 import Text.XML.HXT.DOM.Interface
-
 import Text.XML.HXT.DOM.XmlNode
     ( mkDTDElem
     , mkText
     , mkCharRef
     , mkEntityRef
     )
-
-import Text.XML.HXT.DOM.Unicode
-    ( isXmlChar
-    , intToCharRef
-    , intToCharRefHex
-    )
-
 import Text.XML.HXT.Parser.XmlCharParser
     ( xmlNameChar
     , xmlNameStartChar
diff --git a/src/Text/XML/HXT/RelaxNG.hs b/src/Text/XML/HXT/RelaxNG.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG.hs
+++ /dev/null
@@ -1,24 +0,0 @@
--- |
--- This helper module exports elements from the basic Relax NG libraries:
--- Validator, CreatePattern, PatternToString and DataTypes.
--- It is the main entry point to the Relax NG schema validator of the Haskell
--- XML Toolbox.
---
--- Author : Torben Kuseler
---
--- Version : $Id: RelaxNG.hs,v 1.1 2005/09/02 17:09:39 hxml Exp $
-
-module Text.XML.HXT.RelaxNG
-  ( module Text.XML.HXT.RelaxNG.PatternToString
-  , module Text.XML.HXT.RelaxNG.Validator
-  , module Text.XML.HXT.RelaxNG.DataTypes
-  , module Text.XML.HXT.RelaxNG.CreatePattern
-  , module Text.XML.HXT.RelaxNG.XmlSchema.RegexMatch
-  )
-where
-
-import Text.XML.HXT.RelaxNG.PatternToString
-import Text.XML.HXT.RelaxNG.Validator
-import Text.XML.HXT.RelaxNG.DataTypes
-import Text.XML.HXT.RelaxNG.CreatePattern
-import Text.XML.HXT.RelaxNG.XmlSchema.RegexMatch
diff --git a/src/Text/XML/HXT/RelaxNG/BasicArrows.hs b/src/Text/XML/HXT/RelaxNG/BasicArrows.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/BasicArrows.hs
+++ /dev/null
@@ -1,326 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.BasicArrows
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
-   Portability: portable
-   Version    : $Id$
-
-   Constants and basic arrows for Relax NG
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.BasicArrows
-where
-
-import Control.Arrow.ListArrows
-
-import Text.XML.HXT.DOM.Interface
-import Text.XML.HXT.Arrow.XmlArrow
-    hiding
-    ( mkText
-    , mkError
-    )
-
-hasRngName      :: ArrowXml a => String -> a XmlTree XmlTree
-hasRngName s
-    = hasName s
-      `orElse`
-      ( hasLocalPart s >>> hasNamespaceUri relaxNamespace )
-
-checkRngName :: ArrowXml a => [String] -> a XmlTree XmlTree
-checkRngName l
-    = ( isElem
-        >>>
-        catA (map hasRngName l)
-      )
-      `guards` this
-
-noOfChildren    :: ArrowXml a => (Int -> Bool) -> a XmlTree XmlTree
-noOfChildren p
-    = getChildren
-      >>.
-      (\ l -> if p (length l) then l else [])
-
--- ------------------------------------------------------------
-
-isAttributeRef  :: ArrowXml a => a XmlTree XmlTree
-isAttributeRef
-    = checkRngName ["attribute", "ref"]
-
-isAttributeRefTextListGroupInterleaveOneOrMoreEmpty     :: ArrowXml a => a XmlTree XmlTree
-isAttributeRefTextListGroupInterleaveOneOrMoreEmpty
-    = checkRngName ["attribute", "ref", "text", "list", "group", "interleave", "oneOrMore", "empty"]
-
-isAttributeRefTextListInterleave        :: ArrowXml a => a XmlTree XmlTree
-isAttributeRefTextListInterleave
-    = checkRngName ["attribute", "ref", "text", "list", "interleave"]
-
-isAttributeListGroupInterleaveOneOrMore :: ArrowXml a => a XmlTree XmlTree
-isAttributeListGroupInterleaveOneOrMore
-    = checkRngName ["attribute", "list", "group", "interleave", "oneOrMore"]
-
-isExternalRefInclude    :: ArrowXml a => a XmlTree XmlTree
-isExternalRefInclude
-    = checkRngName ["externalRef", "include"]
-
-isNameNsNameValue       :: ArrowXml a => a XmlTree XmlTree
-isNameNsNameValue
-    = checkRngName ["name", "nsName", "value"]
-
-isNameNsName    :: ArrowXml a => a XmlTree XmlTree
-isNameNsName
-    = checkRngName ["name", "nsName"]
-
-isNameAnyNameNsName     :: ArrowXml a => a XmlTree XmlTree
-isNameAnyNameNsName
-    = checkRngName ["name", "anyName", "nsName"]
-
-isDefineOneOrMoreZeroOrMoreOptionalListMixed    :: ArrowXml a => a XmlTree XmlTree
-isDefineOneOrMoreZeroOrMoreOptionalListMixed
-    = checkRngName ["define", "oneOrMore", "zeroOrMore", "optional", "list", "mixed"]
-
-isChoiceGroupInterleave :: ArrowXml a => a XmlTree XmlTree
-isChoiceGroupInterleave
-    = checkRngName ["choice", "group", "interleave"]
-
-isChoiceGroupInterleaveOneOrMore        :: ArrowXml a => a XmlTree XmlTree
-isChoiceGroupInterleaveOneOrMore
-    = checkRngName ["choice", "group", "interleave", "oneOrMore"]
-
-isGroupInterleave       :: ArrowXml a => a XmlTree XmlTree
-isGroupInterleave
-    = checkRngName ["group", "interleave"]
-
--- ------------------------------------------------------------
-
-isRngAnyName            :: ArrowXml a => a XmlTree XmlTree
-isRngAnyName            = isElem >>> hasRngName "anyName"
-
-isRngAttribute          :: ArrowXml a => a XmlTree XmlTree
-isRngAttribute          = isElem >>> hasRngName "attribute"
-
-isRngChoice             :: ArrowXml a => a XmlTree XmlTree
-isRngChoice             = isElem >>> hasRngName "choice"
-
-isRngCombine            :: ArrowXml a => a XmlTree XmlTree
-isRngCombine            = isElem >>> hasRngName "combine"
-
-isRngData               :: ArrowXml a => a XmlTree XmlTree
-isRngData               = isElem >>> hasRngName "data"
-
-isRngDefine             :: ArrowXml a => a XmlTree XmlTree
-isRngDefine             = isElem >>> hasRngName "define"
-
-isRngDiv                :: ArrowXml a => a XmlTree XmlTree
-isRngDiv                = isElem >>> hasRngName "div"
-
-isRngElement            :: ArrowXml a => a XmlTree XmlTree
-isRngElement            = isElem >>> hasRngName "element"
-
-isRngEmpty              :: ArrowXml a => a XmlTree XmlTree
-isRngEmpty              = isElem >>> hasRngName "empty"
-
-isRngExcept             :: ArrowXml a => a XmlTree XmlTree
-isRngExcept             = isElem >>> hasRngName "except"
-
-isRngExternalRef        :: ArrowXml a => a XmlTree XmlTree
-isRngExternalRef        = isElem >>> hasRngName "externalRef"
-
-isRngGrammar            :: ArrowXml a => a XmlTree XmlTree
-isRngGrammar            = isElem >>> hasRngName "grammar"
-
-isRngGroup              :: ArrowXml a => a XmlTree XmlTree
-isRngGroup              = isElem >>> hasRngName "group"
-
-isRngInclude            :: ArrowXml a => a XmlTree XmlTree
-isRngInclude            = isElem >>> hasRngName "include"
-
-isRngInterleave         :: ArrowXml a => a XmlTree XmlTree
-isRngInterleave         = isElem >>> hasRngName "interleave"
-
-isRngList               :: ArrowXml a => a XmlTree XmlTree
-isRngList               = isElem >>> hasRngName "list"
-
-isRngMixed              :: ArrowXml a => a XmlTree XmlTree
-isRngMixed              = isElem >>> hasRngName "mixed"
-
-isRngName               :: ArrowXml a => a XmlTree XmlTree
-isRngName               = isElem >>> hasRngName "name"
-
-isRngNotAllowed         :: ArrowXml a => a XmlTree XmlTree
-isRngNotAllowed         = isElem >>> hasRngName "notAllowed"
-
-isRngNsName             :: ArrowXml a => a XmlTree XmlTree
-isRngNsName             = isElem >>> hasRngName "nsName"
-
-isRngOneOrMore          :: ArrowXml a => a XmlTree XmlTree
-isRngOneOrMore          = isElem >>> hasRngName "oneOrMore"
-
-isRngOptional           :: ArrowXml a => a XmlTree XmlTree
-isRngOptional           = isElem >>> hasRngName "optional"
-
-isRngParam              :: ArrowXml a => a XmlTree XmlTree
-isRngParam              = isElem >>> hasRngName "param"
-
-isRngParentRef          :: ArrowXml a => a XmlTree XmlTree
-isRngParentRef          = isElem >>> hasRngName "parentRef"
-
-isRngRef                :: ArrowXml a => a XmlTree XmlTree
-isRngRef                = isElem >>> hasRngName "ref"
-
-isRngRelaxError         :: ArrowXml a => a XmlTree XmlTree
-isRngRelaxError         = isElem >>> hasRngName "relaxError"
-
-isRngStart              :: ArrowXml a => a XmlTree XmlTree
-isRngStart              = isElem >>> hasRngName "start"
-
-isRngText               :: ArrowXml a => a XmlTree XmlTree
-isRngText               = isElem >>> hasRngName "text"
-
-isRngType               :: ArrowXml a => a XmlTree XmlTree
-isRngType               = isElem >>> hasRngName "type"
-
-isRngValue              :: ArrowXml a => a XmlTree XmlTree
-isRngValue              = isElem >>> hasRngName "value"
-
-isRngZeroOrMore         :: ArrowXml a => a XmlTree XmlTree
-isRngZeroOrMore         = isElem >>> hasRngName "zeroOrMore"
-
--- ------------------------------------------------------------
-
-mkRngElement            :: ArrowXml a => String -> a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngElement n          = mkElement (mkQName "" n relaxNamespace)
-
-mkRngChoice             :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngChoice             = mkRngElement "choice"
-
-mkRngDefine             :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngDefine             = mkRngElement "define"
-
-mkRngEmpty              :: ArrowXml a => a n XmlTree -> a n XmlTree
-mkRngEmpty a            = mkRngElement "empty" a none
-
-mkRngGrammar            :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngGrammar            = mkRngElement "grammar"
-
-mkRngGroup              :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngGroup              = mkRngElement "group"
-
-mkRngInterleave         :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngInterleave         = mkRngElement "interleave"
-
-mkRngName               :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngName               = mkRngElement "name"
-
-mkRngNotAllowed         :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngNotAllowed         = mkRngElement "notAllowed"
-
-mkRngOneOrMore          :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngOneOrMore          = mkRngElement "oneOrMore"
-
-mkRngRef                :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngRef                = mkRngElement "ref"
-
-mkRngRelaxError         :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngRelaxError         = mkRngElement "relaxError"
-
-mkRngStart              :: ArrowXml a => a n XmlTree -> a n XmlTree -> a n XmlTree
-mkRngStart              = mkRngElement "start"
-
-mkRngText               :: ArrowXml a => a n XmlTree -> a n XmlTree
-mkRngText a             = mkRngElement "text" a none
-
--- ------------------------------------------------------------
-
-setRngName              :: ArrowXml a => String -> a XmlTree XmlTree
-setRngName n            = setElemName (mkQName "" n relaxNamespace)
-
-setRngNameDiv           :: ArrowXml a => a XmlTree XmlTree
-setRngNameDiv           = setRngName "div"
-
-setRngNameRef           :: ArrowXml a => a XmlTree XmlTree
-setRngNameRef           = setRngName "ref"
-
--- ------------------------------------------------------------
-
--- Attributes
-
-isRngAttrAttribute              :: ArrowXml a => a XmlTree XmlTree
-isRngAttrAttribute              = isAttr >>> hasRngName "attribute"
-
-isRngAttrCombine                :: ArrowXml a => a XmlTree XmlTree
-isRngAttrCombine                = isAttr >>> hasRngName "combine"
-
-isRngAttrDatatypeLibrary        :: ArrowXml a => a XmlTree XmlTree
-isRngAttrDatatypeLibrary        = isAttr >>> hasRngName "datatypeLibrary"
-
-isRngAttrHref                   :: ArrowXml a => a XmlTree XmlTree
-isRngAttrHref                   = isAttr >>> hasRngName "href"
-
-isRngAttrName                   :: ArrowXml a => a XmlTree XmlTree
-isRngAttrName                   = isAttr >>> hasRngName "name"
-
-isRngAttrNs                     :: ArrowXml a => a XmlTree XmlTree
-isRngAttrNs                     = isAttr >>> hasRngName "ns"
-
-isRngAttrType                   :: ArrowXml a => a XmlTree XmlTree
-isRngAttrType                   = isAttr >>> hasRngName "type"
-
--- ------------------------------------------------------------
-
-hasRngAttrAttribute             :: ArrowXml a => a XmlTree XmlTree
-hasRngAttrAttribute             = hasAttr "attribute"
-
-hasRngAttrCombine               :: ArrowXml a => a XmlTree XmlTree
-hasRngAttrCombine               = hasAttr "combine"
-
-hasRngAttrDatatypeLibrary       :: ArrowXml a => a XmlTree XmlTree
-hasRngAttrDatatypeLibrary       = hasAttr "datatypeLibrary"
-
-hasRngAttrHref                  :: ArrowXml a => a XmlTree XmlTree
-hasRngAttrHref                  = hasAttr "href"
-
-hasRngAttrName                  :: ArrowXml a => a XmlTree XmlTree
-hasRngAttrName                  = hasAttr "name"
-
-hasRngAttrNs                    :: ArrowXml a => a XmlTree XmlTree
-hasRngAttrNs                    = hasAttr "ns"
-
-hasRngAttrType                  :: ArrowXml a => a XmlTree XmlTree
-hasRngAttrType                  = hasAttr "type"
-
--- ------------------------------------------------------------
-
-getRngAttrAttribute             :: ArrowXml a => a XmlTree String
-getRngAttrAttribute             = getAttrValue "attribute"
-
-getRngAttrCombine               :: ArrowXml a => a XmlTree String
-getRngAttrCombine               = getAttrValue "combine"
-
-getRngAttrDatatypeLibrary       :: ArrowXml a => a XmlTree String
-getRngAttrDatatypeLibrary       = getAttrValue "datatypeLibrary"
-
-getRngAttrDescr                 :: ArrowXml a => a XmlTree String
-getRngAttrDescr                 = getAttrValue "descr"
-
-getRngAttrHref                  :: ArrowXml a => a XmlTree String
-getRngAttrHref                  = getAttrValue "href"
-
-getRngAttrName                  :: ArrowXml a => a XmlTree String
-getRngAttrName                  = getAttrValue "name"
-
-getRngAttrNs                    :: ArrowXml a => a XmlTree String
-getRngAttrNs                    = getAttrValue "ns"
-
-getRngAttrType                  :: ArrowXml a => a XmlTree String
-getRngAttrType                  = getAttrValue "type"
-
--- ------------------------------------------------------------
-
diff --git a/src/Text/XML/HXT/RelaxNG/CreatePattern.hs b/src/Text/XML/HXT/RelaxNG/CreatePattern.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/CreatePattern.hs
+++ /dev/null
@@ -1,349 +0,0 @@
--- |
---
--- Creates the 'Pattern' datastructure from a simplified Relax NG schema.
--- The created datastructure is used in the validation algorithm
--- (see also: "Text.XML.HXT.RelaxNG.Validation")
-
-module Text.XML.HXT.RelaxNG.CreatePattern
-  ( createPatternFromXmlTree
-  , createNameClass
-  , firstChild
-  , lastChild
-  , module Text.XML.HXT.RelaxNG.PatternFunctions
-  )
-where
-
-import Control.Arrow.ListArrows
-
-import Text.XML.HXT.DOM.Interface
-
-import Text.XML.HXT.Arrow.XmlArrow
-
-import Text.XML.HXT.RelaxNG.DataTypes
-import Text.XML.HXT.RelaxNG.BasicArrows
-import Text.XML.HXT.RelaxNG.PatternFunctions
-
-import Data.Maybe
-    ( fromMaybe )
-
-import Data.List
-    ( isPrefixOf )
-
--- ------------------------------------------------------------
-
--- | Creates the 'Pattern' datastructure from a simplified Relax NG schema.
-
-createPatternFromXmlTree :: LA XmlTree Pattern
-createPatternFromXmlTree = createPatternFromXml $< createEnv
- where
- -- | Selects all define-pattern and creates an environment list.
- -- Each list entry maps the define name to the children of the define-pattern.
- -- The map is used to replace a ref-pattern with the referenced define-pattern.
- createEnv :: LA XmlTree Env
- createEnv = listA $ deep isRngDefine
-                     >>>
-                     (getRngAttrName &&& getChildren)
-
-
--- | Transforms each XML-element to the corresponding pattern
-
-createPatternFromXml :: Env -> LA XmlTree Pattern
-createPatternFromXml env
- = choiceA [
-     isRoot                            :-> processRoot env,
-     isRngEmpty      :-> constA Empty,
-     isRngNotAllowed :-> mkNotAllowed,
-     isRngText       :-> constA Text,
-     isRngChoice     :-> mkRelaxChoice env,
-     isRngInterleave :-> mkRelaxInterleave env,
-     isRngGroup      :-> mkRelaxGroup env,
-     isRngOneOrMore  :-> mkRelaxOneOrMore env,
-     isRngList       :-> mkRelaxList env,
-     isRngData       :-> mkRelaxData env,
-     isRngValue      :-> mkRelaxValue,
-     isRngAttribute  :-> mkRelaxAttribute env,
-     isRngElement    :-> mkRelaxElement env,
-     isRngRef        :-> mkRelaxRef env,
-     this                              :-> mkRelaxError ""
-   ]
-
-
-processRoot :: Env -> LA XmlTree Pattern
-processRoot env
-  = getChildren
-    >>>
-    choiceA [
-      isRngRelaxError :-> (mkRelaxError $< getRngAttrDescr),
-      isRngGrammar    :-> (processGrammar env),
-      this                              :-> (mkRelaxError "no grammar-pattern in schema")
-    ]
-
-
-processGrammar :: Env -> LA XmlTree Pattern
-processGrammar env
-  = getChildren
-    >>>
-    choiceA [
-      isRngDefine     :-> none,
-      isRngRelaxError :-> (mkRelaxError $< getAttrValue "desc"),
-      isRngStart      :-> (getChildren >>> createPatternFromXml env),
-      this            :-> (mkRelaxError "no start-pattern in schema")
-    ]
-
-
-{- |
-  Transforms a ref-element.
-  The value of the name-attribute is looked up in the environment list
-  to find the corresponding define-pattern.
-  Haskells lazy-evaluation is used to transform circular structures.
--}
-mkRelaxRef :: Env -> LA XmlTree Pattern
-mkRelaxRef e
- = getRngAttrName
-   >>>
-   arr (\n -> fromMaybe (notAllowed $ "define-pattern with name " ++ n ++ " not found")
-              . lookup n $ transformEnv e
-       )
- where
- transformEnv :: [(String, XmlTree)] -> [(String, Pattern)]
- transformEnv env = [ (treeName, (transformEnvElem tree env)) | (treeName, tree) <- env]
- transformEnvElem :: XmlTree -> [(String, XmlTree)] -> Pattern
- transformEnvElem tree env = head $ runLA (createPatternFromXml env) tree
-
-
--- | Transforms a notAllowed-element.
-mkNotAllowed :: LA XmlTree Pattern
-mkNotAllowed = constA $ notAllowed "notAllowed-pattern in Relax NG schema definition"
-
-
--- | Creates an error message.
-mkRelaxError :: String -> LA XmlTree Pattern
-mkRelaxError errStr
- = choiceA [
-     isRngRelaxError :-> (getRngAttrDescr >>> arr notAllowed),
-     isElem  :-> ( getName
-                   >>>
-                   arr (\n -> notAllowed $ "Pattern " ++ n ++
-                                           " is not allowed in Relax NG schema"
-                       )
-                 ),
-     isAttr  :-> ( getName
-                   >>>
-                   arr (\n -> notAllowed $ "Attribute " ++ n ++
-                                           " is not allowed in Relax NG schema"
-                       )
-                 ),
-     isError :-> (getErrorMsg >>> arr notAllowed),
-     this    :-> (arr (\e -> notAllowed $ if errStr /= ""
-                                          then errStr
-                                          else "Can't create pattern from " ++ show e)
-                 )
-   ]
-
-
--- | Transforms a choice-element.
-mkRelaxChoice :: Env -> LA XmlTree Pattern
-mkRelaxChoice env
-    = ifA ( getChildren >>.
-            ( \ l -> if length l == 1 then l else [] )
-          )
-      ( createPatternFromXml env )
-      ( getTwoChildrenPattern env >>> arr2 Choice )
-
--- | Transforms a interleave-element.
-mkRelaxInterleave :: Env -> LA XmlTree Pattern
-mkRelaxInterleave env
-    = getTwoChildrenPattern env
-      >>>
-      arr2 Interleave
-
-
--- | Transforms a group-element.
-mkRelaxGroup :: Env -> LA XmlTree Pattern
-mkRelaxGroup env
-    = getTwoChildrenPattern env
-      >>>
-      arr2 Group
-
-
--- | Transforms a oneOrMore-element.
-mkRelaxOneOrMore :: Env -> LA XmlTree Pattern
-mkRelaxOneOrMore env
-    = getOneChildPattern env
-      >>>
-      arr OneOrMore
-
-
--- | Transforms a list-element.
-mkRelaxList :: Env -> LA XmlTree Pattern
-mkRelaxList env
-    = getOneChildPattern env
-      >>>
-      arr List
-
-
--- | Transforms a data- or dataExcept-element.
-mkRelaxData :: Env -> LA XmlTree Pattern
-mkRelaxData env
-  = ifA (getChildren >>> isRngExcept)
-     (processDataExcept >>> arr3 DataExcept)
-     (processData >>> arr2 Data)
-  where
-  processDataExcept :: LA XmlTree (Datatype, (ParamList, Pattern))
-  processDataExcept = getDatatype &&& getParamList &&&
-                      ( getChildren
-                        >>>
-                        isRngExcept
-                        >>>
-                        getChildren
-                        >>>
-                        createPatternFromXml env
-                      )
-  processData :: LA XmlTree (Datatype, ParamList)
-  processData = getDatatype &&& getParamList
-  getParamList :: LA XmlTree ParamList
-  getParamList = listA $ getChildren
-                         >>>
-                         isRngParam
-                         >>>
-                         (getRngAttrName &&& (getChildren >>> getText))
-
-
--- | Transforms a value-element.
-mkRelaxValue :: LA XmlTree Pattern
-mkRelaxValue = getDatatype &&& getValue &&& getContext
-               >>>
-               arr3 Value
-  where
-  getContext :: LA XmlTree Context
-  getContext = getAttrValue contextBaseAttr &&& getMapping
-  getMapping :: LA XmlTree [(Prefix, Uri)]
-  getMapping = listA $ getAttrl >>>
-                       ( (getName >>> isA (contextAttributes `isPrefixOf`))
-                         `guards`
-                         ( (getName >>> arr (drop $ length contextAttributes))
-                           &&&
-                           (getChildren >>> getText)
-                         )
-                       )
-  getValue :: LA XmlTree String
-  getValue = (getChildren >>> getText) `orElse` (constA "")
-
-
-getDatatype :: LA XmlTree Datatype
-getDatatype = getRngAttrDatatypeLibrary
-              &&&
-              getRngAttrType
-
-
--- | Transforms a attribute-element.
--- The first child is a 'NameClass', the second (the last) one a pattern.
-
-mkRelaxAttribute :: Env -> LA XmlTree Pattern
-mkRelaxAttribute env
-    = ( ( firstChild >>> createNameClass )
-        &&&
-        ( lastChild >>> createPatternFromXml env )
-      )
-      >>>
-      arr2 Attribute
-
--- | Transforms a element-element.
--- The first child is a 'NameClass', the second (the last) one a pattern.
-mkRelaxElement :: Env -> LA XmlTree Pattern
-mkRelaxElement env
-    = ( ( firstChild >>> createNameClass )
-        &&&
-        ( lastChild >>> createPatternFromXml env )
-      )
-      >>>
-      arr2 Element
-
-
--- | Creates a 'NameClass' from an \"anyName\"-, \"nsName\"- or  \"name\"-Pattern,
-createNameClass :: LA XmlTree NameClass
-createNameClass
-    = choiceA
-      [ isRngAnyName :-> processAnyName
-      , isRngNsName  :-> processNsName
-      , isRngName    :-> processName
-      , isRngChoice  :-> processChoice
-      , this         :-> mkNameClassError
-      ]
-    where
-    processAnyName :: LA XmlTree NameClass
-    processAnyName
-        = ifA (getChildren >>> isRngExcept)
-          ( getChildren
-            >>> getChildren
-            >>> createNameClass
-            >>> arr AnyNameExcept
-          )
-         ( constA AnyName )
-
-    processNsName :: LA XmlTree NameClass
-    processNsName
-        = ifA (getChildren >>> isRngExcept)
-          ( ( getRngAttrNs
-              &&&
-              ( getChildren >>> getChildren >>> createNameClass )
-            )
-            >>>
-            arr2 NsNameExcept
-          )
-          ( getRngAttrNs >>> arr NsName )
-
-    processName :: LA XmlTree NameClass
-    processName
-        = (getRngAttrNs &&& (getChildren >>> getText)) >>> arr2 Name
-
-    processChoice :: LA XmlTree NameClass
-    processChoice
-        = ( ( firstChild >>> createNameClass )
-            &&&
-            ( lastChild  >>> createNameClass )
-          )
-          >>>
-          arr2 NameClassChoice
-
-mkNameClassError :: LA XmlTree NameClass
-mkNameClassError
-    = choiceA [ isRngRelaxError
-                        :-> ( getRngAttrDescr
-                              >>>
-                              arr NCError
-                         )
-              , isElem  :-> ( getName
-                              >>>
-                              arr (\n -> NCError ("Can't create name class from element " ++ n))
-                            )
-              , isAttr  :-> ( getName
-                              >>>
-                              arr (\n -> NCError ("Can't create name class from attribute: " ++ n))
-                            )
-              , isError :-> ( getErrorMsg
-                              >>>
-                              arr NCError
-                            )
-              , this    :-> ( arr (\e ->  NCError $ "Can't create name class from " ++ show e) )
-              ]
-
-
-getOneChildPattern :: Env -> LA XmlTree Pattern
-getOneChildPattern env
-    = firstChild >>> createPatternFromXml env
-
-
-getTwoChildrenPattern :: Env -> LA XmlTree (Pattern, Pattern)
-getTwoChildrenPattern env
-    = ( getOneChildPattern env )
-        &&&
-        ( lastChild  >>> createPatternFromXml env )
-
--- | Simple access arrows
-
-firstChild      :: (ArrowTree a, Tree t) => a (t b) (t b)
-firstChild      = single getChildren
-
-lastChild       :: (ArrowTree a, Tree t) => a (t b) (t b)
-lastChild       = getChildren >>. (take 1 . reverse)
diff --git a/src/Text/XML/HXT/RelaxNG/DataTypeLibMysql.hs b/src/Text/XML/HXT/RelaxNG/DataTypeLibMysql.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/DataTypeLibMysql.hs
+++ /dev/null
@@ -1,169 +0,0 @@
--- |
--- Datatype library for the MySQL datatypes
---
--- $Id: DataTypeLibMysql.hs,v 1.1 2005/09/02 17:09:39 hxml Exp $
-
-module Text.XML.HXT.RelaxNG.DataTypeLibMysql
-  ( mysqlNS
-  , mysqlDatatypeLib
-  )
-where
-
-import Text.XML.HXT.RelaxNG.DataTypeLibUtils
-
-import Data.Maybe
-
--- ------------------------------------------------------------
-
--- | Namespace of the MySQL datatype library
-
-mysqlNS :: String
-mysqlNS = "http://www.mysql.com"
-
-
--- | The main entry point to the MySQL datatype library.
---
--- The 'DTC' constructor exports the list of supported datatypes and params.
--- It also exports the specialized functions to validate a XML instance value with
--- respect to a datatype.
-
-mysqlDatatypeLib :: DatatypeLibrary
-mysqlDatatypeLib = (mysqlNS, DTC datatypeAllowsMysql datatypeEqualMysql mysqlDatatypes)
-
-
--- | All supported datatypes of the library
-mysqlDatatypes :: AllowedDatatypes
-mysqlDatatypes = [ -- numeric types
-                   ("SIGNED-TINYINT", numericParams)
-                 , ("UNSIGNED-TINYINT", numericParams)
-                 , ("SIGNED-SMALLINT", numericParams)
-                 , ("UNSIGNED-SMALLINT", numericParams)
-                 , ("SIGNED-MEDIUMINT", numericParams)
-                 , ("UNSIGNED-MEDIUMINT", numericParams)
-                 , ("SIGNED-INT", numericParams)
-                 , ("UNSIGNED-INT", numericParams)
-                 , ("SIGNED-BIGINT", numericParams)
-                 , ("UNSIGNED-BIGINT", numericParams)
-
-                 -- string types
-                 , ("CHAR", stringParams)
-                 , ("VARCHAR", stringParams)
-                 , ("BINARY", stringParams)
-                 , ("VARBINARY", stringParams)
-                 , ("TINYTEXT", stringParams)
-                 , ("TINYBLOB", stringParams)
-                 , ("TEXT", stringParams)
-                 , ("BLOB", stringParams)
-                 , ("MEDIUMTEXT", stringParams)
-                 , ("MEDIUMBLOB", stringParams)
-                 , ("LONGTEXT", stringParams)
-                 , ("LONGBLOB", stringParams)
-                 ]
-
-
--- | List of supported string datatypes
-stringTypes :: [String]
-stringTypes = [ "CHAR"
-              , "VARCHAR"
-              , "BINARY"
-              , "VARBINARY"
-              , "TINYTEXT"
-              , "TINYBLOB"
-              , "TEXT"
-              , "BLOB"
-              , "MEDIUMTEXT"
-              , "MEDIUMBLOB"
-              , "LONGTEXT"
-              , "LONGBLOB"
-              ]
-
-
--- | List of supported numeric datatypes
-numericTypes :: [String]
-numericTypes = [ "SIGNED-TINYINT"
-               , "UNSIGNED-TINYINT"
-               , "SIGNED-SMALLINT"
-               , "UNSIGNED-SMALLINT"
-               , "SIGNED-MEDIUMINT"
-               , "UNSIGNED-MEDIUMINT"
-               , "SIGNED-INT"
-               , "UNSIGNED-INT"
-               , "SIGNED-BIGINT"
-               , "UNSIGNED-BIGINT"
-               ]
-
-
--- | List of allowed params for the numeric datatypes
-numericParams :: AllowedParams
-numericParams = [ rng_maxExclusive
-                , rng_minExclusive
-                , rng_maxInclusive
-                , rng_minInclusive
-                ]
-
-
--- | List of allowed params for the string datatypes
-stringParams :: AllowedParams
-stringParams = [ rng_length
-               , rng_maxLength
-               , rng_minLength
-               ]
-
--- ------------------------------------------------------------
---
--- | Tests whether a XML instance value matches a data-pattern.
-
-datatypeAllowsMysql :: DatatypeAllows
-datatypeAllowsMysql d params value _
-    = performCheck check value
-    where
-    check
-        | isJust ndt    = checkNum (fromJust ndt)
-        | isJust sdt    = checkStr (fromJust sdt)
-        | otherwise     = failure $ errorMsgDataTypeNotAllowed mysqlNS d params
-    checkNum r  = uncurry (numberValid d) r params
-    checkStr r  = uncurry (stringValid d) r params
-    ndt = lookup d $
-          [ ("SIGNED-TINYINT", ((-128), 127))
-          , ("UNSIGNED-TINYINT", (0, 255))
-          , ("SIGNED-SMALLINT", ((-32768), 32767))
-          , ("UNSIGNED-SMALLINT", (0, 65535))
-          , ("SIGNED-MEDIUMINT", ((-8388608), 8388607))
-          , ("UNSIGNED-MEDIUMINT", (0, 16777215))
-          , ("SIGNED-INT", ((-2147483648), 2147483647))
-          , ("UNSIGNED-INT", (0, 4294967295))
-          , ("SIGNED-BIGINT", ((-9223372036854775808), 9223372036854775807))
-          , ("UNSIGNED-BIGINT", (0, 18446744073709551615))
-          ]
-    sdt = lookup d $
-          [ ("CHAR", (0, 255))
-          , ("VARCHAR", (0, 65535))
-          , ("BINARY", (0, 255))
-          , ("VARBINARY", (0, 65535))
-          , ("TINYTEXT", (0, 256))
-          , ("TINYBLOB", (0, 256))
-          , ("TEXT", (0, 65536))
-          , ("BLOB", (0, 65536))
-          , ("MEDIUMTEXT", (0, 16777216))
-          , ("MEDIUMBLOB", (0, 16777216))
-          , ("LONGTEXT", (0, 4294967296))
-          , ("LONGBLOB", (0, 4294967296))
-          ]
-
--- ------------------------------------------------------------
-
--- | Tests whether a XML instance value matches a value-pattern.
-
-datatypeEqualMysql :: DatatypeEqual
-datatypeEqualMysql d s1 _ s2 _
-    = performCheck check (s1, s2)
-      where
-      cmp nf    = arr (\ (x1, x2) -> (nf x1, nf x2))
-                  >>>
-                  assert (uncurry (==)) (uncurry $ errorMsgEqual d)
-      check
-          | d `elem` stringTypes        = cmp id
-          | d `elem` numericTypes       = cmp normalizeNumber
-          | otherwise                   = failure $ const (errorMsgDataTypeNotAllowed0 mysqlNS d)
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/DataTypeLibUtils.hs b/src/Text/XML/HXT/RelaxNG/DataTypeLibUtils.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/DataTypeLibUtils.hs
+++ /dev/null
@@ -1,407 +0,0 @@
--- |
--- exports helper functions for the integration of new datatype-libraries
-
-module Text.XML.HXT.RelaxNG.DataTypeLibUtils
-  ( errorMsgEqual
-  , errorMsgDataTypeNotAllowed
-  , errorMsgDataTypeNotAllowed0
-  , errorMsgDataTypeNotAllowed2
-  , errorMsgDataLibQName
-  , errorMsgParam
-
-  , rng_length
-  , rng_maxLength
-  , rng_minLength
-   ,rng_maxExclusive
-  , rng_minExclusive
-  , rng_maxInclusive
-  , rng_minInclusive
-
-  , module Control.Arrow
-  , module Text.XML.HXT.DOM.Util
-  , module Text.XML.HXT.RelaxNG.Utils
-  , module Text.XML.HXT.RelaxNG.DataTypes
-
-  , FunctionTable
-
-  , stringValidFT       -- generalized checkString
-  , fctTableString      -- minLength, maxLenght, length
-  , fctTableList        -- minLength, maxLenght, length
-
-  , stringValid         -- checkString
-  , numberValid         -- checkNumeric
-
-  , numParamValid
-
-  , CheckA              -- Check datatype
-  , CheckString         -- CheckA String String
-  , CheckInteger        -- CheckA Integer Integer
-
-  , performCheck        -- run a CheckA
-  , ok                  -- always true
-  , failure             -- create an error meesage
-  , assert              -- create a primitive check from a predicate
-  , assertMaybe         -- create a primitive check from a maybe
-  , checkWith           -- convert value before checking
-  )
-
-where
-import Prelude hiding (id, (.))
-
-import Control.Category
-import Control.Arrow
-
-import Data.Maybe
-
-import Text.XML.HXT.DOM.Util
-
-import Text.XML.HXT.RelaxNG.DataTypes
-import Text.XML.HXT.RelaxNG.Utils
-
--- ------------------------------------------------------------
-
-newtype CheckA a b      = C { runCheck :: a -> Either String b }
-
-instance Category CheckA where
-    id          = C $ Right
-
-    f2 . f1     = C $                           -- logical and: f1 and f2 must hold
-                  \ x -> case runCheck f1 x of
-                         Right y        -> runCheck f2 y
-                         Left  e        -> Left e
-
-instance Arrow CheckA where
-    arr f       = C ( Right . f )               -- unit: no check, always o.k., just a conversion
-
-    first f1    = C $                           -- check 1. component of a pair
-                  \ ~(x1, x2) -> case runCheck f1 x1 of
-                                 Right y1       -> Right (y1, x2)
-                                 Left  e        -> Left  e
-
-    second f2   = C $                           -- check 2. component of a pair
-                  \ ~(x1, x2) -> case runCheck f2 x2 of
-                                 Right y2       -> Right (x1, y2)
-                                 Left  e        -> Left  e
-
-
-
-instance ArrowZero CheckA where
-    zeroArrow   = C $ const (Left "")           -- always false: zero
-
-instance ArrowPlus CheckA where
-    f1 <+> f2   = C $                           -- logical or
-                  \ x -> case runCheck f1 x of
-                         Right y1       -> Right y1
-                         Left  e1       -> case runCheck f2 x of
-                                           Right y2     -> Right y2
-                                           Left  e2     -> Left ( if null e1
-                                                                  then e2
-                                                                  else
-                                                                  if null e2
-                                                                  then e1
-                                                                  else e1 ++ " or " ++ e2
-                                                                )
-
-type CheckString        = CheckA String String
-type CheckInteger       = CheckA Integer Integer
-
--- | run a check and deliver Just an error message or Nothing
-
-performCheck    :: CheckA a b -> a -> Maybe String
-performCheck c  = either Just (const Nothing) . runCheck c
-
--- | always failure
-
-failure         :: (a -> String) -> CheckA a b
-failure msg     = C (Left . msg)
-
--- | every thing is fine
-
-ok              :: CheckA a a
-ok              = arr id
-
--- | perform a simple check with a predicate p,
---   when the predicate holds, assert acts as identity,
---   else an error message is generated
-
-assert  :: (a -> Bool) -> (a -> String) -> CheckA a a
-assert p msg    = C $ \ x -> if p x then Right x else Left (msg x)
-
--- | perform a simple check with a Maybe function, Nothing indicates error
-
-assertMaybe     :: (a -> Maybe b) -> (a -> String) -> CheckA a b
-assertMaybe f msg
-    = C $ \ x -> case f x of
-                 Nothing        -> Left (msg x)
-                 Just y         -> Right y
-
--- | perform a check, but convert the value before checking
-
-checkWith       :: (a -> b) -> CheckA b c -> CheckA a a
-checkWith f c   = C $
-                  \ x -> case runCheck c (f x) of
-                         Right _        -> Right x
-                         Left  e        -> Left  e
-
--- ------------------------------------------------------------
-
--- RelaxNG attribute names
-
-rng_length, rng_maxLength, rng_minLength
- ,rng_maxExclusive, rng_minExclusive, rng_maxInclusive, rng_minInclusive :: String
-
-rng_length              = "length"
-rng_maxLength           = "maxLength"
-rng_minLength           = "minLength"
-
-rng_maxExclusive        = "maxExclusive"
-rng_minExclusive        = "minExclusive"
-rng_maxInclusive        = "maxInclusive"
-rng_minInclusive        = "minInclusive"
-
--- ------------------------------------------------------------
-
--- | Function table type
-
-type FunctionTable      = [(String, String -> String -> Bool)]
-
--- | Function table for numeric tests,
--- XML document value is first operand, schema value second
-
-fctTableNum :: (Ord a, Num a) => [(String, a -> a -> Bool)]
-fctTableNum
-    = [ (rng_maxExclusive, (<))
-      , (rng_minExclusive, (>))
-      , (rng_maxInclusive, (<=))
-      , (rng_minInclusive, (>=))
-      ]
-
--- | Function table for string tests,
--- XML document value is first operand, schema value second
-fctTableString :: FunctionTable
-fctTableString
-    = [ (rng_length,    (numParamValid (==)))
-      , (rng_maxLength, (numParamValid (<=)))
-      , (rng_minLength, (numParamValid (>=)))
-      ]
-
--- | Function table for list tests,
--- XML document value is first operand, schema value second
-
-fctTableList :: FunctionTable
-fctTableList
-    = [ (rng_length,    (listParamValid (==)))
-      , (rng_maxLength, (listParamValid (<=)))
-      , (rng_minLength, (listParamValid (>=)))
-      ]
-
-{- |
-tests whether a string value matches a numeric param
-
-valid example:
-
-> <data type="CHAR"> <param name="maxLength">5</param> </data>
-
-invalid example:
-
-> <data type="CHAR"> <param name="minLength">foo</param> </data>
-
--}
-
-numParamValid :: (Integer -> Integer -> Bool) -> String -> String -> Bool
-numParamValid fct a b
-  = isNumber b
-    &&
-    ( toInteger (length a) `fct` (read b) )
-
-{- |
-tests whether a list value matches a length constraint
-
-valid example:
-
-> <data type="IDREFS"> <param name="maxLength">5</param> </data>
-
-invalid example:
-
-> <data type="IDREFS"> <param name="minLength">foo</param> </data>
-
--}
-
-listParamValid :: (Integer -> Integer -> Bool) -> String -> String -> Bool
-listParamValid fct a b
-  = isNumber b
-    &&
-    ( toInteger (length . words $ a) `fct` (read b) )
-
--- ------------------------------------------------------------
--- new check functions
-
-{- |
-Tests whether a \"string\" datatype value is between the lower and
-upper bound of the datatype and matches all parameters.
-
-All tests are performed on the string value.
-
-   * 1.parameter  :  datatype
-
-   - 2.parameter  :  lower bound of the datatype range
-
-   - 3.parameter  :  upper bound of the datatype range (-1 = no upper bound)
-
-   - 4.parameter  :  list of parameters
-
-   - 5.parameter  :  datatype value to be checked
-
-   - return : Just \"Errormessage\" in case of an error, else Nothing
-
--}
-
-stringValid     :: DatatypeName -> Integer -> Integer -> ParamList -> CheckString
-stringValid     = stringValidFT fctTableString
-
-stringValidFT :: FunctionTable -> DatatypeName -> Integer -> Integer -> ParamList -> CheckString
-stringValidFT ft datatype lowerBound upperBound params
-    = assert boundsOK boundsErr
-      >>>
-      paramsStringValid params
-    where
-    boundsOK v
-        = ( (lowerBound == 0)
-            ||
-            (toInteger (length v) >= lowerBound)
-          )
-          &&
-          ( (upperBound == (-1))
-            ||
-            (toInteger (length v) <= upperBound)
-          )
-
-    boundsErr v
-        = "Length of " ++ v
-          ++ " (" ++ (show $ length v) ++ " chars) out of range: "
-          ++ show lowerBound ++ " .. " ++ show upperBound
-          ++ " for datatype " ++ datatype
-
-    paramStringValid :: (LocalName, String) -> CheckString
-    paramStringValid (pn, pv)
-        = assert paramOK (errorMsgParam pn pv)
-          where
-          paramOK v  = paramFct pn v pv
-          paramFct n = fromMaybe (const . const $ True) $ lookup n ft
-
-    paramsStringValid :: ParamList -> CheckString
-    paramsStringValid
-        = foldr (>>>) ok . map paramStringValid
-
--- ------------------------------------------------------------
-
-{- |
-Tests whether a \"numeric\" datatype value is between the lower and upper
-bound of the datatype and matches all parameters.
-
-First, the string value is parsed into a numeric representation.
-If no error occur, all following tests are performed on the numeric value.
-
-   * 1.parameter  :  datatype
-
-   - 2.parameter  :  lower bound of the datatype range
-
-   - 3.parameter  :  upper bound of the datatype range (-1 = no upper bound)
-
-   - 4.parameter  :  list of parameters
-
-   - 5.parameter  :  datatype value to be checked
-
-   - return : Just \"Errormessage\" in case of an error, else Nothing
-
--}
-
-numberValid :: DatatypeName -> Integer -> Integer -> ParamList -> CheckString
-numberValid datatype lowerBound upperBound params
-    = assert isNumber numErr
-      >>>
-      checkWith read ( assert inRange rangeErr
-                       >>>
-                       paramsNumValid params
-                     )
-    where
-    inRange     :: Integer -> Bool
-    inRange x   = x >= lowerBound
-                  &&
-                  x <= upperBound
-
-    rangeErr v  = ( "Value = " ++ show v ++ " out of range: "
-                    ++ show lowerBound ++ " .. " ++ show upperBound
-                    ++ " for datatype " ++ datatype
-                  )
-    numErr v
-        = "Value = " ++ v ++ " is not a number"
-
-paramsNumValid  :: ParamList -> CheckInteger
-paramsNumValid
-    = foldr (>>>) ok . map paramNumValid
-
-paramNumValid   :: (LocalName, String) -> CheckInteger
-paramNumValid (pn, pv)
-    = assert paramOK (errorMsgParam pn pv . show)
-    where
-    paramOK  v = isNumber pv
-                 &&
-                 paramFct pn v (read pv)
-    paramFct n = fromJust $ lookup n fctTableNum
-
--- ------------------------------------------------------------
-
-{- |
-Error Message for the equality test of two datatype values
-
-   * 1.parameter  :  datatype
-
-   - 2.parameter  :  datatype value
-
-   - 3.parameter  :  datatype value
-
-example:
-
-> errorMsgEqual "Int" "21" "42" -> "Datatype Int with value = 21 expected, but value = 42 found"
-
--}
-
-errorMsgParam   :: LocalName -> String -> String -> String
-errorMsgParam pn pv v
-    = ( "Parameter restriction: \""
-        ++ pn ++ " = " ++ pv
-        ++ "\" does not hold for value = \"" ++ v ++ "\""
-      )
-
-errorMsgEqual :: DatatypeName -> String -> String -> String
-errorMsgEqual d s1 s2
-    = ( "Datatype" ++ show d ++
-        " with value = " ++ show s1 ++
-        " expected, but value = " ++ show s2 ++ " found"
-      )
-errorMsgDataTypeNotAllowed :: String -> String -> [(String, String)] -> String -> String
-errorMsgDataTypeNotAllowed l t p v
-    = ( "Datatype " ++ show t ++ " with parameter(s) " ++
-        formatStringListPairs p ++ " and value = " ++ show v ++
-        " not allowed for DatatypeLibrary " ++ show l
-      )
-
-errorMsgDataTypeNotAllowed0 :: String -> String -> String
-errorMsgDataTypeNotAllowed0 l t
-    = ( "Datatype " ++ show t ++
-        " not allowed for DatatypeLibrary " ++ show l
-      )
-errorMsgDataTypeNotAllowed2 :: String -> String -> String -> String -> String
-errorMsgDataTypeNotAllowed2 l t v1 v2
-    = ( "Datatype " ++ show t ++
-        " with values = " ++ show v1 ++
-        " and " ++ show v2 ++
-        " not allowed for DatatypeLibrary " ++ show l
-      )
-
-errorMsgDataLibQName :: String -> String -> String -> String
-errorMsgDataLibQName l n v
-    = show v ++ " is not a valid " ++ n ++ " for DatatypeLibrary " ++ l
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/DataTypeLibraries.hs b/src/Text/XML/HXT/RelaxNG/DataTypeLibraries.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/DataTypeLibraries.hs
+++ /dev/null
@@ -1,140 +0,0 @@
--- | This modul exports the list of supported datatype libraries.
--- It also exports the main functions to validate an XML instance value
--- with respect to a datatype.
-
-module Text.XML.HXT.RelaxNG.DataTypeLibraries
-  ( datatypeLibraries
-  , datatypeEqual
-  , datatypeAllows
-  )
-where
-
-import Text.XML.HXT.DOM.Interface
-    ( relaxNamespace
-    )
-
-import Text.XML.HXT.RelaxNG.DataTypeLibUtils
-
-import Text.XML.HXT.RelaxNG.DataTypeLibMysql
-    ( mysqlDatatypeLib )
-
-import Text.XML.HXT.RelaxNG.XmlSchema.DataTypeLibW3C
-    ( w3cDatatypeLib )
-
-import Data.Maybe
-    ( fromJust )
-
--- ------------------------------------------------------------
-
-
--- | List of all supported datatype libraries which can be
--- used within the Relax NG validator modul.
-
-datatypeLibraries :: DatatypeLibraries
-datatypeLibraries
-    = [ relaxDatatypeLib
-      , relaxDatatypeLib'
-      , mysqlDatatypeLib
-      , w3cDatatypeLib
-      ]
-
-
-{- |
-Tests whether a XML instance value matches a value-pattern.
-
-The following tests are performed:
-
-   * 1. :  does the uri exist in the list of supported datatype libraries
-
-   - 2. :  does the library support the datatype
-
-   - 3. :  does the XML instance value match the value-pattern
-
-The hard work is done by the specialized 'DatatypeEqual' function
-(see also: 'DatatypeCheck') of the datatype library.
--}
-
-datatypeEqual :: Uri -> DatatypeEqual
-datatypeEqual uri d s1 c1 s2 c2
-    = if elem uri (map fst datatypeLibraries)
-      then dtEqFct d s1 c1 s2 c2
-      else Just ( "Unknown DatatypeLibrary " ++ show uri )
-    where
-    DTC _ dtEqFct _ = fromJust $ lookup uri datatypeLibraries
-
-{- |
-Tests whether a XML instance value matches a data-pattern.
-
-The following tests are performed:
-
-   * 1. :  does the uri exist in the list of supported datatype libraries
-
-   - 2. :  does the library support the datatype
-
-   - 3. :  does the XML instance value match the data-pattern
-
-   - 4. :  does the XML instance value match all params
-
-The hard work is done by the specialized 'DatatypeAllows' function
-(see also: 'DatatypeCheck') of the datatype library.
-
--}
-
-datatypeAllows :: Uri -> DatatypeAllows
-datatypeAllows uri d params s1 c1
-    = if elem uri (map fst datatypeLibraries)
-      then dtAllowFct d params s1 c1
-      else Just ( "Unknown DatatypeLibrary " ++ show uri )
-    where
-    DTC dtAllowFct _ _ = fromJust $ lookup uri datatypeLibraries
-
-
--- --------------------------------------------------------------------------------------
--- Relax NG build in datatype library
-
-relaxDatatypeLib        :: DatatypeLibrary
-relaxDatatypeLib        = (relaxNamespace, DTC datatypeAllowsRelax datatypeEqualRelax relaxDatatypes)
-
--- | if there is no datatype uri, the built in datatype library is used
-relaxDatatypeLib'       :: DatatypeLibrary
-relaxDatatypeLib'       = ("",             DTC datatypeAllowsRelax datatypeEqualRelax relaxDatatypes)
-
--- | The build in Relax NG datatype lib supportes only the token and string datatype,
--- without any params.
-
-relaxDatatypes :: AllowedDatatypes
-relaxDatatypes
-    = map ( (\ x -> (x, [])) . fst ) relaxDatatypeTable
-
-datatypeAllowsRelax :: DatatypeAllows
-datatypeAllowsRelax d p v _
-    = maybe notAllowed' allowed . lookup d $ relaxDatatypeTable
-    where
-    notAllowed'
-        = Just $ errorMsgDataTypeNotAllowed relaxNamespace d p v
-    allowed _
-        = Nothing
-
--- | If the token datatype is used, the values have to be normalized
--- (trailing and leading whitespaces are removed).
--- token does not perform any changes to the values.
-
-datatypeEqualRelax :: DatatypeEqual
-datatypeEqualRelax d s1 _ s2 _
-    = maybe notAllowed' checkValues . lookup d $ relaxDatatypeTable
-      where
-      notAllowed'
-          = Just $ errorMsgDataTypeNotAllowed2 relaxNamespace d s1 s2
-      checkValues predicate
-          = if predicate s1 s2
-            then Nothing
-            else Just $ errorMsgEqual d s1 s2
-
-relaxDatatypeTable :: [(String, String -> String -> Bool)]
-relaxDatatypeTable
-    = [ ("string", (==))
-      , ("token",  \ s1 s2 -> normalizeWhitespace s1 == normalizeWhitespace s2 )
-      ]
-
-
--- --------------------------------------------------------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/DataTypes.hs b/src/Text/XML/HXT/RelaxNG/DataTypes.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/DataTypes.hs
+++ /dev/null
@@ -1,296 +0,0 @@
-module Text.XML.HXT.RelaxNG.DataTypes
-where
-
-import Text.XML.HXT.DOM.TypeDefs
-
--- ------------------------------------------------------------
-
-relaxSchemaFile :: String
-relaxSchemaFile = "Text/XML/HXT/RelaxNG/SpecificationSchema.rng"
-
-
-relaxSchemaGrammarFile :: String
-relaxSchemaGrammarFile = "Text/XML/HXT/RelaxNG/SpecificationSchemaGrammar.rng"
-
--- ------------------------------------------------------------
--- datatypes for the simplification process
-
-a_numberOfErrors,
- a_relaxSimplificationChanges,
- defineOrigName :: String
-
-a_numberOfErrors             = "numberOfErrors"
-a_relaxSimplificationChanges = "relaxSimplificationChanges"
-defineOrigName               = "RelaxDefineOriginalName"
-
-
-type Env = [(String, XmlTree)]
-
--- | Start of a context attribute value
--- (see also: 'Text.XML.HXT.RelaxNG.Simplification.simplificationStep1')
---
--- The value is always followed by the original attribute name and value
-
-contextAttributes :: String
-contextAttributes = "RelaxContext:"
-
-
--- | Start of base uri attribute value
--- (see also: 'simplificationStep1' in "Text.XML.HXT.RelaxNG.Simplification")
-
-contextBaseAttr :: String
-contextBaseAttr = "RelaxContextBaseURI"
-
-
--- see simplificationStep5 in Text.XML.HXT.RelaxNG.Simplification
-
-type OldName = String
-type NewName = String
-type NamePair = (OldName, NewName)
-type RefList = [NamePair]
-
-
--- ------------------------------------------------------------
--- datatype library handling
-
--- | Type of all datatype libraries functions that tests whether
--- a XML instance value matches a value-pattern.
---
--- Returns Just \"errorMessage\" in case of an error else Nothing.
-
-type DatatypeEqual  = DatatypeName -> String -> Context -> String -> Context -> Maybe String
-
-
--- | Type of all datatype libraries functions that tests whether
--- a XML instance value matches a data-pattern.
---
--- Returns Just \"errorMessage\" in case of an error else Nothing.
-
-type DatatypeAllows = DatatypeName -> ParamList -> String -> Context -> Maybe String
-
-
--- | List of all supported datatype libraries
-
-type DatatypeLibraries = [DatatypeLibrary]
-
-
--- | Each datatype library is identified by a URI.
-
-type DatatypeLibrary   = (Uri, DatatypeCheck)
-
-type DatatypeName      = String
-
-type ParamName         = String
-
-
--- | List of all supported params for a datatype
-
-type AllowedParams     = [ParamName]
-
-
--- | List of all supported datatypes and there allowed params
-
-type AllowedDatatypes  = [(DatatypeName, AllowedParams)]
-
-
--- | The Constructor exports the list of supported datatypes for a library.
--- It also exports the specialized datatype library functions to validate
--- a XML instance value with respect to a datatype.
-
-data DatatypeCheck
-  = DTC { dtAllowsFct    :: DatatypeAllows -- ^ function to test whether a value matches a data-pattern
-        , dtEqualFct     :: DatatypeEqual -- ^ function to test whether a value matches a value-pattern
-        , dtAllowedTypes :: AllowedDatatypes -- ^ list of all supported params for a datatype
-        }
-
--- ------------------------------------------------------------
--- datatypes for the validation process
-
-type Uri = String
-
-type LocalName = String
-
-
--- | List of parameters; each parameter is a pair consisting of a local name and a value.
-
-type ParamList = [(LocalName, String)]
-
-type Prefix = String
-
-
--- | A Context represents the context of an XML element.
--- It consists of a base URI and a mapping from prefixes to namespace URIs.
-
-type Context = (Uri, [(Prefix, Uri)])
-
--- | A Datatype identifies a datatype by a datatype library name and a local name.
-
-type Datatype = (Uri, LocalName)
-
-showDatatype    :: Datatype -> String
-showDatatype (u, ln)
-         | null u       = ln
-         | otherwise    = "{" ++ u ++ "}" ++ ln
-
--- | Represents a name class
-
-data NameClass = AnyName
-               | AnyNameExcept NameClass
-               | Name Uri LocalName
-               | NsName Uri
-               | NsNameExcept Uri NameClass
-               | NameClassChoice NameClass NameClass
-               | NCError String
-               deriving Eq
-
-instance Show NameClass
-    where
-    show AnyName        = "AnyName"
-    show (AnyNameExcept nameClass)
-                        = "AnyNameExcept: " ++ show nameClass
-    show (Name uri localName)
-        | null uri      = localName
-        | otherwise     = "{" ++ uri ++ "}" ++ localName
-    show (NsName uri)   = "{" ++ uri ++ "}AnyName"
-    show (NsNameExcept uri nameClass)
-                        = "NsNameExcept: {" ++ uri ++ "}" ++ show nameClass
-    show (NameClassChoice nameClass1 nameClass2)
-                        = "NameClassChoice: " ++ show nameClass1 ++ "|" ++ show nameClass2
-    show (NCError string)
-                         = "NCError: " ++ string
-
-
--- | Represents a pattern after simplification
-
-data Pattern = Empty
-             | NotAllowed ErrMessage
-             | Text
-             | Choice Pattern Pattern
-             | Interleave Pattern Pattern
-             | Group Pattern Pattern
-             | OneOrMore Pattern
-             | List Pattern
-             | Data Datatype ParamList
-             | DataExcept Datatype ParamList Pattern
-             | Value Datatype String Context
-             | Attribute NameClass Pattern
-             | Element NameClass Pattern
-             | After Pattern Pattern
-
-instance Show Pattern where
-    show Empty                  = "empty"
-    show (NotAllowed e)         = show e
-    show Text                   = "text"
-    show (Choice p1 p2)         = "( " ++ show p1 ++ " | " ++ show p2 ++ " )"
-    show (Interleave p1 p2)     = "( " ++ show p1 ++ " & " ++ show p2 ++ " )"
-    show (Group p1 p2)          = "( " ++ show p1 ++ " , " ++ show p2 ++ " )"
-    show (OneOrMore p)          = show p ++ "+"
-    show (List p)               = "list { " ++ show p ++ " }"
-    show (Data dt pl)           = showDatatype dt ++ showPL pl
-                                  where
-                                  showPL []     = ""
-                                  showPL l      = " {" ++ concatMap showP l ++ " }"
-                                  showP (ln, v) = " " ++ ln ++ " = " ++ show v
-    show (DataExcept dt pl p)   = show (Data dt pl) ++ " - (" ++ show p ++ " )"
-    show (Value dt v _cx)       = showDatatype dt ++ " " ++ show v
-    show (Attribute nc p)       = "attribute " ++ show nc ++ " { " ++ show p ++ " }"
-    show (Element nc p)         = "element "   ++ show nc ++ " { " ++ show p ++ " }"
-    show (After p1 p2)          =  "( " ++ show p1 ++ " ; " ++ show p2 ++ " )"
-
-data ErrMessage = ErrMsg ErrLevel [String]
-                  -- deriving Show
-
-instance Show ErrMessage where
-    show (ErrMsg _lev es) = foldr1 (\ x y -> x ++ "\n" ++ y) es
-
-type ErrLevel   = Int
-
--- ------------------------------------------------------------
-
--- smart constructor funtions for Pattern
-
--- | smart constructor for NotAllowed
-
-notAllowed      :: String -> Pattern
-notAllowed      = notAllowedN 0
-
-notAllowed1     :: String -> Pattern
-notAllowed1     = notAllowedN 1
-
-notAllowed2     :: String -> Pattern
-notAllowed2     = notAllowedN 2
-
-notAllowedN     :: ErrLevel -> String -> Pattern
-notAllowedN l s = NotAllowed (ErrMsg l [s])
-
--- | merge error messages
---
--- If error levels are different, the more important is taken,
--- if level is 2 (max level) both error messages are taken
--- else the 1. error mesage is taken
-
-mergeNotAllowed :: Pattern -> Pattern -> Pattern
-mergeNotAllowed p1@(NotAllowed (ErrMsg l1 s1)) p2@(NotAllowed (ErrMsg l2 s2))
-    | l1 < l2   = p2
-    | l1 > l2   = p1
-    | l1 == 2   = NotAllowed $ ErrMsg 2 (s1 ++ s2)
-    | otherwise = p1
-
--- TODO : weird error when collecting error messages errors are duplicated
-
-mergeNotAllowed _p1 _p2
-    = notAllowed2 "mergeNotAllowed with wrong patterns"
-
--- | smart constructor for Choice
-
-choice :: Pattern -> Pattern -> Pattern
-choice p1@(NotAllowed _) p2@(NotAllowed _)      = mergeNotAllowed p1 p2
-choice p1                   (NotAllowed _)      = p1
-choice (NotAllowed _)    p2                     = p2
-choice p1                p2                     = Choice p1 p2
-
--- | smart constructor for Group
-
-group :: Pattern -> Pattern -> Pattern
-group p1@(NotAllowed _)  p2@(NotAllowed _)      = mergeNotAllowed p1 p2
-group _                   n@(NotAllowed _)      = n
-group   n@(NotAllowed _)  _                     = n
-group p                  Empty                  = p
-group Empty              p                      = p
-group p1                 p2                     = Group p1 p2
-
--- | smart constructor for OneOrMore
-
-oneOrMore :: Pattern -> Pattern
-oneOrMore n@(NotAllowed _) = n
-oneOrMore p                = OneOrMore p
-
--- | smart constructor for Interleave
-
-interleave :: Pattern -> Pattern -> Pattern
-interleave p1@(NotAllowed _) p2@(NotAllowed _)  = mergeNotAllowed p1 p2
-interleave _                 p2@(NotAllowed _)  = p2
-interleave p1@(NotAllowed _) _                  = p1
-interleave p1                Empty              = p1
-interleave Empty             p2                 = p2
-interleave p1                p2                 = Interleave p1 p2
-
--- | smart constructor for After
-
-after :: Pattern -> Pattern -> Pattern
-after p1@(NotAllowed _) p2@(NotAllowed _)       = mergeNotAllowed p1 p2
-after _                 p2@(NotAllowed _)       = p2
-after p1@(NotAllowed _) _                       = p1
-after p1                p2                      = After p1 p2
-
-
--- | Possible content types of a Relax NG pattern.
--- (see also chapter 7.2 in Relax NG specification)
-
-data ContentType = CTEmpty
-                 | CTComplex
-                 | CTSimple
-                 | CTNone
-     deriving (Show, Eq, Ord)
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/PatternFunctions.hs b/src/Text/XML/HXT/RelaxNG/PatternFunctions.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/PatternFunctions.hs
+++ /dev/null
@@ -1,108 +0,0 @@
--- | basic 'Pattern' functions
---
-
-module Text.XML.HXT.RelaxNG.PatternFunctions
-
-where
-
-import Text.XML.HXT.RelaxNG.DataTypes
-
-
--- ------------------------------------------------------------
-
-isRelaxEmpty :: Pattern -> Bool
-isRelaxEmpty Empty = True
-isRelaxEmpty _     = False
-
-isRelaxNotAllowed :: Pattern -> Bool
-isRelaxNotAllowed (NotAllowed _) = True
-isRelaxNotAllowed _              = False
-
-isRelaxText :: Pattern -> Bool
-isRelaxText Text = True
-isRelaxText _    = False
-
-isRelaxChoice :: Pattern -> Bool
-isRelaxChoice (Choice _ _) = True
-isRelaxChoice _            = False
-
-isRelaxInterleave :: Pattern -> Bool
-isRelaxInterleave (Interleave _ _) = True
-isRelaxInterleave _                = False
-
-isRelaxGroup :: Pattern -> Bool
-isRelaxGroup (Group _ _) = True
-isRelaxGroup _           = False
-
-isRelaxOneOrMore :: Pattern -> Bool
-isRelaxOneOrMore (OneOrMore _) = True
-isRelaxOneOrMore _             = False
-
-isRelaxList :: Pattern -> Bool
-isRelaxList (List _) = True
-isRelaxList _        = False
-
-isRelaxData :: Pattern -> Bool
-isRelaxData (Data _ _) = True
-isRelaxData _          = False
-
-isRelaxDataExcept :: Pattern -> Bool
-isRelaxDataExcept (DataExcept _ _ _) = True
-isRelaxDataExcept _                  = False
-
-isRelaxValue :: Pattern -> Bool
-isRelaxValue (Value _ _ _) = True
-isRelaxValue _             = False
-
-isRelaxAttribute :: Pattern -> Bool
-isRelaxAttribute (Attribute _ _) = True
-isRelaxAttribute _               = False
-
-isRelaxElement :: Pattern -> Bool
-isRelaxElement (Element _ _) = True
-isRelaxElement _             = False
-
-isRelaxAfter :: Pattern -> Bool
-isRelaxAfter (After _ _) = True
-isRelaxAfter _           = False
-
-
--- | Returns a list of children pattern for each pattern,
--- e.g. (Choice p1 p2) = [p1, p2]
-getChildrenPattern :: Pattern -> [Pattern]
-getChildrenPattern (Choice p1 p2) = [p1, p2]
-getChildrenPattern (Interleave p1 p2) = [p1, p2]
-getChildrenPattern (Group p1 p2) = [p1, p2]
-getChildrenPattern (OneOrMore p) = [p]
-getChildrenPattern (List p) = [p]
-getChildrenPattern (Element _ p) = [p]
-getChildrenPattern (DataExcept _ _ p) = [p]
-getChildrenPattern (Attribute _ p) = [p]
-getChildrenPattern (After p1 p2) = [p1, p2]
-getChildrenPattern _ = []
-
-
--- | Returns the nameclass of a element- or attribute pattern.
--- Otherwise 'NCError' is returned.
-getNameClassFromPattern :: Pattern -> NameClass
-getNameClassFromPattern (Element nc _) = nc
-getNameClassFromPattern (Attribute nc _) = nc
-getNameClassFromPattern _ = NCError "Pattern without a NameClass"
-
-
--- | Returns a string representation of the pattern name
-getPatternName :: Pattern -> String
-getPatternName (Empty) = "Empty"
-getPatternName (NotAllowed _) = "NotAllowed"
-getPatternName (Text) = "Text"
-getPatternName (Choice _ _) = "Choice"
-getPatternName (Interleave _ _) = "Interleave"
-getPatternName (Group _ _) = "Group"
-getPatternName (OneOrMore _) = "OneOrMore"
-getPatternName (List _) = "List"
-getPatternName (Data _ _ ) = "Data"
-getPatternName (DataExcept _ _ _) = "DataExcept"
-getPatternName (Value _ _ _) = "Value"
-getPatternName (Attribute _ _) = "Attribute"
-getPatternName (Element _ _) = "Element"
-getPatternName (After _ _) = "After"
diff --git a/src/Text/XML/HXT/RelaxNG/PatternToString.hs b/src/Text/XML/HXT/RelaxNG/PatternToString.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/PatternToString.hs
+++ /dev/null
@@ -1,360 +0,0 @@
-module Text.XML.HXT.RelaxNG.PatternToString
-  ( patternToStringTree
-  , patternToFormatedString
-  , xmlTreeToPatternStringTree
-  , xmlTreeToPatternFormatedString
-  , xmlTreeToPatternString
-  , nameClassToString
-  )
-where
-
-import Control.Arrow.ListArrows
-
-import Data.Tree.NTree.TypeDefs
-
-import Text.XML.HXT.DOM.Interface
-
-import Text.XML.HXT.RelaxNG.DataTypes
-import Text.XML.HXT.RelaxNG.CreatePattern
-import Text.XML.HXT.RelaxNG.Utils
-
--- ------------------------------------------------------------
-
-type PatternTree = NTree String
-
-
-{- |
-Returns a string representation of the pattern structure.
-(see also: 'createPatternFromXmlTree')
-
-Example:
-
-> Element {}foo (Choice (Choice (Value ("","token") "abc"
-> ("foo","www.bar.baz")]))(Data ("http://www.mysql.com","VARCHAR")
-> [("length","2"),("maxLength","5")])) (Element {}bar (Group (Element {}baz
-
-The function can @not@ be used to display circular ref-pattern structures.
--}
-
-xmlTreeToPatternString :: LA XmlTree String
-xmlTreeToPatternString
-    = createPatternFromXmlTree
-      >>^
-      show
-
-
--- | Returns a string representation of a nameclass.
-
-nameClassToString :: NameClass -> String
-nameClassToString AnyName
-    = "AnyName"
-
-nameClassToString (AnyNameExcept nc)
-    = "AnyNameExcept " ++ nameClassToString nc
-
-nameClassToString (Name uri local)
-    = "{" ++ uri ++ "}" ++ local
-
-nameClassToString (NsName uri)
-    = "{" ++ uri ++ "}"
-
-nameClassToString (NsNameExcept uri nc)
-    = uri ++ "except (NsName) " ++ nameClassToString nc
-
-nameClassToString (NameClassChoice nc1 nc2)
-    = nameClassToString nc1 ++ " " ++ nameClassToString nc2
-
-nameClassToString (NCError e)
-    = "NameClass Error: " ++ e
-
-
--- ------------------------------------------------------------
-
-{- |
-Returns a tree representation of the pattern structure.
-The hard work is done by 'formatTree'.
-
-Example:
-
-> +---element {}bar
->     |
->     +---group
->         |
->         +---oneOrMore
->         |   |
->         |   +---attribute AnyName
->         |       |
->         |       +---text
->         |
->         +---text
-
-The function can be used to display circular ref-pattern structures.
-
-Example:
-
-> <define name="baz">
->   <element name="baz">
->     ... <ref name="baz"/> ...
->   </element>
-> </define>
-
--}
-
-patternToStringTree :: LA Pattern String
-patternToStringTree
-    = fromSLA [] pattern2PatternTree
-      >>^
-      (\p -> formatTree id p ++ "\n")
-
-
--- | Returns a tree representation of the pattern structure.
--- (see also: 'createPatternFromXmlTree' and 'patternToStringTree')
-
-xmlTreeToPatternStringTree :: LA XmlTree String
-xmlTreeToPatternStringTree
-    = createPatternFromXmlTree
-      >>>
-      patternToStringTree
-
-
-pattern2PatternTree :: SLA [NameClass] Pattern PatternTree
-pattern2PatternTree
-    = choiceA
-      [ isA isRelaxEmpty      :-> (constA $ NTree "empty" [])
-      , isA isRelaxNotAllowed :-> notAllowed2PatternTree
-      , isA isRelaxText       :-> (constA $ NTree "text" [])
-      , isA isRelaxChoice     :-> choice2PatternTree
-      , isA isRelaxInterleave :-> children2PatternTree "interleave"
-      , isA isRelaxGroup      :-> children2PatternTree "group"
-      , isA isRelaxOneOrMore  :-> children2PatternTree "oneOrMore"
-      , isA isRelaxList       :-> children2PatternTree "list"
-      , isA isRelaxData       :-> data2PatternTree
-      , isA isRelaxDataExcept :-> dataExcept2PatternTree
-      , isA isRelaxValue      :-> value2PatternTree
-      , isA isRelaxAttribute  :-> createPatternTreeFromElement "attribute"
-      , isA isRelaxElement    :-> element2PatternTree
-      , isA isRelaxAfter      :-> children2PatternTree "after"
-      ]
-
-notAllowed2PatternTree :: SLA [NameClass] Pattern PatternTree
-notAllowed2PatternTree
-    = arr $ \(NotAllowed (ErrMsg _l sl)) -> NTree "notAllowed" $ map (\ s -> NTree s []) sl
-
-
-data2PatternTree :: SLA [NameClass] Pattern PatternTree
-data2PatternTree
-    = arr $ \ (Data d p) -> NTree "data" [ datatype2PatternTree d
-                                         , mapping2PatternTree "parameter" p
-                                         ]
-
-dataExcept2PatternTree :: SLA [NameClass] Pattern PatternTree
-dataExcept2PatternTree
-    = this &&& (listA $ arrL getChildrenPattern >>> pattern2PatternTree)
-      >>>
-      arr2 ( \ (DataExcept d param _) pattern ->
-             NTree "dataExcept" ([ datatype2PatternTree d
-                                 , mapping2PatternTree "parameter" param
-                                 ] ++ pattern)
-           )
-
-value2PatternTree :: SLA [NameClass] Pattern PatternTree
-value2PatternTree
-    = arr $ \ (Value d v c) -> NTree ("value = " ++ v) [ datatype2PatternTree d
-                                                       , context2PatternTree c
-                                                       ]
-
-
-createPatternTreeFromElement :: String -> SLA [NameClass] Pattern PatternTree
-createPatternTreeFromElement name
-    = ( arr getNameClassFromPattern
-        &&&
-        listA (arrL getChildrenPattern >>> pattern2PatternTree)
-      )
-      >>>
-      arr2 (\nc rl -> NTree (name ++ " " ++ show nc) rl)
-
-children2PatternTree :: String -> SLA [NameClass] Pattern PatternTree
-children2PatternTree name
-    = listA (arrL getChildrenPattern >>> pattern2PatternTree)
-      >>^
-      (NTree name)
-
-choice2PatternTree :: SLA [NameClass] Pattern PatternTree
-choice2PatternTree
-    = ifA ( -- wenn das zweite kind ein noch nicht ausgegebenes element ist,
-            -- muss dieses anders behandelt werden
-            -- nur fuer bessere formatierung des outputs
-            arr (last . getChildrenPattern) >>> isA (isRelaxElement) >>>
-            (arr getNameClassFromPattern &&& getState) >>>
-            isA(\ (nc, liste) -> not $ elem nc liste)
-          )
-      ( -- element in status aufnehmen, wird dann nicht mehr vom erste kind ausgegeben
-        arr getChildrenPattern
-        >>>
-        changeState (\s p -> (getNameClassFromPattern (last p)) : s)
-        >>>
-        ( ( head ^>> pattern2PatternTree )              -- erstes kind normal verarbeiten
-          &&&                                           -- zweites kind, das element, verarbeiten
-          ( last ^>> createPatternTreeFromElement "element" )
-        )
-        >>>
-        arr2 ( \ l1 l2 -> NTree "choice" [l1, l2] )
-      )
-      ( children2PatternTree "choice" )
-
-
-element2PatternTree :: SLA [NameClass] Pattern PatternTree
-element2PatternTree
-    = ifA ( (arr getNameClassFromPattern &&& getState)
-            >>>
-            isA (\ (nc, liste) -> elem nc liste)
-          )
-      ( arr getNameClassFromPattern
-        >>>
-        arr (\nc -> NTree ("reference to element " ++ show nc) [])
-      )
-      ( changeState (\ s p -> (getNameClassFromPattern p) : s)
-        >>>
-        createPatternTreeFromElement "element"
-      )
-
-
-mapping2PatternTree :: String -> [(Prefix, Uri)] -> PatternTree
-mapping2PatternTree name mapping
-    = NTree name (map (\(a, b) -> NTree (a ++ " = " ++ b) []) mapping)
-
-
-datatype2PatternTree :: Datatype -> PatternTree
-datatype2PatternTree dt
-    = NTree (datatype2String dt) []
-
-
-context2PatternTree :: Context -> PatternTree
-context2PatternTree (base, mapping)
-    = NTree "context" [ NTree ("base-uri = " ++ base) []
-                      , mapping2PatternTree "namespace environment" mapping
-                      ]
-
--- ------------------------------------------------------------
-
--- | Returns a formated string representation of the pattern structure.
--- (see also: 'createPatternFromXmlTree' and 'patternToFormatedString')
-xmlTreeToPatternFormatedString :: LA XmlTree String
-xmlTreeToPatternFormatedString
-    = createPatternFromXmlTree
-      >>>
-      fromSLA [] patternToFormatedString
-
-
-{- |
-Returns a formated string representation of the pattern structure.
-
-Example:
-
-> Element {}foo (Choice (Choice ( Value = abc,
-> datatypelibrary = http://relaxng.org/ns/structure/1.0, type = token,
-> context (base-uri =file://test.rng,
-> parameter: xml = http://www.w3.org/XML/1998/namespaces, foo = www.bar.baz),
-
-The function can be used to display circular ref-pattern structures.
--}
-
-patternToFormatedString :: SLA [NameClass] Pattern String
-patternToFormatedString
-    = choiceA
-      [ isA isRelaxEmpty      :-> (constA " empty ")
-      , isA isRelaxNotAllowed :-> (arr $ \ (NotAllowed errorEnv) -> show errorEnv)
-      , isA isRelaxText       :-> (constA " text ")
-      , isA isRelaxChoice     :-> children2FormatedString "choice"
-      , isA isRelaxInterleave :-> children2FormatedString "interleave"
-      , isA isRelaxGroup      :-> children2FormatedString "group"
-      , isA isRelaxOneOrMore  :-> children2FormatedString "oneOrMore"
-      , isA isRelaxList       :-> children2FormatedString "list"
-      , isA isRelaxData       :-> data2FormatedString
-      , isA isRelaxDataExcept :-> dataExcept2FormatedString
-      , isA isRelaxValue      :-> value2FormatedString
-      , isA isRelaxAttribute  :-> createFormatedStringFromElement "attribute"
-      , isA isRelaxElement    :-> element2FormatedString
-      , isA isRelaxAfter      :-> children2FormatedString "after"
-      ]
-
-children2FormatedString :: String -> SLA [NameClass] Pattern String
-children2FormatedString name
-    = listA (arrL getChildrenPattern >>> patternToFormatedString)
-      >>^
-      (\ l -> name ++ " (" ++ formatStringListPatt l ++ ") " )
-
-data2FormatedString :: SLA [NameClass] Pattern String
-data2FormatedString
-    = arr ( \ (Data datatype paramList) ->
-            "Data " ++ datatype2String datatype ++ "\n " ++
-            mapping2String "parameter" paramList ++ "\n"
-          )
-
-dataExcept2FormatedString :: SLA [NameClass] Pattern String
-dataExcept2FormatedString
- = arr ( \ (DataExcept datatype paramList _) ->
-         "DataExcept " ++ show datatype ++ "\n " ++
-         mapping2String "parameter" paramList ++ "\n "
-       )
-   &&&
-   ( arr (\ (DataExcept _ _ p) -> p) >>> patternToFormatedString )
-   >>>
-   arr2 (++)
-
-
-value2FormatedString :: SLA [NameClass] Pattern String
-value2FormatedString
- = arr $ \(Value datatype val context) ->
-           "Value = " ++ val ++ ", " ++ datatype2String datatype ++
-           "\n " ++ context2String context ++ "\n"
-
-
-element2FormatedString :: SLA [NameClass] Pattern String
-element2FormatedString
-    = ifA ( (arr getNameClassFromPattern &&& getState)
-            >>>
-            isA (\ (nc, liste) -> elem nc liste)
-          )
-      ( arr getNameClassFromPattern
-        >>^
-        ( \nc -> "reference to element " ++ nameClassToString nc ++ " " )
-      )
-      ( changeState (\ s p -> (getNameClassFromPattern p) : s)
-        >>>
-        createFormatedStringFromElement "element"
-      )
-
-
-createFormatedStringFromElement :: String -> SLA [NameClass] Pattern String
-createFormatedStringFromElement name
-    = ( arr getNameClassFromPattern
-        &&&
-        ( listA (arrL getChildrenPattern >>> patternToFormatedString)
-          >>^
-          formatStringListId
-        )
-      )
-      >>>
-      arr2 (\ nc rl -> name ++ " " ++ nameClassToString nc ++ " (" ++ rl ++ ")")
-
-
--- ------------------------------------------------------------
-
-mapping2String :: String -> [(Prefix, Uri)] -> String
-mapping2String name mapping
-    = name ++ ": " ++
-      formatStringList id ", " (map (\(a, b) -> a ++ " = " ++ b) mapping)
-
-datatype2String :: Datatype -> String
-datatype2String (lib, localName)
-    = "datatypelibrary = " ++ getLib ++ ", type = " ++ localName
-    where
-    getLib = if lib == "" then relaxNamespace else lib
-
-context2String :: Context -> String
-context2String (base, mapping)
-    = "context (base-uri = " ++ base ++ ", " ++
-      mapping2String "namespace environment" mapping ++ ")"
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/Schema.hs b/src/Text/XML/HXT/RelaxNG/Schema.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/Schema.hs
+++ /dev/null
@@ -1,3921 +0,0 @@
-{- |
-   Module     : Text.HXT.RelaxNG.Schema
-
-   Don't edit this module, it's generated by RelaxSchemaToXmlTree
-
--}
-
-module Text.XML.HXT.RelaxNG.Schema
-    ( relaxSchemaTree, relaxSchemaArrow )
-where
-
-import Text.XML.HXT.DOM.TypeDefs
-import Text.XML.HXT.DOM.XmlNode (mkRoot, mkElement, mkAttr, mkText)
-
-import Control.Arrow.ListArrows
-
-relaxSchemaArrow :: ArrowList a => a b XmlTree
-relaxSchemaArrow = constA relaxSchemaTree
-
-relaxSchemaTree :: XmlTree
-relaxSchemaTree =
-  let
-  ns1   = "http://relaxng.org/ns/structure/1.0"
-  qn1   = mkSNsName "RelaxContext:xml"
-  qn2   = mkSNsName "RelaxContextBaseURI"
-  qn3   = mkSNsName "RelaxContextDefault"
-  qn4   = mkNsName "anyName" ns1
-  qn5   = mkNsName "attribute" ns1
-  qn6   = mkNsName "choice" ns1
-  qn7   = mkNsName "data" ns1
-  qn8   = mkSNsName "datatypeLibrary"
-  qn9   = mkNsName "define" ns1
-  qn10  = mkNsName "element" ns1
-  qn11  = mkNsName "empty" ns1
-  qn12  = mkNsName "except" ns1
-  qn13  = mkNsName "grammar" ns1
-  qn14  = mkNsName "group" ns1
-  qn15  = mkNsName "interleave" ns1
-  qn16  = mkSNsName "name"
-  qn17  = mkNsName "name" ns1
-  qn18  = mkSNsName "ns"
-  qn19  = mkNsName "nsName" ns1
-  qn20  = mkNsName "oneOrMore" ns1
-  qn21  = mkNsName "ref" ns1
-  qn22  = mkNsName "start" ns1
-  qn23  = mkNsName "text" ns1
-  qn24  = mkSNsName "type"
-  qn25  = mkNsName "value" ns1
-  in
-  mkRoot []
-    [ mkElement qn13 []
-      [ mkElement qn22 []
-        [ mkElement qn6 []
-          [ mkElement qn6 []
-            [ mkElement qn6 []
-              [ mkElement qn6 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn21
-                                              [ mkAttr qn16 [ mkText "24" ]
-                                              ] []
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "25" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "26" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "27" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "28" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "29" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "30" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "31" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "32" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "33" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "34" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "35" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "36" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "37" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "38" ]
-                    ] []
-                  ]
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "39" ]
-                  ] []
-                ]
-              , mkElement qn21
-                [ mkAttr qn16 [ mkText "42" ]
-                ] []
-              ]
-            , mkElement qn21
-              [ mkAttr qn16 [ mkText "43" ]
-              ] []
-            ]
-          , mkElement qn21
-            [ mkAttr qn16 [ mkText "44" ]
-            ] []
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "44" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "grammar"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn21
-                          [ mkAttr qn16 [ mkText "11" ]
-                          ] []
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "10" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "22" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "23" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "43" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "externalRef"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn5 []
-                [ mkElement qn17
-                  [ mkAttr qn18 [ mkText "" ]
-                  ]
-                  [ mkText "href"
-                  ]
-                , mkElement qn7
-                  [ mkAttr qn24 [ mkText "anyURI" ]
-                  , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                  ] []
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "15" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "42" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "notAllowed"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "15" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "39" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "data"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn5 []
-                [ mkElement qn17
-                  [ mkAttr qn18 [ mkText "" ]
-                  ]
-                  [ mkText "type"
-                  ]
-                , mkElement qn7
-                  [ mkAttr qn24 [ mkText "NCName" ]
-                  , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                  ] []
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn21
-                      [ mkAttr qn16 [ mkText "40" ]
-                      ] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "41" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "41" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "except"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "40" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "param"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn5 []
-              [ mkElement qn17
-                [ mkAttr qn18 [ mkText "" ]
-                ]
-                [ mkText "name"
-                ]
-              , mkElement qn7
-                [ mkAttr qn24 [ mkText "NCName" ]
-                , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                ] []
-              ]
-            , mkElement qn23 [] []
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "38" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "value"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "type"
-                    ]
-                  , mkElement qn7
-                    [ mkAttr qn24 [ mkText "NCName" ]
-                    , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn23 [] []
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "37" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "text"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "15" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "36" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "empty"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "15" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "35" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "parentRef"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn5 []
-              [ mkElement qn17
-                [ mkAttr qn18 [ mkText "" ]
-                ]
-                [ mkText "name"
-                ]
-              , mkElement qn7
-                [ mkAttr qn24 [ mkText "NCName" ]
-                , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                ] []
-              ]
-            , mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "34" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "ref"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn5 []
-              [ mkElement qn17
-                [ mkAttr qn18 [ mkText "" ]
-                ]
-                [ mkText "name"
-                ]
-              , mkElement qn7
-                [ mkAttr qn24 [ mkText "NCName" ]
-                , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                ] []
-              ]
-            , mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "33" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "mixed"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "32" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "list"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "31" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "oneOrMore"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "30" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "zeroOrMore"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "29" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "optional"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "28" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "choice"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "27" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "interleave"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "26" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "group"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "25" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "attribute"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "name"
-                    ]
-                  , mkElement qn7
-                    [ mkAttr qn24 [ mkText "QName" ]
-                    , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                    ] []
-                  ]
-                , mkElement qn15 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn20 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "15" ]
-                        ] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn21
-                          [ mkAttr qn16 [ mkText "17" ]
-                          ] []
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "18" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "19" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "20" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "24" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "element"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn6 []
-                [ mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "name"
-                    ]
-                  , mkElement qn7
-                    [ mkAttr qn24 [ mkText "QName" ]
-                    , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                    ] []
-                  ]
-                , mkElement qn15 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn20 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "15" ]
-                        ] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn21
-                          [ mkAttr qn16 [ mkText "17" ]
-                          ] []
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "18" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "19" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "20" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "23" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "include"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn5 []
-                [ mkElement qn17
-                  [ mkAttr qn18 [ mkText "" ]
-                  ]
-                  [ mkText "href"
-                  ]
-                , mkElement qn7
-                  [ mkAttr qn24 [ mkText "anyURI" ]
-                  , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                  ] []
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "11" ]
-                        ] []
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "10" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "21" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "22" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "div"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn21
-                          [ mkAttr qn16 [ mkText "11" ]
-                          ] []
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "10" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "22" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "23" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "21" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "div"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "11" ]
-                        ] []
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "10" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "21" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "20" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "choice"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "17" ]
-                        ] []
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "18" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "19" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "20" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "19" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "nsName"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "16" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "18" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "anyName"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "16" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "17" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "name"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn7
-              [ mkAttr qn24 [ mkText "QName" ]
-              , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-              ] []
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "16" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "except"
-            ]
-          , mkElement qn15 []
-            [ mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "15" ]
-                  ] []
-                ]
-              ]
-            , mkElement qn20 []
-              [ mkElement qn6 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn21
-                      [ mkAttr qn16 [ mkText "17" ]
-                      ] []
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "18" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "19" ]
-                    ] []
-                  ]
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "20" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "15" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn4 []
-            [ mkElement qn12 []
-              [ mkElement qn19
-                [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                ] []
-              ]
-            ]
-          , mkElement qn6 []
-            [ mkElement qn11 [] []
-            , mkElement qn20 []
-              [ mkElement qn6 []
-                [ mkElement qn6 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 [] []
-                    , mkElement qn23 [] []
-                    ]
-                  , mkElement qn23 [] []
-                  ]
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "0" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "0" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn4 [] []
-          , mkElement qn6 []
-            [ mkElement qn11 [] []
-            , mkElement qn20 []
-              [ mkElement qn6 []
-                [ mkElement qn6 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 [] []
-                    , mkElement qn23 [] []
-                    ]
-                  , mkElement qn23 [] []
-                  ]
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "0" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "10" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "define"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "name"
-                    ]
-                  , mkElement qn7
-                    [ mkAttr qn24 [ mkText "NCName" ]
-                    , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                    ] []
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "combine"
-                      ]
-                    , mkElement qn6 []
-                      [ mkElement qn25
-                        [ mkAttr qn1 [ mkText "http://www.w3.org/XML/1998/namespace" ]
-                        , mkAttr qn3 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                        , mkAttr qn2 [ mkText "file:///home/uwe/haskell/hxt/curr/src/Text/XML/HXT/RelaxNG/schema2hs/Schema.rng" ]
-                        , mkAttr qn8 [ mkText "" ]
-                        , mkAttr qn24 [ mkText "token" ]
-                        , mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                        ]
-                        [ mkText "choice"
-                        ]
-                      , mkElement qn25
-                        [ mkAttr qn1 [ mkText "http://www.w3.org/XML/1998/namespace" ]
-                        , mkAttr qn3 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                        , mkAttr qn2 [ mkText "file:///home/uwe/haskell/hxt/curr/src/Text/XML/HXT/RelaxNG/schema2hs/Schema.rng" ]
-                        , mkAttr qn8 [ mkText "" ]
-                        , mkAttr qn24 [ mkText "token" ]
-                        , mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                        ]
-                        [ mkText "interleave"
-                        ]
-                      ]
-                    ]
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "24" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "42" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "11" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "start"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "combine"
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn25
-                      [ mkAttr qn1 [ mkText "http://www.w3.org/XML/1998/namespace" ]
-                      , mkAttr qn3 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                      , mkAttr qn2 [ mkText "file:///home/uwe/haskell/hxt/curr/src/Text/XML/HXT/RelaxNG/schema2hs/Schema.rng" ]
-                      , mkAttr qn8 [ mkText "" ]
-                      , mkAttr qn24 [ mkText "token" ]
-                      , mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                      ]
-                      [ mkText "choice"
-                      ]
-                    , mkElement qn25
-                      [ mkAttr qn1 [ mkText "http://www.w3.org/XML/1998/namespace" ]
-                      , mkAttr qn3 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                      , mkAttr qn2 [ mkText "file:///home/uwe/haskell/hxt/curr/src/Text/XML/HXT/RelaxNG/schema2hs/Schema.rng" ]
-                      , mkAttr qn8 [ mkText "" ]
-                      , mkAttr qn24 [ mkText "token" ]
-                      , mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                      ]
-                      [ mkText "interleave"
-                      ]
-                    ]
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "15" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "24" ]
-                                                    ] []
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "25" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "26" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "27" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "28" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "29" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "30" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "31" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "32" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "33" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "34" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "35" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "36" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "37" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "38" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "39" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "42" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "43" ]
-                    ] []
-                  ]
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "44" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      ]
-    ]
diff --git a/src/Text/XML/HXT/RelaxNG/SchemaGrammar.hs b/src/Text/XML/HXT/RelaxNG/SchemaGrammar.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/SchemaGrammar.hs
+++ /dev/null
@@ -1,3831 +0,0 @@
-{- |
-   Module     : Text.HXT.RelaxNG.SchemaGrammar
-
-   Don't edit this module, it's generated by RelaxSchemaToXmlTree
-
--}
-
-module Text.XML.HXT.RelaxNG.SchemaGrammar
-    ( relaxSchemaTree, relaxSchemaArrow )
-where
-
-import Text.XML.HXT.DOM.TypeDefs
-import Text.XML.HXT.DOM.XmlNode (mkRoot, mkElement, mkAttr, mkText)
-
-import Control.Arrow.ListArrows
-
-relaxSchemaArrow :: ArrowList a => a b XmlTree
-relaxSchemaArrow = constA relaxSchemaTree
-
-relaxSchemaTree :: XmlTree
-relaxSchemaTree =
-  let
-  ns1   = "http://relaxng.org/ns/structure/1.0"
-  qn1   = mkSNsName "RelaxContext:xml"
-  qn2   = mkSNsName "RelaxContextBaseURI"
-  qn3   = mkSNsName "RelaxContextDefault"
-  qn4   = mkNsName "anyName" ns1
-  qn5   = mkNsName "attribute" ns1
-  qn6   = mkNsName "choice" ns1
-  qn7   = mkNsName "data" ns1
-  qn8   = mkSNsName "datatypeLibrary"
-  qn9   = mkNsName "define" ns1
-  qn10  = mkNsName "element" ns1
-  qn11  = mkNsName "empty" ns1
-  qn12  = mkNsName "except" ns1
-  qn13  = mkNsName "grammar" ns1
-  qn14  = mkNsName "group" ns1
-  qn15  = mkNsName "interleave" ns1
-  qn16  = mkSNsName "name"
-  qn17  = mkNsName "name" ns1
-  qn18  = mkSNsName "ns"
-  qn19  = mkNsName "nsName" ns1
-  qn20  = mkNsName "oneOrMore" ns1
-  qn21  = mkNsName "ref" ns1
-  qn22  = mkNsName "start" ns1
-  qn23  = mkNsName "text" ns1
-  qn24  = mkSNsName "type"
-  qn25  = mkNsName "value" ns1
-  in
-  mkRoot []
-    [ mkElement qn13 []
-      [ mkElement qn22 []
-        [ mkElement qn21
-          [ mkAttr qn16 [ mkText "14" ]
-          ] []
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "44" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "externalRef"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn5 []
-                [ mkElement qn17
-                  [ mkAttr qn18 [ mkText "" ]
-                  ]
-                  [ mkText "href"
-                  ]
-                , mkElement qn7
-                  [ mkAttr qn24 [ mkText "anyURI" ]
-                  , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                  ] []
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "16" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "43" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "notAllowed"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "16" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "40" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "data"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn5 []
-                [ mkElement qn17
-                  [ mkAttr qn18 [ mkText "" ]
-                  ]
-                  [ mkText "type"
-                  ]
-                , mkElement qn7
-                  [ mkAttr qn24 [ mkText "NCName" ]
-                  , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                  ] []
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn21
-                      [ mkAttr qn16 [ mkText "41" ]
-                      ] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "42" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "42" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "except"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "41" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "param"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn5 []
-              [ mkElement qn17
-                [ mkAttr qn18 [ mkText "" ]
-                ]
-                [ mkText "name"
-                ]
-              , mkElement qn7
-                [ mkAttr qn24 [ mkText "NCName" ]
-                , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                ] []
-              ]
-            , mkElement qn23 [] []
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "39" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "value"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "type"
-                    ]
-                  , mkElement qn7
-                    [ mkAttr qn24 [ mkText "NCName" ]
-                    , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn23 [] []
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "38" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "text"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "16" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "37" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "empty"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "16" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "36" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "parentRef"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn5 []
-              [ mkElement qn17
-                [ mkAttr qn18 [ mkText "" ]
-                ]
-                [ mkText "name"
-                ]
-              , mkElement qn7
-                [ mkAttr qn24 [ mkText "NCName" ]
-                , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                ] []
-              ]
-            , mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "35" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "ref"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn5 []
-              [ mkElement qn17
-                [ mkAttr qn18 [ mkText "" ]
-                ]
-                [ mkText "name"
-                ]
-              , mkElement qn7
-                [ mkAttr qn24 [ mkText "NCName" ]
-                , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                ] []
-              ]
-            , mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "34" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "mixed"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "33" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "list"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "32" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "oneOrMore"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "31" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "zeroOrMore"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "30" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "optional"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "29" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "choice"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "28" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "interleave"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "27" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "group"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "26" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "attribute"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "name"
-                    ]
-                  , mkElement qn7
-                    [ mkAttr qn24 [ mkText "QName" ]
-                    , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                    ] []
-                  ]
-                , mkElement qn15 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn20 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "16" ]
-                        ] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn21
-                          [ mkAttr qn16 [ mkText "18" ]
-                          ] []
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "19" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "20" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "21" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "25" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "element"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn6 []
-                [ mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "name"
-                    ]
-                  , mkElement qn7
-                    [ mkAttr qn24 [ mkText "QName" ]
-                    , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                    ] []
-                  ]
-                , mkElement qn15 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn20 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "16" ]
-                        ] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn21
-                          [ mkAttr qn16 [ mkText "18" ]
-                          ] []
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "19" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "20" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "21" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "24" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "include"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn5 []
-                [ mkElement qn17
-                  [ mkAttr qn18 [ mkText "" ]
-                  ]
-                  [ mkText "href"
-                  ]
-                , mkElement qn7
-                  [ mkAttr qn24 [ mkText "anyURI" ]
-                  , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                  ] []
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "11" ]
-                        ] []
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "10" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "22" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "23" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "div"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn21
-                          [ mkAttr qn16 [ mkText "11" ]
-                          ] []
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "10" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "23" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "24" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "22" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "div"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "11" ]
-                        ] []
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "10" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "22" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "21" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "choice"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn21
-                        [ mkAttr qn16 [ mkText "18" ]
-                        ] []
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "19" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "20" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "21" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "20" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "nsName"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "17" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "19" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "anyName"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "17" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "18" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "name"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn7
-              [ mkAttr qn24 [ mkText "QName" ]
-              , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-              ] []
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "17" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "except"
-            ]
-          , mkElement qn15 []
-            [ mkElement qn6 []
-              [ mkElement qn11 [] []
-              , mkElement qn20 []
-                [ mkElement qn21
-                  [ mkAttr qn16 [ mkText "16" ]
-                  ] []
-                ]
-              ]
-            , mkElement qn20 []
-              [ mkElement qn6 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn21
-                      [ mkAttr qn16 [ mkText "18" ]
-                      ] []
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "19" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "20" ]
-                    ] []
-                  ]
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "21" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "16" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn4 []
-            [ mkElement qn12 []
-              [ mkElement qn19
-                [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                ] []
-              ]
-            ]
-          , mkElement qn6 []
-            [ mkElement qn11 [] []
-            , mkElement qn20 []
-              [ mkElement qn6 []
-                [ mkElement qn6 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 [] []
-                    , mkElement qn23 [] []
-                    ]
-                  , mkElement qn23 [] []
-                  ]
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "0" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "0" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn4 [] []
-          , mkElement qn6 []
-            [ mkElement qn11 [] []
-            , mkElement qn20 []
-              [ mkElement qn6 []
-                [ mkElement qn6 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 [] []
-                    , mkElement qn23 [] []
-                    ]
-                  , mkElement qn23 [] []
-                  ]
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "0" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "10" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "define"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "name"
-                    ]
-                  , mkElement qn7
-                    [ mkAttr qn24 [ mkText "NCName" ]
-                    , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                    ] []
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "combine"
-                      ]
-                    , mkElement qn6 []
-                      [ mkElement qn25
-                        [ mkAttr qn1 [ mkText "http://www.w3.org/XML/1998/namespace" ]
-                        , mkAttr qn3 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                        , mkAttr qn2 [ mkText "file:///home/uwe/haskell/hxt/curr/src/Text/XML/HXT/RelaxNG/schema2hs/SchemaGrammar.rng" ]
-                        , mkAttr qn8 [ mkText "" ]
-                        , mkAttr qn24 [ mkText "token" ]
-                        , mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                        ]
-                        [ mkText "choice"
-                        ]
-                      , mkElement qn25
-                        [ mkAttr qn1 [ mkText "http://www.w3.org/XML/1998/namespace" ]
-                        , mkAttr qn3 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                        , mkAttr qn2 [ mkText "file:///home/uwe/haskell/hxt/curr/src/Text/XML/HXT/RelaxNG/schema2hs/SchemaGrammar.rng" ]
-                        , mkAttr qn8 [ mkText "" ]
-                        , mkAttr qn24 [ mkText "token" ]
-                        , mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                        ]
-                        [ mkText "interleave"
-                        ]
-                      ]
-                    ]
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn20 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn6 []
-                                                    [ mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "25" ]
-                                                      ] []
-                                                    , mkElement qn21
-                                                      [ mkAttr qn16 [ mkText "26" ]
-                                                      ] []
-                                                    ]
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "27" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "28" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "29" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "30" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "31" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "32" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "33" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "34" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "35" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "36" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "37" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "38" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "39" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "40" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "43" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "44" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "14" ]
-                    ] []
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "11" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "start"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn5 []
-                  [ mkElement qn17
-                    [ mkAttr qn18 [ mkText "" ]
-                    ]
-                    [ mkText "combine"
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn25
-                      [ mkAttr qn1 [ mkText "http://www.w3.org/XML/1998/namespace" ]
-                      , mkAttr qn3 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                      , mkAttr qn2 [ mkText "file:///home/uwe/haskell/hxt/curr/src/Text/XML/HXT/RelaxNG/schema2hs/SchemaGrammar.rng" ]
-                      , mkAttr qn8 [ mkText "" ]
-                      , mkAttr qn24 [ mkText "token" ]
-                      , mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                      ]
-                      [ mkText "choice"
-                      ]
-                    , mkElement qn25
-                      [ mkAttr qn1 [ mkText "http://www.w3.org/XML/1998/namespace" ]
-                      , mkAttr qn3 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                      , mkAttr qn2 [ mkText "file:///home/uwe/haskell/hxt/curr/src/Text/XML/HXT/RelaxNG/schema2hs/SchemaGrammar.rng" ]
-                      , mkAttr qn8 [ mkText "" ]
-                      , mkAttr qn24 [ mkText "token" ]
-                      , mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                      ]
-                      [ mkText "interleave"
-                      ]
-                    ]
-                  ]
-                ]
-              , mkElement qn14 []
-                [ mkElement qn14 []
-                  [ mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "ns"
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  , mkElement qn6 []
-                    [ mkElement qn11 [] []
-                    , mkElement qn5 []
-                      [ mkElement qn17
-                        [ mkAttr qn18 [ mkText "" ]
-                        ]
-                        [ mkText "datatypeLibrary"
-                        ]
-                      , mkElement qn7
-                        [ mkAttr qn24 [ mkText "anyURI" ]
-                        , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                        ] []
-                      ]
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn20 []
-                    [ mkElement qn5 []
-                      [ mkElement qn4 []
-                        [ mkElement qn12 []
-                          [ mkElement qn6 []
-                            [ mkElement qn19
-                              [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                              ] []
-                            , mkElement qn19
-                              [ mkAttr qn18 [ mkText "" ]
-                              ] []
-                            ]
-                          ]
-                        ]
-                      , mkElement qn23 [] []
-                      ]
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn6 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn6 []
-                          [ mkElement qn6 []
-                            [ mkElement qn6 []
-                              [ mkElement qn6 []
-                                [ mkElement qn6 []
-                                  [ mkElement qn6 []
-                                    [ mkElement qn6 []
-                                      [ mkElement qn6 []
-                                        [ mkElement qn6 []
-                                          [ mkElement qn6 []
-                                            [ mkElement qn6 []
-                                              [ mkElement qn6 []
-                                                [ mkElement qn6 []
-                                                  [ mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "25" ]
-                                                    ] []
-                                                  , mkElement qn21
-                                                    [ mkAttr qn16 [ mkText "26" ]
-                                                    ] []
-                                                  ]
-                                                , mkElement qn21
-                                                  [ mkAttr qn16 [ mkText "27" ]
-                                                  ] []
-                                                ]
-                                              , mkElement qn21
-                                                [ mkAttr qn16 [ mkText "28" ]
-                                                ] []
-                                              ]
-                                            , mkElement qn21
-                                              [ mkAttr qn16 [ mkText "29" ]
-                                              ] []
-                                            ]
-                                          , mkElement qn21
-                                            [ mkAttr qn16 [ mkText "30" ]
-                                            ] []
-                                          ]
-                                        , mkElement qn21
-                                          [ mkAttr qn16 [ mkText "31" ]
-                                          ] []
-                                        ]
-                                      , mkElement qn21
-                                        [ mkAttr qn16 [ mkText "32" ]
-                                        ] []
-                                      ]
-                                    , mkElement qn21
-                                      [ mkAttr qn16 [ mkText "33" ]
-                                      ] []
-                                    ]
-                                  , mkElement qn21
-                                    [ mkAttr qn16 [ mkText "34" ]
-                                    ] []
-                                  ]
-                                , mkElement qn21
-                                  [ mkAttr qn16 [ mkText "35" ]
-                                  ] []
-                                ]
-                              , mkElement qn21
-                                [ mkAttr qn16 [ mkText "36" ]
-                                ] []
-                              ]
-                            , mkElement qn21
-                              [ mkAttr qn16 [ mkText "37" ]
-                              ] []
-                            ]
-                          , mkElement qn21
-                            [ mkAttr qn16 [ mkText "38" ]
-                            ] []
-                          ]
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "39" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "40" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "43" ]
-                      ] []
-                    ]
-                  , mkElement qn21
-                    [ mkAttr qn16 [ mkText "44" ]
-                    ] []
-                  ]
-                , mkElement qn21
-                  [ mkAttr qn16 [ mkText "14" ]
-                  ] []
-                ]
-              ]
-            ]
-          ]
-        ]
-      , mkElement qn9
-        [ mkAttr qn16 [ mkText "14" ]
-        ]
-        [ mkElement qn10 []
-          [ mkElement qn17
-            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-            ]
-            [ mkText "grammar"
-            ]
-          , mkElement qn14 []
-            [ mkElement qn14 []
-              [ mkElement qn14 []
-                [ mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "ns"
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                , mkElement qn6 []
-                  [ mkElement qn11 [] []
-                  , mkElement qn5 []
-                    [ mkElement qn17
-                      [ mkAttr qn18 [ mkText "" ]
-                      ]
-                      [ mkText "datatypeLibrary"
-                      ]
-                    , mkElement qn7
-                      [ mkAttr qn24 [ mkText "anyURI" ]
-                      , mkAttr qn8 [ mkText "http://www.w3.org/2001/XMLSchema-datatypes" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn5 []
-                    [ mkElement qn4 []
-                      [ mkElement qn12 []
-                        [ mkElement qn6 []
-                          [ mkElement qn19
-                            [ mkAttr qn18 [ mkText "http://relaxng.org/ns/structure/1.0" ]
-                            ] []
-                          , mkElement qn19
-                            [ mkAttr qn18 [ mkText "" ]
-                            ] []
-                          ]
-                        ]
-                      ]
-                    , mkElement qn23 [] []
-                    ]
-                  ]
-                ]
-              ]
-            , mkElement qn15 []
-              [ mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn21
-                    [ mkAttr qn16 [ mkText "16" ]
-                    ] []
-                  ]
-                ]
-              , mkElement qn6 []
-                [ mkElement qn11 [] []
-                , mkElement qn20 []
-                  [ mkElement qn6 []
-                    [ mkElement qn6 []
-                      [ mkElement qn6 []
-                        [ mkElement qn21
-                          [ mkAttr qn16 [ mkText "11" ]
-                          ] []
-                        , mkElement qn21
-                          [ mkAttr qn16 [ mkText "10" ]
-                          ] []
-                        ]
-                      , mkElement qn21
-                        [ mkAttr qn16 [ mkText "23" ]
-                        ] []
-                      ]
-                    , mkElement qn21
-                      [ mkAttr qn16 [ mkText "24" ]
-                      ] []
-                    ]
-                  ]
-                ]
-              ]
-            ]
-          ]
-        ]
-      ]
-    ]
diff --git a/src/Text/XML/HXT/RelaxNG/Simplification.hs b/src/Text/XML/HXT/RelaxNG/Simplification.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/Simplification.hs
+++ /dev/null
@@ -1,2321 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.Simplification
-   Copyright  : Copyright (C) 2008 Torben Kuseler, Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : stable
-   Portability: portable
-
-   The modul creates the simplified form of a Relax NG schema.
-   See also chapter 4 of the Relax NG specification.
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.Simplification
-  ( createSimpleForm
-  , getErrors
-  )
-
-where
-
-
-import Control.Arrow.ListArrows
-
-import           Text.XML.HXT.DOM.Interface
-import qualified Text.XML.HXT.DOM.XmlNode as XN
-    ( mkAttr
-    , mkText
-    )
-
-import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
-
-import Text.XML.HXT.Arrow.Namespace
-    ( processWithNsEnv
-    , propagateNamespaces
-    )
-
-import Text.XML.HXT.Arrow.Edit
-    ( removeWhiteSpace
-    )
-
-import Text.XML.HXT.RelaxNG.DataTypes
-import Text.XML.HXT.RelaxNG.BasicArrows
-import Text.XML.HXT.RelaxNG.CreatePattern
-import Text.XML.HXT.RelaxNG.DataTypeLibraries
-import Text.XML.HXT.RelaxNG.Utils
-import Text.XML.HXT.RelaxNG.Validation
-import Text.XML.HXT.RelaxNG.Schema        as S
-import Text.XML.HXT.RelaxNG.SchemaGrammar as SG
-
-import Data.Maybe
-    ( fromJust
-    , fromMaybe
-    , isNothing
-    )
-import Data.List
-    ( elemIndices
-    , isPrefixOf
-    , nub
-    , deleteBy
-    , find
-    , (\\)
-    )
-
-import System.Directory
-  ( doesFileExist )
-
-
--- ------------------------------------------------------------
-
-{-
-- 4.1. Annotations: Foreign attributes and elements are removed.
-- 4.2. Whitespace:
-    - For each element other than value and param, each child that is a string
-      containing only whitespace characters is removed. -> fertig
-    - Leading and trailing whitespace characters are removed from the value of each name,
-      type and combine attribute and from the content of each name element. -> fertig
-- 4.3. datatypeLibrary attribute:
-    - The value of each datatypeLibary attribute is transformed by escaping disallowed characters
-    - For any data or value element that does not have a datatypeLibrary attribute,
-      a datatypeLibrary attribute is added.
-    - Any datatypeLibrary attribute that is on an element other than data or value is removed.
-- 4.4. type attribute of value element
--}
-simplificationStep1 :: IOSArrow XmlTree XmlTree
-simplificationStep1
-    = ( {-
-        - 4.5. href attribute
-        - The value of the href attribute on an externalRef or include element is first
-        - transformed by escaping disallowed characters
-        - The URI reference is then resolved into an absolute form
-        - The value of the href attribute will be used to construct an element.
-        -}
-        ( processHref $< getBaseURI )
-        >>>
-        -- 4.10 QNames
-        processWithNsEnv processEnvNames (toNsEnv [("xml",xmlNamespace)])
-        >>>
-        -- 4.4 For any data or value element that does not have a datatypeLibrary attribute,
-        -- a datatypeLibrary attribute is added.
-        -- Wird vorgezogen, da danach der Rest in einem Baumdurchlauf erledigt werden kann
-        processdatatypeLib ""
-        >>>
-        processTopDownWithAttrl
-        (
-         ( -- 4.1 Foreign attributes and elements are removed
-           none
-           `when`
-           ( ( isElem >>> neg isRoot
-               >>>
-               getNamespaceUri
-               >>>
-               isA (\ uri -> (not $ compareURI uri relaxNamespace))
-             )
-             `orElse`
-             ( isAttr
-               >>>
-               getNamespaceUri
-               >>>
-               isA (\ uri -> (uri /= "" && (not $ compareURI uri relaxNamespace)))
-             )
-           )
-         )
-         >>>
-         ( -- 4.2 For each element other than value and param, each child that
-           -- is a string containing only whitespace characters is removed.
-           ( processChildren removeWhiteSpace
-             `whenNot`
-             (isRngParam `orElse` isRngValue)
-           )
-           `when` isElem
-         )
-         >>>
-         ( -- 4.2 Leading and trailing whitespace characters are removed from the value
-           -- of each name, type and combine attribute ...
-           changeAttrValue normalizeWhitespace
-           `when`
-           ( isRngAttrName `orElse` isRngAttrType `orElse` isRngAttrCombine)
-         )
-         >>>
-         ( -- 4.2 ... and from the content of each name element.
-           processChildren (changeText normalizeWhitespace)
-           `when`
-           isRngName
-         )
-         >>>
-         ( -- 4.3 The value of each datatypeLibary attribute is transformed
-           -- by escaping disallowed characters
-           changeAttrValue escapeURI
-           `when`
-           isRngAttrDatatypeLibrary
-         )
-         >>>
-         ( -- The value of the datatypeLibary attribute has to be a valid URI
-           ( mkRelaxError "" $< ( getRngAttrDatatypeLibrary
-                                  >>>
-                                  arr (\ a -> ( "datatypeLibrary attribute: " ++
-                                                a ++ " is not a valid URI"
-                                              )
-                                      )
-                                )
-           )
-           `when`
-           ( isElem
-             >>>
-             hasRngAttrDatatypeLibrary
-             >>>
-             getRngAttrDatatypeLibrary >>> isA (not . isRelaxAnyURI)
-           )
-         )
-         >>>
-         ( -- 4.3 Any datatypeLibrary attribute that is on an element
-           -- other than data or value is removed.
-           removeAttr "datatypeLibrary"
-           `when`
-           ( isElem
-             >>>
-             neg (isRngData `orElse` isRngValue)
-             >>>
-             hasRngAttrDatatypeLibrary
-           )
-         )
-         >>>
-         ( -- 4.4 For any value element that does not have a type attribute,
-           -- a type attribute is added with value token and the value of
-           -- the datatypeLibrary attribute is changed to the empty string.
-           ( addAttr "type" "token"
-             >>>
-             addAttr "datatypeLibrary" ""
-           )
-           `when`
-           ( isRngValue >>> neg hasRngAttrType )
-         )
-        )
-      ) `when` collectErrors
-    where
-    processHref :: String -> IOSArrow XmlTree XmlTree
-    processHref uri
-        = processChildren
-          ( choiceA
-            [ ( isElem >>> hasAttr "xml:base" )
-              :-> ( ifA ( isExternalRefInclude >>> hasRngAttrHref )
-                    ( -- The value of the href attribute is transformed by
-                      -- escaping disallowed characters
-                      (processAttrl (changeAttrValue escapeURI `when` isRngAttrHref))
-                      >>> -- compute the new base uri from the old uri and the href attribute
-                      (addAttr "href" $< (absURI "href" $< (absURI "xml:base" uri)))
-                      >>>
-                      (processHref $< absURI "xml:base" uri)
-                    ) -- element without a href attribute, just compute the new base uri
-                    (processHref $< absURI "xml:base" uri)
-                  )
-            , ( isExternalRefInclude >>> hasRngAttrHref )
-              :-> ( -- The value of the href attribute is transformed by
-                    -- escaping disallowed characters
-                    (processAttrl (changeAttrValue escapeURI `when` isRngAttrHref))
-                    >>>
-                    (addAttr "href" $< absURI "href" uri)
-                  )
-            , this
-              :-> processHref uri
-            ]
-          )
-        where
-        absURI :: String -> String -> IOSArrow XmlTree String
-        absURI attrName u
-            = ( getAttrValue attrName
-                >>>
-                arr (\ a -> fromMaybe "" (expandURIString a u))
-                >>> -- the uri should not have a fragment-identifier (4.5)
-                ( arr ("illegal URI, fragment identifier not allowed: " ++)
-                  `whenNot`
-                  (getFragmentFromURI >>> isA null)
-                )
-              )
-
-    processEnvNames :: NsEnv -> IOSArrow XmlTree XmlTree
-    processEnvNames env
-        = ( ( (replaceQNames env $< getAttrValue "name")
-              `when`
-              ( (isRngElement `orElse` isRngAttribute)
-                >>>
-                getRngAttrName
-                >>>
-                isA (elem ':')
-              )
-            )
-            >>>
-            ( (addAttrl (getBaseURI >>> createAttrL))
-              `when`
-              isRngValue
-            )
-          )
-        where
-        createAttrL :: IOSArrow String XmlTree
-        createAttrL
-            = setBaseUri &&& constA (map createAttr env) >>> arr2L (:)
-            where
-
-            createAttr :: (XName, XName) -> XmlTree
-            createAttr (pre, uri)
-                = XN.mkAttr (mkName nm) [XN.mkText (show uri)]
-                where
-                nm  | isNullXName pre   = "RelaxContextDefault"
-                    | otherwise         = contextAttributes ++ show pre
-
-            setBaseUri :: IOSArrow String XmlTree
-            setBaseUri = mkAttr (mkName contextBaseAttr) (txt $< this)
-
-        replaceQNames :: NsEnv -> String -> IOSArrow XmlTree XmlTree
-        replaceQNames e name
-            | isNothing uri
-                = mkRelaxError "" ( "No Namespace-Mapping for the prefix " ++ show pre ++
-                                    " in the Context of Element: " ++ show name
-                                  )
-            | otherwise
-                = addAttr "name" ( "{" ++ (show . fromJust $ uri) ++ "}" ++ local )
-            where
-            (pre, local') = span (/= ':') name
-            local         = tail local'
-            uri         :: Maybe XName
-            uri           = lookup (newXName pre) e
-
-    -- The value of the added datatypeLibrary attribute is the value of the
-    -- datatypeLibrary attribute of the nearest ancestor element that
-    -- has a datatypeLibrary attribute, or the empty string
-    -- if there is no such ancestor.
-    processdatatypeLib :: (ArrowXml a) => String -> a XmlTree XmlTree
-    processdatatypeLib lib
-        = processChildren $
-          choiceA
-          [ ( isElem >>> hasRngAttrDatatypeLibrary
-            -- set the new datatypeLibrary value
-            )
-            :->
-            ( processdatatypeLib $< getRngAttrDatatypeLibrary )
-          , ( (isRngData `orElse` isRngValue)
-              >>>
-              neg hasRngAttrDatatypeLibrary
-              -- add a datatypeLibrary attribute
-            )
-            :->
-            ( addAttr "datatypeLibrary" lib >>> processdatatypeLib lib )
-          , this
-            :->
-            processdatatypeLib lib
-          ]
-
--- ------------------------------------------------------------
-
-
-{-
-- 4.5. href attribute
-    - see simplificationStep1
-- 4.6. externalRef element
-    - An element is constructed using the URI reference
-      that is the value of href attribute
-    - This element must match the syntax for pattern.
-    - The element is transformed by recursively applying the rules from
-      this subsection and from previous subsections of this section.
-    - This must not result in a loop.
-    - Any ns attribute on the externalRef element is transferred
-      to the referenced element if the referenced element does
-      not already have an ns attribute.
-    - The externalRef element is then replaced by the referenced element.
-- 4.7. include element
-    - An element is constructed using the URI reference that is the
-      value of href attribute
-    - This element must be a grammar element, matching the syntax for grammar.
-    - This grammar element is transformed by recursively applying the rules
-      from this subsection and from previous subsections of this section.
-    - This must not result in a loop.
-
-    - If the include element has a start component, then the grammar element
-      must have a start component.
-    - If the include element has a start component, then all start components
-      are removed from the grammar element.
-    - If the include element has a define component, then the grammar element
-      must have a define component with the same name.
-    - For every define component of the include element, all define components
-      with the same name are removed from the grammar element.
-
-    - The include element is transformed into a div element.
-    - The attributes of the div element are the attributes of the
-      include element other than the href attribute.
-    - The children of the div element are the grammar element
-    - The grammar element is then renamed to div.
--}
-
-simplificationStep2 :: Attributes -> Bool -> Bool -> [Uri] -> [Uri] -> IOSArrow XmlTree XmlTree
-simplificationStep2 readOptions validateExternalRef validateInclude extHRefs includeHRefs =
-  ( processTopDown (
-      ( (importExternalRef $<< (getRngAttrNs &&& getRngAttrHref))
-        `when`
-        isRngExternalRef
-      )
-      >>>
-      ( (importInclude $< getAttrValue "href")
-        `when`
-        isRngInclude
-      )
-    )
-  ) `when` collectErrors
-  where
-  importExternalRef :: String -> String -> IOSArrow XmlTree XmlTree
-  importExternalRef ns href
-    = ifA ( neg $ constA href
-                  >>> getPathFromURI
-                  >>> ( isA (not . ("illegal URI" `isPrefixOf`))
-                        `guards`
-                        isIOA doesFileExist
-                      )
-          )
-        ( mkRelaxError ""
-          ( show href ++
-            ": can't read URI, referenced in externalRef-Pattern"
-          )
-        )
-        ( ifP (const $ elem href extHRefs)
-           -- if the referenced name already exists in the list of processed ref attributes
-           -- we have found a loop
-            ( mkRelaxError ""
-              (  "loop in externalRef-Pattern, " ++
-                 formatStringListArr (reverse $ href:extHRefs)
-              )
-            )
-            ( ifA ( if validateExternalRef                                      -- if validation parameters are set
-                    then validateDocWithRelax S.relaxSchemaArrow [] href        -- the referenced schema is validated with respect to
-                    else none                                                   -- the Relax NG specification
-                  )
-                ( mkRelaxError ""
-                  ( "The content of the schema " ++ show href ++
-                    ", referenced in externalRef does not " ++
-                    "match the syntax for pattern"
-                  )
-                )
-                ( readForRelax readOptions href
-                  >>>
-                  simplificationStep1                                           -- perform the transformations from previous steps
-                  >>>
-                  simplificationStep2 readOptions validateExternalRef validateInclude (href:extHRefs) includeHRefs
-                  >>>
-                  getChildren -- remove the root node
-                  >>>
-                  ( -- Any ns attribute on the externalRef element
-                    -- is transferred to the referenced element
-                    addAttr "ns" ns
-                    `when`
-                    (getRngAttrNs >>> isA (\a -> a == "" && ns /= ""))
-                  )
-                )
-            )
-        )
-
-  importInclude :: String -> IOSArrow XmlTree XmlTree
-  importInclude href
-    = ifA ( -- test whether the referenced schema exists
-            neg $ constA href >>> getPathFromURI >>> isIOA doesFileExist
-          )
-        ( mkRelaxError ""
-          ( "Can't read " ++ show href ++
-            ", referenced in include-Pattern"
-          )
-        )
-        ( ifP (const $ elem href includeHRefs)
-           -- if the referenced name still exists in the list of processed
-           -- ref attributes we have found a loop
-            ( mkRelaxError ""
-              ( "loop in include-Pattern, " ++
-                formatStringListArr (reverse $ href:includeHRefs)
-              )
-            )
-            ( ifA ( if validateInclude                                          -- if the parameter is set
-                    then validateDocWithRelax SG.relaxSchemaArrow [] href       -- the referenced schema is validated with respect to
-                    else none                                                   -- the Relax NG grammar element
-                  )
-                ( mkRelaxError ""
-                  ( "The content of the schema " ++ show href ++
-                    ", referenced in include does not match " ++
-                    "the syntax for grammar"
-                  )
-                )
-                ( processInclude href $< ( readForRelax readOptions href
-                                           >>>
-                                           simplificationStep1                          -- perform the transformations from previous steps
-                                           >>>
-                                           simplificationStep2 readOptions validateExternalRef validateInclude extHRefs (href:includeHRefs)
-                                           >>>
-                                           getChildren                                  -- remove the root node
-                                         )
-                )
-            )
-        )
-
-  processInclude :: String -> XmlTree -> IOSArrow XmlTree XmlTree
-  processInclude href newDoc
-    = -- The include element is transformed into a div element.
-      setRngNameDiv
-      >>>
-      -- The attributes of the div element are the attributes of
-      -- the include element other than the href attribute.
-      removeAttr "href"
-      >>>
-      checkInclude href newDoc
-
-
-  insertNewDoc :: XmlTree -> Bool -> [String] -> IOSArrow XmlTree XmlTree
-  insertNewDoc newDoc hasStart defNames
-    = insertChildrenAt 0 $
-        constA newDoc
-        >>>
-        -- If the include element has a start component, then all start components
-        -- are removed from the grammar element.
-        (removeStartComponent `whenP` (const hasStart))
-        >>>
-        -- For every define component of the include element, all define components
-        -- with the same name are removed from the grammar element.
-        ((removeDefineComponent defNames) `whenP` (const $ defNames /= []))
-        >>>
-        -- The grammar element is then renamed to div.
-        setRngNameDiv
-
-
-  checkInclude :: String -> XmlTree -> IOSArrow XmlTree XmlTree
-  checkInclude href newDoc
-    = ifA ( -- If the include element has a start component, then the grammar element
-            -- must have a start component.
-            hasStartComponent &&& (constA newDoc >>> hasStartComponent)
-            >>>
-            isA (\ (a, b) -> if a then b else True)
-          )
-        ( ifA ( -- If the include element has a define component, then the grammar element
-                -- must have a define component with the same name.
-                getDefineComponents &&& (constA newDoc >>> getDefineComponents)
-                >>>
-                isA (\ (a, b) -> (diff a b) == [])
-              )
-            (insertNewDoc newDoc $<< hasStartComponent &&& getDefineComponents)
-            ( mkRelaxError ""
-              ( "Define-pattern missing in schema " ++ show href ++
-                ", referenced in include-pattern"
-              )
-            )
-        )
-        ( mkRelaxError ""
-          ( "Grammar-element without a start-pattern in schema " ++
-            show href ++ ", referenced in include-pattern"
-          )
-        )
-    where
-    diff a b = (noDoubles a) \\ (noDoubles b)
-
-  removeStartComponent :: IOSArrow XmlTree XmlTree
-  removeStartComponent
-    = processChildren $
-        choiceA [
-          isRngStart :-> none,
-          isRngDiv   :-> removeStartComponent,
-          this       :-> this
-        ]
-
-  removeDefineComponent :: [String] -> IOSArrow XmlTree XmlTree
-  removeDefineComponent defNames
-    = processChildren $
-        choiceA [
-          ( isRngDefine
-            >>>
-            getRngAttrName
-            >>>
-            isA (\n -> elem n defNames))          :-> none,
-          (isElem >>> getName >>> isA (== "div")) :-> (removeDefineComponent defNames),
-          (constA "foo" >>> isA (== "foo"))       :-> this
-        ]
-
-  hasStartComponent :: IOSArrow XmlTree Bool
-  hasStartComponent = listA hasStartComponent' >>> arr (any id)
-    where
-    hasStartComponent' :: IOSArrow XmlTree Bool
-    hasStartComponent'
-      = getChildren
-        >>>
-        choiceA [
-          isRngStart :-> (constA True),
-          isRngDiv   :-> hasStartComponent',
-          this       :-> (constA False)
-        ]
-
-  getDefineComponents :: IOSArrow XmlTree [String]
-  getDefineComponents = listA getDefineComponents'
-                        >>>
-                        arr (\xs -> [x | x <- xs, x /= ""])
-    where
-    getDefineComponents' :: IOSArrow XmlTree String
-    getDefineComponents'
-      = getChildren
-        >>>
-        choiceA
-        [ isRngDefine :-> getRngAttrName
-        , isRngDiv    :-> getDefineComponents'
-        , this        :-> constA ""
-        ]
-
-
--- ------------------------------------------------------------
-
-
-{-
-- 4.8. name attribute of element and attribute elements
-    - The name attribute on an element or attribute element
-      is transformed into a name child element.
-    - If an attribute element has a name attribute but no ns attribute,
-      then an ns="" attribute is added to the name child element.
-- 4.9. ns attribute
-    - For any name, nsName or value element that does not have
-      an ns attribute, an ns attribute is added.
-    - any ns attribute that is on an element other than name,
-      nsName or value is removed.
-- 4.10. QNames
-    - For any name element containing a prefix, the prefix is removed
-      and an ns attribute is added replacing any existing ns attribute.
-    - The value of the added ns attribute is the value to which the
-      namespace map of the context of the name element maps the prefix.
-    - The context must have a mapping for the prefix.
--}
-simplificationStep3 :: IOSArrow XmlTree XmlTree
-simplificationStep3 =
-  ( processTopDown (
-      ( -- 4.8 The name attribute on an element or attribute
-        -- element is transformed into a name child element
-        ( insertChildrenAt 0 (mkRngName none (txt $< getRngAttrName))
-        )
-        >>>
-        ( -- 4.8 If an attribute element has a name attribute but no ns attribute,
-          --  then an ns="" attribute is added to the name child element
-           (processChildren (addAttr "ns" "" `when` isRngName))
-           `when`
-           (isRngAttribute >>> hasRngAttrName >>> neg hasRngAttrNs)
-        )
-        >>>
-        removeAttr "name"
-      )
-      `when`
-      ( (isRngElement `orElse` isRngAttribute) >>> hasRngAttrName )
-    )
-    >>>
-    -- 4.9 For any name, nsName or value element that does not have
-    -- an ns attribute, an ns attribute is added.
-    processnsAttribute ""
-    >>>
-    processTopDown (
-      ( -- 4.9 any ns attribute that is on an element other than name,
-        -- nsName or value is removed.
-        (removeAttr "ns")
-        `when`
-        (isElem >>> neg (isRngName `orElse` isRngNsName `orElse` isRngValue))
-      )
-      >>>
-      ( -- 4.10 For any name element containing a prefix, the prefix is removed and an ns attribute
-        -- is added replacing any existing ns attribute.
-        (replaceNameAttr $< (getChildren >>> isText >>> getText))
-        `when`
-        isRngName
-      )
-    )
-  ) `when` collectErrors
-  where
-  replaceNameAttr :: (ArrowXml a) => String -> a XmlTree XmlTree
-  replaceNameAttr name
-    = (addAttr "ns" pre >>> processChildren (changeText $ const local))
-      `whenP`
-      (const $ elem '}' name)
-    where
-    (pre', local') = span (/= '}') name
-    pre            = tail pre'
-    local          = tail local'
-
-  processnsAttribute :: String -> IOSArrow XmlTree XmlTree
-  processnsAttribute name
-    = processChildren $
-        choiceA [
-          -- set the new ns attribute value
-          (isElem >>> hasRngAttrNs)
-               :-> (processnsAttribute $< getRngAttrNs),
-          -- For any name, nsName or value element that does not have
-          -- an ns attribute, an ns attribute is added.
-          ( isNameNsNameValue >>> neg hasRngAttrNs)
-               :-> (addAttr "ns" name >>> processnsAttribute name),
-          this :-> (processnsAttribute name)
-        ]
-
-
--- ------------------------------------------------------------
-
-
-{-
-- 4.11 Each div element is replaced by its children
-- 4.12 Number of child elements
-    - A define, oneOrMore, zeroOrMore, optional, list or mixed element
-      is transformed so that it has exactly one child element
-    - An element element is transformed so that it has exactly two child elements
-    - A except element is transformed so that it has exactly one child element
-    - If an attribute element has only one child element (a name class), then a text element is added.
-    - A choice, group or interleave element is transformed so that it has exactly two child elements.
-- 4.13 A mixed element is transformed into an interleaving with a text element
-- 4.14 An optional element is transformed into a choice with empty
-- 4.15 A zeroOrMore element is transformed into a choice between oneOrMore and empty
-- 4.16. Constraints: no transformation is performed, but various constraints are checked.
-    - An except element that is a child of an anyName element must not have any anyName descendant elements.
-    - An except element that is a child of an nsName element must not have any nsName or anyName
-      descendant elements.
-    - A name element that occurs as the first child of an attribute element or as the descendant of the
-      first child of an attribute element and that has an ns attribute with value equal to the empty
-      string must not have content equal to xmlns.
-    - A name or nsName element that occurs as the first child of an attribute element or as the
-      descendant of the first child of an attribute element must not have an ns attribute with
-      value http://www.w3.org/2000/xmlns.
-    - A data or value element must be correct in its use of datatypes.
--}
-simplificationStep4 :: IOSArrow XmlTree XmlTree
-simplificationStep4 =
-  ( processTopDown (
-      ( -- Each div element is replaced by its children.
-        (getChildren >>> simplificationStep4)
-        `when`
-        isRngDiv
-      )
-      >>>
-      ( -- A define, oneOrMore, zeroOrMore, optional, list or mixed element
-        -- is transformed so that it has exactly one child element
-        ( replaceChildren
-          ( mkRngGroup
-            (setChangesAttr $< (getName >>> arr ("group-Pattern: " ++)))
-            getChildren
-          )
-        )
-        `when`
-        (  isDefineOneOrMoreZeroOrMoreOptionalListMixed
-           >>>
-           noOfChildren (> 1)
-        )
-      )
-      >>>
-      ( -- An element element is transformed so that it has exactly two child elements
-        ( replaceChildren
-          ( ( getChildren >>> isNameAnyNameNsName )
-            <+>
-            ( mkRngGroup none
-              ( getChildren
-                >>>
-                neg isNameAnyNameNsName
-              )
-            )
-          )
-        )
-        `when`
-        ( isRngElement >>> noOfChildren (> 2) )
-      )
-      >>>
-      ( -- A except element is transformed so that it has exactly one child element.
-        replaceChildren ( mkRngChoice none getChildren )
-        `when`
-        ( isRngExcept >>> noOfChildren (> 1) )
-      )
-      >>>
-      ( -- If an attribute element has only one child element
-        -- (a name class), then a text element is added.
-        insertChildrenAt 1 (mkRngText none)
-        `when`
-        ( isRngAttribute >>> noOfChildren (== 1) )
-      )
-      >>>
-      ( -- A choice, group or interleave element is transformed so
-        -- that it has exactly two child elements.
-        ((wrapPattern2Two $< getName) >>> simplificationStep4)
-        `when`
-        (  isChoiceGroupInterleave
-           >>>
-           noOfChildren (\ i -> i > 2 || i == 1)
-        )
-      )
-      >>>
-      ( -- A mixed element is transformed into an interleaving with a text element
-        ( mkRngInterleave
-          ( setChangesAttr "mixed is transformed into an interleave" )
-          ( getChildren
-            <+>
-            mkRngText
-            ( setChangesAttr ( "new text-Pattern: mixed is transformed into " ++
-                                  " an interleave with text"
-                             )
-            )
-          )
-        )
-        `when`
-        isRngMixed
-      )
-      >>>
-      ( -- An optional element is transformed into a choice with empty
-        ( mkRngChoice
-          ( setChangesAttr "optional is transformed into a choice" )
-          ( getChildren
-            <+>
-            mkRngEmpty
-            ( setChangesAttr ( "new empty-Pattern: optional is transformed " ++
-                               " into a choice with empty"
-                             )
-            )
-          )
-        )
-        `when`
-        isRngOptional
-      )
-      >>>
-      ( -- A zeroOrMore element is transformed into a choice between oneOrMore and empty
-        ( mkRngChoice
-          ( setChangesAttr "zeroOrMore is transformed into a choice" )
-          ( ( mkRngOneOrMore
-              ( setChangesAttr ( "zeroOrMore is transformed into a " ++
-                                   "choice between oneOrMore and empty"
-                               )
-              )
-              getChildren
-            )
-            <+>
-            ( mkRngEmpty
-              ( setChangesAttr ( "new empty-Pattern: zeroOrMore is transformed " ++
-                                   "into a choice between oneOrMore and empty"
-                               )
-              )
-            )
-          )
-        )
-        `when`
-        isRngZeroOrMore
-      )
-    )
-  ) `when` collectErrors
-
-
--- ------------------------------------------------------------
-
-
-restrictionsStep1 :: IOSArrow XmlTree XmlTree
-restrictionsStep1 =
-  ( processTopDown (
-      ( ( mkRelaxError ""
-          ( "An except element that is a child of an anyName " ++
-            "element must not have any anyName descendant elements"
-          )
-        )
-        `when`
-        ( isRngAnyName
-          >>>
-          getChildren
-          >>>
-          isRngExcept
-          >>>
-          deep isRngAnyName
-        )
-      )
-      >>>
-      ( ( mkRelaxError ""
-          ( "An except element that is a child of an nsName element " ++
-            "must not have any nsName or anyName descendant elements."
-          )
-        )
-        `when`
-        ( isRngNsName
-          >>>
-          getChildren
-          >>>
-          isRngExcept
-          >>>
-          deep (isRngAnyName `orElse` isRngNsName)
-        )
-      )
-      >>>
-      ( ( mkRelaxError ""
-          ( "A name element that occurs as the first child or descendant of " ++
-            "an attribute and has an ns attribute with an empty value must " ++
-            "not have content equal to \"xmlns\""
-          )
-        )
-        `when`
-        ( isRngAttribute
-          >>>
-          firstChild
-          >>>
-          ( multi (isRngName >>> hasRngAttrNs) )
-          >>>
-          ( ( getRngAttrNs >>> isA null)
-            `guards`
-            (getChildren >>> getText >>> isA (== "xmlns"))
-          )
-        )
-      )
-      >>>
-      ( ( mkRelaxError ""
-          ( "A name or nsName element that occurs as the first child or " ++
-            "descendant of an attribute must not have an ns attribute " ++
-            "with value http://www.w3.org/2000/xmlns"
-          )
-        )
-        `when`
-        ( isRngAttribute
-          >>>
-          firstChild
-          >>>
-          ( multi (isNameNsName >>> hasRngAttrNs) )
-          >>>
-          getRngAttrNs
-          >>>
-          isA (compareURI xmlnsNamespace)
-        )
-      )
-      >>> -- A data or value element must be correct in its use of datatypes.
-      ( ( checkDatatype $<< getRngAttrDatatypeLibrary &&& getRngAttrType )
-        `when`
-        ( isRngData `orElse` isRngValue )
-      )
-    )
-  ) `when` collectErrors
-  where
-
-  -- the datatypeLibrary attribute must identify a valid datatype library
-
-  checkDatatype :: Uri -> DatatypeName -> IOSArrow XmlTree XmlTree
-  checkDatatype libName typeName
-      = ifP (const $ elem libName $ map fst datatypeLibraries)
-        ( checkType libName typeName allowedDataTypes )
-        ( mkRelaxError ""
-          ( "DatatypeLibrary " ++ show libName ++ " not found" )
-        )
-    where
-    DTC _ _ allowedDataTypes = fromJust $ lookup libName datatypeLibraries
-
-  -- the type attribute must identify a datatype within the datatype library identified
-  -- by the value of the datatypeLibrary attribute.
-
-  checkType :: Uri -> DatatypeName -> AllowedDatatypes -> IOSArrow XmlTree XmlTree
-  checkType libName typeName allowedTypes
-      = ifP (const $ elem typeName $ map fst allowedTypes)
-        ( checkParams typeName libName getParams $<
-          ( listA (getChildren >>> isRngParam >>> getRngAttrName) )
-        )
-       ( mkRelaxError ""
-         ( "Datatype " ++ show typeName ++
-           " not declared for DatatypeLibrary " ++ show libName
-         )
-       )
-    where
-    getParams = fromJust $ lookup typeName allowedTypes
-
-  -- For a data element, the parameter list must be one that is allowed by the datatype
-
-  checkParams :: DatatypeName -> Uri -> AllowedParams -> [ParamName] -> IOSArrow XmlTree XmlTree
-  checkParams typeName libName allowedParams paramNames
-      = ( mkRelaxError ""
-          ( "Param(s): " ++ formatStringListQuot diff ++
-            " not allowed for Datatype " ++ show typeName ++
-            " in Library " ++
-            show ( if null libName
-                   then relaxNamespace
-                   else libName
-                 )
-          )
-        )
-        `when`
-        ( isRngData >>> isA (const $ diff /= []) )
-      where
-      diff = filter (\param -> not $ elem param allowedParams) paramNames
-
-
--- ------------------------------------------------------------
-
-
-{-
-- 4.17. combine attribute
-    - For each grammar element, all define elements with the same name are combined together.
-    - Similarly, for each grammar element all start elements are combined together.
-- 4.18. grammar element
-    - A grammar must have a start child element.
-    - Transform the top-level pattern p into <grammar><start>p</start></grammar>.
-    - Rename define elements so that no two define elements anywhere in the schema
-      have the same name. To rename a define element, change the value of its name
-      attribute and change the value of the name attribute of all ref and parentRef
-      elements that refer to that define element.
-    - Move all define elements to be children of the top-level grammar element
-    - Replace each nested grammar element by the child of its start element
-    - Rename each parentRef element to ref.
--}
-simplificationStep5 :: IOSArrow XmlTree XmlTree
-simplificationStep5
-    = ( processTopDown
-        ( ( ( ( (deep isRngRelaxError)
-                <+>
-                ( mkRelaxError "" "A grammar must have a start child element" )
-              )
-              `when`
-              (neg (getChildren >>> isRngStart))
-            )
-            >>>
-            -- For each grammar element, all define elements with the same
-            -- name are combined together.
-            ( combinePatternList "define" $< (getPatternNamesInGrammar "define" >>> arr nub) )
-            >>>
-            -- Similarly, for each grammar element all start elements
-            -- are combined together.
-            ( combinePatternList "start" $< (getPatternNamesInGrammar "start" >>> arr nub) )
-          )
-          `when`
-          isRngGrammar
-        )
-        >>>
-        ( -- transform the top-level pattern p into <grammar><start>p</start></grammar>.
-          ( replaceChildren
-            ( mkRngGrammar none
-              ( mkRngStart none getChildren )
-            )
-          )
-          `when`
-          neg (getChildren >>> isRngGrammar)
-        )
-        >>>
-        ( renameDefines $<<
-          ( getPatternNamesInGrammar "define"
-            >>>
-            (createUniqueNames $< (getAndSetCounter "define_id" >>> arr read))
-            &&&
-            constA []
-          )
-        )
-        >>>
-        -- Move all define elements to be children of the top-level grammar element
-        ( processChildren
-          ( -- root node
-            processChildren
-            ( -- the first grammar pattern remains unchanged
-              ( deleteAllDefines
-                <+>
-                ( getAllDefines >>> processChildren deleteAllDefines )
-              )
-              >>>
-              processTopDown
-              ( ( -- Replace each nested grammar element by the child of its start element
-                  ( getChildren >>> isRngStart >>> getChildren )
-                  `when`
-                  isRngGrammar
-                )
-                >>>
-                ( -- Rename each parentRef element to ref.
-                  ( setRngNameRef
-                    `when`
-                    isRngParentRef
-                  )
-                )
-              )
-            )
-          )
-        )
-      ) `when` collectErrors
-    where
-    getPatternNamesInGrammar :: (ArrowXml a) => String -> a XmlTree [String]
-    getPatternNamesInGrammar pattern
-        = processChildren
-          ( processTopDown ( none `when` isRngGrammar ) )
-          >>>
-          listA ( (multi (isElem >>> hasRngName pattern))
-                  >>>
-                  getRngAttrName
-                )
-
-    createUniqueNames :: Int -> IOSArrow [String] RefList
-    createUniqueNames num
-        = arr (\ l -> unique l num)
-          >>>
-          perform (setParamInt "define_id" $< arr (max num . getNextValue))
-        where
-        unique :: [String] -> Int -> RefList
-        unique []     _    = []
-        unique (x:xs) num' = (x, (show num')):(unique xs (num'+1))
-        getNextValue :: RefList -> Int
-        getNextValue [] = 0
-        getNextValue rl = maximum (map (read . snd) rl) + 1
-
-    renameDefines :: RefList -> RefList -> IOSArrow XmlTree XmlTree
-    renameDefines ref parentRef
-        = processChildren
-          ( choiceA
-            [ isRngDefine
-              :-> ( -- the original name is needed for error messages
-                    addAttr defineOrigName $< getRngAttrName
-                    >>>
-                    -- rename the define-pattern
-                    -- the new name is looked up in the ref table
-                    addAttr "name" $< ( getRngAttrName
-                                        >>>
-                                        arr (\n -> fromJust $ lookup n ref)
-                                      )
-                    >>>
-                    renameDefines ref parentRef
-                  )
-            , isRngGrammar
-              :-> ( renameDefines $<< ( ( -- compute all define names in the grammar
-                                          getPatternNamesInGrammar "define"
-                                          >>>
-                                          -- create a new (unique) name for all define names
-                                          (createUniqueNames $< (getParamInt 0 "define_id"))
-                                        )
-                                        &&&
-                                        -- set the old ref list to be the new parentRef list
-                                        constA ref
-                                      )
-                  )
-            , isRngRef
-              :-> ( ifA ( getRngAttrName
-                          >>>
-                          isA (\name -> (elem name (map fst ref)))
-                        )
-                    ( -- the original name is needed for error messages
-                      addAttr defineOrigName $< getRngAttrName
-                      >>>
-                      -- rename the ref-pattern
-                      -- the new name is looked up in the ref table
-                      addAttr "name" $< ( getRngAttrName
-                                          >>>
-                                          arr (\n -> fromJust $ lookup n ref)
-                                        )
-                    )
-                    ( -- the referenced pattern does not exist in the schema
-                      mkRelaxError "" $< ( getRngAttrName
-                                           >>>
-                                           arr (\ n -> ( "Define-Pattern with name " ++ show n ++
-                                                         " referenced in ref-Pattern not " ++
-                                                         "found in schema"
-                                                       )
-                                               )
-                                         )
-                    )
-                  )
-            , isRngParentRef -- same as ref, but the parentRef list is used
-              :-> ( ifA ( getRngAttrName
-                          >>>
-                          isA (\name -> (elem name (map fst parentRef)))
-                        )
-                    ( addAttr defineOrigName $< getRngAttrName
-                      >>>
-                      addAttr "name" $< ( getRngAttrName
-                                          >>>
-                                          arr (\n -> fromJust $ lookup n parentRef)
-                                        )
-                    )
-                    ( mkRelaxError "" $<
-                      ( getRngAttrName
-                        >>>
-                        arr (\ n -> ( "Define-Pattern with name " ++ show n ++
-                                      " referenced in parentRef-Pattern " ++
-                                      "not found in schema"
-                                    )
-                            )
-                      )
-                    )
-                  )
-            , this
-              :-> renameDefines ref parentRef
-            ]
-          )
-
-
-    getAllDefines :: IOSArrow XmlTree XmlTree
-    getAllDefines = multi isRngDefine
-
-    deleteAllDefines :: IOSArrow XmlTree XmlTree
-    deleteAllDefines = processTopDown $ none `when` isRngDefine
-
-    combinePatternList :: String -> [String] -> IOSArrow XmlTree XmlTree
-    combinePatternList _ [] = this
-    combinePatternList pattern (x:xs)
-        = (replaceChildren $ combinePattern pattern x)
-          >>>
-          combinePatternList pattern xs
-
-    -- combine a define- or start-pattern (first parameter) with a
-    -- specific name (second parameter)
-    combinePattern :: String -> String -> IOSArrow XmlTree XmlTree
-    combinePattern pattern name
-        = createPatternElems pattern name
-          <+>
-          (getChildren >>> deletePatternElems pattern name)
-
-    createPatternElems :: String -> String -> IOSArrow XmlTree XmlTree
-    createPatternElems pattern name
-        = ( ( (listA (getElems pattern name >>> getRngAttrCombine))
-              >>>
-              checkPatternCombine pattern name
-            )
-            -- After determining this unique value, the combine attributes are removed.
-            &&&
-            (listA (getElems pattern name >>> removeAttr "combine")))
-          >>> -- ((errorCode::Int,errorMessage::String), result::XmlTrees)
-          choiceA
-          [ isA (\ ((code,_) , _)   -> code == 0)
-            :->
-            (mkRelaxError "" $< arr (snd . fst))
-          , isA (\ ((code,str) , _) -> code == 1 && str == "")
-            :->
-            arrL snd
-          , isA (\ ((code,str) , _) -> code == 1 && str /= "")
-            :->
-            ( createPatternElem pattern name $<<
-              ( arr (snd . fst) &&& (arr snd) )
-            )
-          , this
-            :->
-            ( mkRelaxError ""
-              ( "Can't create Pattern: " ++ show pattern ++
-                " with name " ++ show name ++ " in createPatternElems"
-              )
-            )
-          ]
-
-    createPatternElem :: (ArrowXml a) => String -> String -> String -> XmlTrees -> a n XmlTree
-    createPatternElem pattern name combine trees
-        = mkRngElement pattern (mkAttr (mkName "name") (txt name))
-          ( ( mkRngElement combine none
-              (arrL (const trees) >>> getChildren)
-            )
-            >>>
-            wrapPattern2Two combine
-          )
-
-    checkPatternCombine :: (ArrowXml a) => String -> String -> a [String] (Int, String)
-    checkPatternCombine pattern name
-        = choiceA
-          [ -- just one pattern with that name -> ok, no combine is needed
-            (isA (\ cl -> length cl == 1))
-            :->
-            constA (1, "")
-          , (isA (\ cl -> (length $ elemIndices "" cl) > 1))
-            :->
-            constA ( 0
-                   , "More than one " ++ pattern ++ "-Pattern: " ++ show name ++
-                     " without an combine-attribute in the same grammar"
-                   )
-          , (isA (\ cl -> (length $ nub $ deleteBy (==) "" cl) > 1))
-            :->
-            arr (\ cl -> ( 0
-                         , "Different combine-Attributes: " ++
-                           (formatStringListQuot $ noDoubles cl) ++
-                           " for the " ++ pattern ++ "-Pattern " ++
-                           show name ++ " in the same grammar"
-                         )
-                )
-          , -- ok -> combine value is returned
-            this
-            :->
-            arr (\ cl -> (1, fromJust $ find (/= "") cl))
-          ]
-
-    isElemWithNameValue :: (ArrowXml a) => String -> String -> a XmlTree XmlTree
-    isElemWithNameValue ename nvalue
-        = ( isElem
-            >>>
-            hasRngName ename
-            >>>
-            getRngAttrName
-            >>>
-            isA (== nvalue)
-          )
-          `guards` this
-
-    getElems :: (ArrowXml a) => String -> String -> a XmlTree XmlTree
-    getElems pattern name
-        = getChildren
-          >>>
-          choiceA
-          [ isElemWithNameValue pattern name
-            :->
-            (this <+> getElems pattern name)
-          , isRngGrammar
-            :-> none
-          , this
-            :->
-            getElems pattern name
-          ]
-
-    deletePatternElems :: (ArrowXml a) => String -> String -> a XmlTree XmlTree
-    deletePatternElems pattern name
-        = choiceA
-          [ isElemWithNameValue pattern name
-            :->
-            none
-          , isRngGrammar
-            :-> this
-          , this
-            :->
-            processChildren ( deletePatternElems pattern name )
-          ]
-
-
--- ------------------------------------------------------------
-
-
-{-
-- 4.19. define and ref elements
-    - Remove any define element that is not reachable.
-    - Now, for each element element that is not the child of a define element,
-      add a define element to the grammar element,
-      and replace the element element by a ref element referring
-      to the added define element.
-    - For each ref element that is expandable and is a descendant
-      of a start element or an element element, expand it by replacing
-      the ref element by the child of the define element to which it refers
-    - This must not result in a loop.
-    - Remove any define element whose child is not an element element.
--}
-simplificationStep6 :: IOSArrow XmlTree XmlTree
-simplificationStep6 =
-  ( -- Remove any define element that is not reachable.
-    (removeUnreachableDefines $<<< getAllDeepDefines
-                                   &&&
-                                   constA []
-                                   &&&
-                                   getRefsFromStartPattern
-    )
-    >>>
-    -- for each element element that is not the child of a define element,
-    -- add a define element to the grammar element,
-    ( processElements False
-      >>>
-      processChildren (insertChildrenAt 1 (getParam "elementTable"))
-    )
-    >>>
-    -- For each ref element that is expandable...
-    -- Remove any define element whose child is not an element element
-    (replaceExpandableRefs [] $< getExpandableDefines >>> deleteExpandableDefines)
-  ) `when` collectErrors
-  where
-  replaceExpandableRefs :: RefList -> Env -> IOSArrow XmlTree XmlTree
-  replaceExpandableRefs foundNames defTable
-    = choiceA [
-        isRngRef
-             :-> (ifA ( getRngAttrName
-                        >>>
-                        isA (\name -> elem name (map fst foundNames))
-                      )
-                    -- we have found a loop if the name is in the list
-                    (mkRelaxError "" $< ( getAttrValue defineOrigName
-                                          >>>
-                                          arr (\ n -> ( "Recursion in ref-Pattern: " ++
-                                                        formatStringListArr (reverse $ (n:) $ map snd foundNames)
-                                                      )
-                                              )
-                                        )
-                    )
-                    (replaceRef $<< getRngAttrName &&& getAttrValue defineOrigName)
-                 ),
-        this :-> (processChildren $ replaceExpandableRefs foundNames defTable)
-      ]
-    where
-    replaceRef :: NewName -> OldName -> IOSArrow XmlTree XmlTree
-    replaceRef name oldname
-      = ( constA (fromJust $ lookup name defTable)
-          >>>
-          getChildren
-          >>>
-          replaceExpandableRefs ((name,oldname):foundNames) defTable
-        )
-        `whenP`
-        (const $ elem name $ map fst defTable)
-
-
-  processElements :: Bool -> IOSArrow XmlTree XmlTree
-  processElements parentIsDefine
-    = processChildren
-      ( choiceA
-        [ isRngElement
-          :-> ( ifP (const parentIsDefine)
-                (processElements False)
-                ( processElements' $<< ( getAndSetCounter "define_id"
-                                         &&&
-                                         getDefineName
-                                       )
-                )
-              )
-        , isRngDefine
-          :-> processElements True
-        , this
-          :-> processElements False
-        ])
-    where
-    getDefineName :: IOSArrow XmlTree String
-    getDefineName
-        = firstChild
-          >>>
-          fromLA createNameClass
-          >>>
-          arr show
-
-    processElements' :: NewName -> OldName -> IOSArrow XmlTree XmlTree
-    processElements' name oldname
-      = storeElement name oldname
-        >>>
-        mkRngRef (createAttr name oldname) none
-
-    storeElement :: NewName -> OldName -> IOSArrow XmlTree XmlTree
-    storeElement name oldname
-      = perform $
-          ( mkRngDefine
-             (createAttr name oldname) (processElements False)
-          )
-          &&&
-          (listA $ getParam "elementTable")
-          >>>
-          arr2 (:)
-          >>>
-          setParamList "elementTable"
-
-    createAttr :: NewName -> OldName -> IOSArrow XmlTree XmlTree
-    createAttr name oldname
-      = mkAttr (mkName "name") (txt name)
-        <+>
-        mkAttr (mkName defineOrigName) (txt $ "created for element " ++ oldname)
-
-  getExpandableDefines :: (ArrowXml a) => a XmlTree Env
-  getExpandableDefines
-    = listA $ (multi ( ( isRngDefine
-                         >>>
-                         getChildren
-                         >>>
-                         neg isRngElement
-                       )
-                       `guards`
-                       this
-                     )
-              )
-              >>>
-              (getRngAttrName &&& this)
-
-  deleteExpandableDefines :: (ArrowXml a) => a XmlTree XmlTree
-  deleteExpandableDefines
-    = processTopDown $ none
-                       `when`
-                       ( isRngDefine
-                         >>>
-                         getChildren
-                         >>>
-                         neg isRngElement
-                       )
-
-
--- ------------------------------------------------------------
-
-
-{-
-- 4.20. notAllowed element
-    - An attribute, list, group, interleave, or oneOrMore element that has
-      a notAllowed child element is transformed into a notAllowed element.
-    - A choice element that has two notAllowed child elements
-      is transformed into a notAllowed element
-    - A choice element that has one notAllowed child element
-      is transformed into its other child element.
-    - An except element that has a notAllowed child element is removed.
-    - The preceding transformations are applied repeatedly
-      until none of them is applicable any more.
-    - Any define element that is no longer reachable is removed.
-- 4.21. empty element
-    - A group, interleave or choice element that has two empty child
-      elements is transformed into an empty element.
-    - A group or interleave element that has one empty child element
-      is transformed into its other child element.
-    - A choice element whose second child element is an empty element
-      is transformed by interchanging its two child elements.
-    - A oneOrMore element that has an empty child element
-      is transformed into an empty element.
-    - The preceding transformations are applied repeatedly
-      until none of them is applicable any more.
--}
-
-simplificationStep7 :: IOSArrow XmlTree XmlTree
-simplificationStep7
-    = ( markTreeChanged 0                               -- 0 = no changes, 1 = changes performed
-        >>>
-        processTopDownWithAttrl
-        ( ( -- An attribute, list, group, interleave, or oneOrMore element that has a
-            -- notAllowed child element is transformed into a notAllowed element.
-            ( ( mkRngNotAllowed none none
-                >>>
-                markTreeChanged 1
-              )
-              `whenNot`                                 -- keep all errors
-              (deep isRngRelaxError)
-            )
-            `when`
-            ( isAttributeListGroupInterleaveOneOrMore
-              >>>
-              getChildren
-              >>>
-              isRngNotAllowed
-            )
-          )
-          >>>
-          ( -- A choice element that has two notAllowed child elements is
-            -- transformed into a notAllowed element
-            ( mkRngNotAllowed none none
-              >>>
-              markTreeChanged 1
-            )
-            `when`
-            ( isRngChoice
-              >>>
-              listA (getChildren >>> isRngNotAllowed)
-              >>>
-              isA (\s -> length s == 2)
-            )
-          )
-          >>>
-          ( -- A choice element that has one notAllowed child element is
-            -- transformed into its other child element.
-            ( getChildren >>> neg isRngNotAllowed
-              >>>
-              markTreeChanged 1
-            )
-            `when`
-            ( isRngChoice >>> getChildren >>> isRngNotAllowed )
-          )
-          >>>
-          ( -- An except element that has a notAllowed child element is removed.
-            ( ( markTreeChanged 1
-                >>>
-                none
-              )
-              `whenNot`                  -- keep all errors
-              deep isRngRelaxError
-            )
-            `when`
-            ( isRngExcept >>> getChildren >>> isRngNotAllowed )
-          )
-          >>> -- transforming the empty pattern (4.21)
-          ( -- A group, interleave or choice element that has two empty child elements
-            -- is transformed into an empty element.
-            ( mkRngEmpty none
-              >>>
-              markTreeChanged 1
-            )
-            `when`
-            ( isChoiceGroupInterleave
-              >>>
-              listA (getChildren >>> isRngEmpty)
-              >>>
-              isA (\s -> length s == 2)
-            )
-          )
-          >>>
-          ( -- A group or interleave element that has one empty child element
-            -- is transformed into its other child element.
-            ( getChildren
-              >>>
-              neg isRngEmpty
-              >>>
-              markTreeChanged 1
-            )
-            `when`
-            ( isGroupInterleave >>> getChildren >>> isRngEmpty )
-          )
-          >>>
-          ( -- A choice element whose second child element is an empty element is transformed
-            -- by interchanging its two child elements.
-            changeChoiceChildren
-            `when`
-            ( isRngChoice >>> getChildren >>> isRngEmpty )
-          )
-          >>>
-          ( -- A oneOrMore element that has an empty child element
-            -- is transformed into an empty element.
-            ( mkRngEmpty none
-              >>>
-              markTreeChanged 1
-            )
-            `when`
-            ( isRngOneOrMore >>> getChildren >>> isRngEmpty )
-          )
-        )
-        >>>
-        -- The preceding transformations are applied repeatedly
-        -- until none of them is applicable any more.
-        ( simplificationStep7
-          `when`
-          hasTreeChanged
-        )
-      ) `when` collectErrors
-    where
-    changeChoiceChildren :: IOSArrow XmlTree XmlTree
-    changeChoiceChildren
-        = ( ( replaceChildren
-              ( mkRngEmpty none
-                <+>
-                (getChildren >>> neg isRngEmpty)
-              )
-              >>>
-              markTreeChanged 1
-            )
-            `when`
-            ( single (getChildren >>> isElem)           -- first child not "empty" elem
-              >>>
-              neg isRngEmpty
-            )
-          )
-
-hasTreeChanged  :: IOSArrow b Int
-hasTreeChanged
-    = getParamInt 0 "rng:changeTree"
-      >>>
-      isA (== 1)
-
-markTreeChanged :: Int -> IOSArrow b b
-markTreeChanged i
-    = perform (setParamInt "rng:changeTree" i)
-
--- ------------------------------------------------------------
-
-
-simplificationStep8 :: IOSArrow XmlTree XmlTree
-simplificationStep8                     -- Remove any define element that is not reachable.
-    = ( ( removeUnreachableDefines $<<<
-          ( getAllDeepDefines
-            &&&
-            constA []
-            &&&
-            getRefsFromStartPattern
-          )
-        )
-        `when` collectErrors
-      )
-
-
--- ------------------------------------------------------------
-
-
-restrictionsStep2 :: IOSArrow XmlTree XmlTree
-restrictionsStep2 =
-  processTopDown (
-    choiceA [
--- 7.1.1. attribute pattern, the following paths are prohibited:
---        attribute//(ref | attribute)
-      isRngAttribute :->
-        ( ( deep isRngRelaxError
-            <+>
-            ( mkRelaxError $<< (getChangesAttr
-                                &&&
-                                ( listA ( getChildren
-                                          >>>
-                                          deep isAttributeRef
-                                          >>>
-                                          (getName &&& getChangesAttr >>> arr2 (++))
-                                        )
-                                  >>>
-                                  arr (\n -> formatStringListPatt n ++
-                                             "Pattern not allowed as descendent(s)" ++
-                                             " of a attribute-Pattern"
-                                      )
-                                )
-                               )
-            )
-          )
-          `when`
-          ( getChildren >>> deep isAttributeRef )
-        ),
-
--- 7.1.2. oneOrMore pattern, the following paths are prohibited:
---        oneOrMore//(group | interleave)//attribute
-      isRngOneOrMore :->
-        ( ( deep isRngRelaxError
-            <+>
-            ( mkRelaxError $<< (getChangesAttr
-                                &&&
-                                ( listA ( getChildren
-                                          >>>
-                                          deep isGroupInterleave
-                                          >>>
-                                          (getName &&& getChangesAttr >>> arr2 (++))
-                                        )
-                                  &&&
-                                  getChangesAttr
-                                  >>>
-                                  arr2 (\ n c -> ( formatStringListPatt n ++
-                                                   "Pattern not allowed as descendent(s) " ++
-                                                   "of a oneOrMore-Pattern" ++
-                                                   (if null c then "" else " " ++ show c) ++
-                                                   " followed by an attribute descendent"
-                                                 )
-                                       )
-                                )
-                               )
-            )
-          )
-          `when`
-          ( getChildren >>> deep isGroupInterleave
-            >>>
-            getChildren >>> deep isRngAttribute
-          )
-        ),
-
--- 7.1.3. list pattern, the following paths are prohibited:
---        list//( list | ref | attribute | text | interleave)
-      isRngList :->
-        ( ( deep isRngRelaxError
-            <+>
-            ( mkRelaxError $<< (getChangesAttr
-                                &&&
-                                ( listA ( getChildren
-                                          >>>
-                                          deep isAttributeRefTextListInterleave
-                                          >>>
-                                          (getName &&& getChangesAttr >>> arr2 (++))
-                                        )
-                                  >>>
-                                  arr (\n -> formatStringListPatt n ++
-                                             "Pattern not allowed as descendent(s) of a list-Pattern")
-                                )
-                               )
-            )
-          )
-          `when`
-          ( getChildren
-            >>>
-            deep isAttributeRefTextListInterleave
-          )
-        ),
-
--- 7.1.4. except in data pattern, the following paths are prohibited:
---        data/except//(attribute | ref | text | list | group | interleave | oneOrMore | empty)
-      isRngData :->
-        ( ( deep isRngRelaxError
-            <+>
-            ( mkRelaxError $<< (getChangesAttr
-                                &&&
-                                ( listA (getChildren
-                                         >>>
-                                         deep isAttributeRefTextListGroupInterleaveOneOrMoreEmpty
-                                         >>>
-                                         (getName &&& getChangesAttr >>> arr2 (++))
-                                        )
-                                  >>>
-                                  arr (\n -> formatStringListPatt n ++
-                                             "Pattern not allowed as descendent(s) of a data/except-Pattern")
-                                )
-                               )
-            )
-          )
-          `when`
-          ( getChildren
-            >>>
-            isRngExcept
-            >>>
-            deep isAttributeRefTextListGroupInterleaveOneOrMoreEmpty
-          )
-        ),
-
--- 7.1.5. start element, the following paths are prohibited:
---        start//(attribute | data | value | text | list | group | interleave | oneOrMore | empty)
-      isRngStart :->
-        ( ( deep isRngRelaxError
-            <+>
-            ( mkRelaxError $<< (getChangesAttr
-                                &&&
-                                ( listA (getChildren
-                                         >>>
-                                         deep (checkElemName [ "attribute", "data", "value", "text", "list",
-                                                               "group", "interleave", "oneOrMore", "empty"])
-                                         >>>
-                                         (getName &&& getChangesAttr >>> arr2 (++))
-                                        )
-                                  >>>
-                                  arr (\n -> formatStringListPatt n ++
-                                             "Pattern not allowed as descendent(s) of a start-Pattern")
-                                )
-                               )
-            )
-          )
-          `when`
-          ( getChildren
-            >>>
-            deep (checkElemName [ "attribute", "data", "value", "text", "list",
-                                  "group", "interleave", "oneOrMore", "empty"])
-          )
-        ),
-
-        this :-> this
-      ]
-  ) `when` collectErrors
-
-
--- ------------------------------------------------------------
-
-
-restrictionsStep3 :: IOSArrow XmlTree XmlTree
-restrictionsStep3
-    = processTopDown
-      ( ( deep isRngRelaxError
-          <+>
-          ( mkRelaxError "" $<
-            ( -- getRngAttrName
-              ( getChildren >>> isRngName >>> getChildren >>> getText )
-              >>>
-              arr (\ n -> ( "Content of element " ++ show n ++ " contains a pattern that can match " ++
-                            "a child and a pattern that matches a single string"
-                          )
-                  )
-            )
-          )
-        )
-        `when`
-        ( isRngElement
-          >>>
-          ( getChildren >>. (take 1 . reverse) )
-          >>>
-          getContentType >>> isA (== CTNone)
-        )
-      ) `when` collectErrors
-
-
-
-getContentType :: IOSArrow XmlTree ContentType
-getContentType
-    = choiceA
-      [ isRngValue      :-> (constA CTSimple)
-      , isRngData       :-> processData
-      , isRngList       :-> (constA CTSimple)
-      , isRngText       :-> (constA CTComplex)
-      , isRngRef        :-> (constA CTComplex)
-      , isRngEmpty      :-> (constA CTEmpty)
-      , isRngAttribute  :-> processAttribute
-      , isRngGroup      :-> processGroup
-      , isRngInterleave :-> processInterleave
-      , isRngOneOrMore  :-> processOneOrMore
-      , isRngChoice     :-> processChoice
-      ]
-    where
-    processData :: IOSArrow XmlTree ContentType
-    processData
-        = ifA (neg (getChildren >>> isRngExcept))
-          (constA CTSimple)
-          ( getChildren
-            >>>
-            isRngExcept
-            >>>
-            getChildren
-            >>>
-            getContentType
-            >>>
-            ifP (/= CTNone) (constA CTSimple) (constA CTNone)
-          )
-    processAttribute :: IOSArrow XmlTree ContentType
-    processAttribute
-        = ifA ( lastChild
-                >>>
-                getContentType
-                >>>
-                isA (/= CTNone)
-              )
-          (constA CTEmpty)
-          (constA CTNone)
-
-    processGroup :: IOSArrow XmlTree ContentType
-    processGroup
-        = get2ContentTypes
-          >>>
-          arr2 (\a b -> if isGroupable a b then max a b else CTNone)
-
-    processInterleave :: IOSArrow XmlTree ContentType
-    processInterleave
-        = get2ContentTypes
-          >>>
-          arr2 (\a b -> if isGroupable a b then max a b else CTNone)
-
-    processOneOrMore :: IOSArrow XmlTree ContentType
-    processOneOrMore
-        = ifA ( getChildren
-                >>>
-                getContentType >>> isA (/= CTNone)
-                >>>
-                isA (\t -> isGroupable t t)
-              )
-          ( getChildren >>> getContentType )
-          ( constA CTNone )
-
-    processChoice :: IOSArrow XmlTree ContentType
-    processChoice
-        = get2ContentTypes
-          >>>
-          arr2 max
-
-    isGroupable :: ContentType -> ContentType -> Bool
-    isGroupable CTEmpty   _         = True
-    isGroupable _         CTEmpty   = True
-    isGroupable CTComplex CTComplex = True
-    isGroupable _         _         = False
-
-
-checkPattern :: IOSArrow (XmlTree, ([NameClass], [NameClass])) XmlTree
-checkPattern
-    = (\ (_, (a, b)) -> isIn a b) `guardsP` (arr fst)
-    where
-    isIn :: [NameClass] -> [NameClass] -> Bool
-    isIn _ []      = False
-    isIn [] _      = False
-    isIn (x:xs) ys = (any (overlap x) ys) || isIn xs ys
-
-
-occur :: String -> IOSArrow XmlTree XmlTree -> IOSArrow XmlTree XmlTree
-occur name fct
-    = choiceA
-      [ ( isElem >>> hasRngName name )
-        :->
-        fct
-      , isChoiceGroupInterleaveOneOrMore
-        :->
-        (getChildren >>> occur name fct)
-      ]
-
-get2ContentTypes :: IOSArrow XmlTree (ContentType, ContentType)
-get2ContentTypes
-    = ( ( firstChild >>> getContentType )
-        &&&
-        ( lastChild  >>> getContentType )
-      )
-
--- ------------------------------------------------------------
-
-
--- Duplicate attributes are not allowed. -> fertig
--- Attributes using infinite name classes must be repeated; an attribute element that
--- has an anyName or nsName descendant element must have a oneOrMore ancestor element. -> fertig
-
--- berechnet alle define-Namen (fuer ref-Pattern) und Nameclasses der element-Pattern
-
-restrictionsStep4 :: IOSArrow XmlTree XmlTree
-restrictionsStep4
-    = ( restrictionsStep4' $<
-        listA ( deep isRngDefine                                -- get all defines
-                >>>
-                ( getRngAttrName                                -- get define name
-                  &&&
-                  ( single ( getChildren
-                             >>>
-                             getChildren
-                             >>>
-                             fromLA createNameClass             -- compute the name class from 1. grandchild
-                           )
-                    `orElse`
-                    (constA AnyName)
-                  )
-                )
-              )
-      ) `when` collectErrors
-
-restrictionsStep4' :: [(String, NameClass)] -> IOSArrow XmlTree XmlTree
-restrictionsStep4' nc =
-  processTopDown (
-    (
-      ( deep isRngRelaxError
-        <+>
-        ( mkRelaxError "" $<
-          ( getRngAttrName
-            >>>
-            arr (\ n -> ( "Both attribute-pattern occuring in an " ++
-                          show n ++ " belong to the same name-class"
-                        )
-                )
-          )
-        )
-      )
-      `when`
-      ( (isRngGroup `orElse` isRngInterleave)
-        >>>
-        ( getChildren
-          &&&
-          ( firstChild
-            >>>
-            listA ( occur "attribute" (single getChildren)
-                    >>>
-                    fromLA createNameClass
-                  )
-          )
-          &&&
-          ( lastChild
-            >>>
-            listA ( occur "attribute" (single getChildren)
-                    >>>
-                    fromLA createNameClass
-                  )
-          )
-        )
-        >>> checkPattern
-      )
-    )
-    >>>
-    (
-      ( deep isRngRelaxError
-        <+>
-        ( mkRelaxError ""
-          ( "An attribute that has an anyName or nsName descendant element " ++
-            "must have a oneOrMore ancestor element"
-          )
-        )
-      )
-      `when`
-      (isRngElement >>> checkInfiniteAttribute)
-    )
-    >>>
-    ( ( deep isRngRelaxError
-        <+>
-        ( mkRelaxError ""
-          ( "Both element-pattern occuring in an interleave " ++
-            "belong to the same name-class"
-          )
-        )
-      )
-      `when`
-      ( isRngInterleave
-        >>>
-        ( getChildren
-          &&&
-          (firstChild >>> listA (occur "ref" this >>> getRngAttrName))
-          &&&
-          (lastChild  >>> listA (occur "ref" this >>> getRngAttrName))
-        )
-        >>>
-        checkNames
-      )
-    )
-    >>>
-    ( ( deep isRngRelaxError
-        <+>
-        ( mkRelaxError "" "A text pattern must not occur in both children of an interleave" )
-      )
-      `when`
-      (isRngInterleave >>> checkText)
-    )
-  )
-  where
-  checkInfiniteAttribute :: IOSArrow XmlTree XmlTree
-  checkInfiniteAttribute
-    = getChildren
-      >>>
-      choiceA
-      [ isRngOneOrMore :-> none
-      , ( isRngAttribute
-          >>>
-          deep (isRngAnyName `orElse` isRngNsName)
-        ) :-> this
-      , this :-> checkInfiniteAttribute
-      ]
-
-  checkNames :: IOSArrow (XmlTree, ([String], [String])) XmlTree
-  checkNames = (arr fst)
-               &&&
-               (arr (\(_, (a, _)) -> getNameClasses nc a))
-               &&&
-               (arr (\(_, (_, b)) -> getNameClasses nc b))
-               >>>
-               checkPattern
-    where
-    getNameClasses :: [(String, NameClass)] -> [String] -> [NameClass]
-    getNameClasses nc' l = map (\x -> fromJust $ lookup x nc') l
-
-  checkText :: IOSArrow XmlTree XmlTree
-  checkText
-      = ( firstChild >>> occur "text" this )
-        `guards`
-        ( lastChild  >>> occur "text" this )
-
--- ------------------------------------------------------------
-
-
-overlap         :: NameClass -> NameClass -> Bool
-overlap nc1 nc2
-    = any (bothContain nc1 nc2) (representatives nc1 ++ representatives nc2)
-
-bothContain     :: NameClass -> NameClass -> QName -> Bool
-bothContain nc1 nc2 qn
-    = contains nc1 qn && contains nc2 qn
-
-illegalLocalName        :: LocalName
-illegalLocalName        = ""
-
-illegalUri              :: Uri
-illegalUri              = "\x1"
-
-representatives         :: NameClass -> [QName]
-representatives AnyName
-    = [mkQName "" illegalLocalName illegalUri]
-
-representatives (AnyNameExcept nc)
-    = (mkQName "" illegalLocalName illegalUri) : (representatives nc)
-
-representatives (NsName ns)
-    = [mkQName "" illegalLocalName ns]
-
-representatives (NsNameExcept ns nc)
-    = (mkQName "" illegalLocalName ns) : (representatives nc)
-
-representatives (Name ns ln)
-    = [mkQName "" ln ns]
-
-representatives (NameClassChoice nc1 nc2)
-    = (representatives nc1) ++ (representatives nc2)
-
-representatives _
-    = []
-
--- -------------------------------------------------------------------------------------------------------
-resetStates :: IOSArrow XmlTree XmlTree
-resetStates
-    = ( perform (constA $ setParamInt "define_id" 0)
-        >>>
-        perform (constA [] >>> setParamList "elementTable" )
-        >>>
-        perform (constA $ setParamInt a_numberOfErrors 0)
-      )
-
-
-getAllDeepDefines :: IOSArrow XmlTree Env
-getAllDeepDefines
-    = listA $ deep isRngDefine
-      >>>
-      ( getRngAttrName &&& this )
-
-
--- | Return all reachable defines from the start pattern
-
-getRefsFromStartPattern :: IOSArrow XmlTree [String]
-getRefsFromStartPattern
-  = listA
-    ( getChildren
-      >>>
-      isRngGrammar
-      >>>
-      getChildren
-      >>>
-      isRngStart
-      >>>
-      deep isRngRef
-      >>>
-      getRngAttrName
-    )
-
-removeUnreachableDefines :: Env -> [String] -> [String] -> IOSArrow XmlTree XmlTree
-removeUnreachableDefines allDefs processedDefs reachableDefs
-    = ifP (const $ unprocessedDefs /= [])
-      ( removeUnreachableDefines allDefs (nextTreeName : processedDefs) $< newReachableDefs )
-      ( processChildren $ -- root node
-        processChildren $ -- first grammar
-        ( none
-          `when`
-          ( isRngDefine
-            >>>
-            getRngAttrName
-            >>>
-            isA (\n -> not $ elem n reachableDefs)
-          )
-        )
-      )
-    where
-    unprocessedDefs :: [String]
-    unprocessedDefs
-        = reachableDefs \\ processedDefs
-
-    newReachableDefs :: IOSArrow n [String]
-    newReachableDefs
-        = constA getTree
-          >>>
-          listA ( deep isRngRef
-                  >>>
-                  getRngAttrName
-                )
-          >>>
-          arr (noDoubles . (reachableDefs ++))
-
-    getTree :: XmlTree
-    getTree
-        = fromJust $ lookup nextTreeName allDefs
-
-    nextTreeName :: String
-    nextTreeName
-        = head unprocessedDefs
-
-
--- -------------------------------------------------------------------------------------------------------
-
-
-checkElemName :: [String] -> IOSArrow XmlTree XmlTree
-checkElemName l
-    = ( isElem >>> getLocalPart >>> isA (\s -> elem s l) )
-      `guards`
-      this
-
-wrapPattern2Two :: (ArrowXml a) => String -> a XmlTree XmlTree
-wrapPattern2Two name
-  = choiceA
-    [ noOfChildren (> 2)
-      :-> ( replaceChildren ( (mkRngElement name none
-                               (getChildren >>. take 2)
-                              )
-                              <+>
-                              (getChildren >>. drop 2)
-                            )
-            >>>
-            wrapPattern2Two name
-          )
-    , noOfChildren (== 1)
-      :-> getChildren
-    , this
-      :-> this
-    ]
-
-mkRelaxError :: String -> String -> IOSArrow n XmlTree
-mkRelaxError changesStr errStr
-  = perform (getAndSetCounter a_numberOfErrors)
-    >>>
-    mkRngRelaxError none none
-    >>>
-    addAttr "desc" errStr
-    >>>
-    ( addAttr "changes" changesStr
-      `whenP`
-      (const $ changesStr /= "")
-    )
-
-collectErrors :: IOSArrow XmlTree XmlTree
-collectErrors
-  = none
-    `when`
-    ( stopAfterFirstError
-      >>>
-      getParamInt 0 a_numberOfErrors >>> isA (>0)
-    )
-  where
-  stopAfterFirstError = getParamString a_do_not_collect_errors
-                        >>>
-                        isA (== "1")
-
-
--- | Returns the list of simplification errors or 'none'
-getErrors :: IOSArrow XmlTree XmlTree
-getErrors = (getParamInt 0 a_numberOfErrors >>> isA (>0))
-            `guards`
-            (root [] [multi isRngRelaxError])
-
-setChangesAttr :: String -> IOSArrow XmlTree XmlTree
-setChangesAttr str
-  = ifA (hasAttr a_relaxSimplificationChanges)
-      ( processAttrl $
-          changeAttrValue (++ (", " ++ str))
-          `when`
-          (hasRngName a_relaxSimplificationChanges)
-      )
-      (mkAttr (mkName a_relaxSimplificationChanges) (txt str))
-
-
-getChangesAttr :: IOSArrow XmlTree String
-getChangesAttr
-  = getAttrValue a_relaxSimplificationChanges
-    &&&
-    getParamString a_output_changes
-    >>>
-    ifP (\(changes, param) -> changes /= "" && param == "1")
-      (arr2 $ \l _ -> " (" ++ l ++ ")")
-      (constA "")
-
-
-getAndSetCounter :: String -> IOSArrow b String
-getAndSetCounter name
-  = genNewId $< getParamInt 0 name
-  where
-  genNewId :: Int -> IOSArrow b String
-  genNewId i = setParamInt name (i+1) >>> constA (show i)
-
-
--- -------------------------------------------------------------------------------------------------------
-
--- | Creates the simple form of a Relax NG schema
--- (see also: 'relaxOptions')
-
-createSimpleForm :: Attributes -> Bool -> Bool -> Bool -> IOSArrow XmlTree XmlTree
-createSimpleForm remainingOptions checkRestrictions validateExternalRef validateInclude
-    = traceMsg 2 ("createSimpleForm: " ++ show (remainingOptions, checkRestrictions,validateExternalRef, validateInclude))
-      >>>
-      ( if checkRestrictions
-        then createSimpleWithRest
-        else createSimpleWithoutRest
-      )
-    where
-
-    createSimpleWithRest :: IOSArrow XmlTree XmlTree
-    createSimpleWithRest
-        = seqA $ concat [ simplificationPart1
-                        , return $ traceDoc "relax NG: simplificationPart1 done"
-                        , restrictionsPart1
-                        , return $ traceDoc "relax NG: restrictionsPart1 done"
-                        , simplificationPart2
-                        , return $ traceDoc "relax NG simplificationPart2 done"
-                        , restrictionsPart2
-                        , return $ traceDoc "relax NG: restrictionsPart2 done"
-                        , finalCleanUp
-                        , return $ traceDoc "relax NG: finalCleanUp done"
-                        ]
-
-    createSimpleWithoutRest :: IOSArrow XmlTree XmlTree
-    createSimpleWithoutRest
-        = seqA $ concat [ simplificationPart1
-                        , simplificationPart2
-                        , finalCleanUp
-                        ]
-    simplificationPart1 :: [IOSArrow XmlTree XmlTree]
-    simplificationPart1
-        = [ propagateNamespaces
-          , simplificationStep1
-          , simplificationStep2 remainingOptions validateExternalRef validateInclude [] []
-          , simplificationStep3
-          , simplificationStep4
-          ]
-
-    simplificationPart2 :: [IOSArrow XmlTree XmlTree]
-    simplificationPart2
-        = [ simplificationStep5
-          , simplificationStep6
-          , simplificationStep7
-          , simplificationStep8
-          ]
-
-    restrictionsPart1 :: [IOSArrow XmlTree XmlTree]
-    restrictionsPart1
-        = [ restrictionsStep1 ]
-
-    restrictionsPart2 :: [IOSArrow XmlTree XmlTree]
-    restrictionsPart2
-        = [ restrictionsStep2
-          , restrictionsStep3
-          , restrictionsStep4
-          ]
-
-    finalCleanUp :: [IOSArrow XmlTree XmlTree]
-    finalCleanUp
-        = [ cleanUp
-          , resetStates
-          ]
-
-    cleanUp :: IOSArrow XmlTree XmlTree
-    cleanUp = processTopDown $
-              removeAttr a_relaxSimplificationChanges
-              >>>
-              removeAttr defineOrigName
-
--- -------------------------------------------------------------------------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/Unicode/Blocks.hs b/src/Text/XML/HXT/RelaxNG/Unicode/Blocks.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/Unicode/Blocks.hs
+++ /dev/null
@@ -1,229 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.Unicode.Blocks
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
-   Portability: portable
-   Version    : $Id$
-
-   Unicode Code Blocks
-
-   don't edit this module
-   it's generated from 'http:\/\/www.unicode.org\/Public\/UNIDATA\/Blocks.txt'
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.Unicode.Blocks
-  ( codeBlocks )
-where
-
--- ------------------------------------------------------------
-
-codeBlocks        :: [(String, (Char, Char))]
-codeBlocks =
-    [ ( "BasicLatin",   ( '\x0000', '\x007F') )
-    , ( "Latin-1Supplement",    ( '\x0080', '\x00FF') )
-    , ( "LatinExtended-A",      ( '\x0100', '\x017F') )
-    , ( "LatinExtended-B",      ( '\x0180', '\x024F') )
-    , ( "IPAExtensions",        ( '\x0250', '\x02AF') )
-    , ( "SpacingModifierLetters",       ( '\x02B0', '\x02FF') )
-    , ( "CombiningDiacriticalMarks",    ( '\x0300', '\x036F') )
-    , ( "GreekandCoptic",       ( '\x0370', '\x03FF') )
-    , ( "Cyrillic",     ( '\x0400', '\x04FF') )
-    , ( "CyrillicSupplement",   ( '\x0500', '\x052F') )
-    , ( "Armenian",     ( '\x0530', '\x058F') )
-    , ( "Hebrew",       ( '\x0590', '\x05FF') )
-    , ( "Arabic",       ( '\x0600', '\x06FF') )
-    , ( "Syriac",       ( '\x0700', '\x074F') )
-    , ( "ArabicSupplement",     ( '\x0750', '\x077F') )
-    , ( "Thaana",       ( '\x0780', '\x07BF') )
-    , ( "NKo",  ( '\x07C0', '\x07FF') )
-    , ( "Samaritan",    ( '\x0800', '\x083F') )
-    , ( "Devanagari",   ( '\x0900', '\x097F') )
-    , ( "Bengali",      ( '\x0980', '\x09FF') )
-    , ( "Gurmukhi",     ( '\x0A00', '\x0A7F') )
-    , ( "Gujarati",     ( '\x0A80', '\x0AFF') )
-    , ( "Oriya",        ( '\x0B00', '\x0B7F') )
-    , ( "Tamil",        ( '\x0B80', '\x0BFF') )
-    , ( "Telugu",       ( '\x0C00', '\x0C7F') )
-    , ( "Kannada",      ( '\x0C80', '\x0CFF') )
-    , ( "Malayalam",    ( '\x0D00', '\x0D7F') )
-    , ( "Sinhala",      ( '\x0D80', '\x0DFF') )
-    , ( "Thai", ( '\x0E00', '\x0E7F') )
-    , ( "Lao",  ( '\x0E80', '\x0EFF') )
-    , ( "Tibetan",      ( '\x0F00', '\x0FFF') )
-    , ( "Myanmar",      ( '\x1000', '\x109F') )
-    , ( "Georgian",     ( '\x10A0', '\x10FF') )
-    , ( "HangulJamo",   ( '\x1100', '\x11FF') )
-    , ( "Ethiopic",     ( '\x1200', '\x137F') )
-    , ( "EthiopicSupplement",   ( '\x1380', '\x139F') )
-    , ( "Cherokee",     ( '\x13A0', '\x13FF') )
-    , ( "UnifiedCanadianAboriginalSyllabics",   ( '\x1400', '\x167F') )
-    , ( "Ogham",        ( '\x1680', '\x169F') )
-    , ( "Runic",        ( '\x16A0', '\x16FF') )
-    , ( "Tagalog",      ( '\x1700', '\x171F') )
-    , ( "Hanunoo",      ( '\x1720', '\x173F') )
-    , ( "Buhid",        ( '\x1740', '\x175F') )
-    , ( "Tagbanwa",     ( '\x1760', '\x177F') )
-    , ( "Khmer",        ( '\x1780', '\x17FF') )
-    , ( "Mongolian",    ( '\x1800', '\x18AF') )
-    , ( "UnifiedCanadianAboriginalSyllabicsExtended",   ( '\x18B0', '\x18FF') )
-    , ( "Limbu",        ( '\x1900', '\x194F') )
-    , ( "TaiLe",        ( '\x1950', '\x197F') )
-    , ( "NewTaiLue",    ( '\x1980', '\x19DF') )
-    , ( "KhmerSymbols", ( '\x19E0', '\x19FF') )
-    , ( "Buginese",     ( '\x1A00', '\x1A1F') )
-    , ( "TaiTham",      ( '\x1A20', '\x1AAF') )
-    , ( "Balinese",     ( '\x1B00', '\x1B7F') )
-    , ( "Sundanese",    ( '\x1B80', '\x1BBF') )
-    , ( "Lepcha",       ( '\x1C00', '\x1C4F') )
-    , ( "OlChiki",      ( '\x1C50', '\x1C7F') )
-    , ( "VedicExtensions",      ( '\x1CD0', '\x1CFF') )
-    , ( "PhoneticExtensions",   ( '\x1D00', '\x1D7F') )
-    , ( "PhoneticExtensionsSupplement", ( '\x1D80', '\x1DBF') )
-    , ( "CombiningDiacriticalMarksSupplement",  ( '\x1DC0', '\x1DFF') )
-    , ( "LatinExtendedAdditional",      ( '\x1E00', '\x1EFF') )
-    , ( "GreekExtended",        ( '\x1F00', '\x1FFF') )
-    , ( "GeneralPunctuation",   ( '\x2000', '\x206F') )
-    , ( "SuperscriptsandSubscripts",    ( '\x2070', '\x209F') )
-    , ( "CurrencySymbols",      ( '\x20A0', '\x20CF') )
-    , ( "CombiningDiacriticalMarksforSymbols",  ( '\x20D0', '\x20FF') )
-    , ( "LetterlikeSymbols",    ( '\x2100', '\x214F') )
-    , ( "NumberForms",  ( '\x2150', '\x218F') )
-    , ( "Arrows",       ( '\x2190', '\x21FF') )
-    , ( "MathematicalOperators",        ( '\x2200', '\x22FF') )
-    , ( "MiscellaneousTechnical",       ( '\x2300', '\x23FF') )
-    , ( "ControlPictures",      ( '\x2400', '\x243F') )
-    , ( "OpticalCharacterRecognition",  ( '\x2440', '\x245F') )
-    , ( "EnclosedAlphanumerics",        ( '\x2460', '\x24FF') )
-    , ( "BoxDrawing",   ( '\x2500', '\x257F') )
-    , ( "BlockElements",        ( '\x2580', '\x259F') )
-    , ( "GeometricShapes",      ( '\x25A0', '\x25FF') )
-    , ( "MiscellaneousSymbols", ( '\x2600', '\x26FF') )
-    , ( "Dingbats",     ( '\x2700', '\x27BF') )
-    , ( "MiscellaneousMathematicalSymbols-A",   ( '\x27C0', '\x27EF') )
-    , ( "SupplementalArrows-A", ( '\x27F0', '\x27FF') )
-    , ( "BraillePatterns",      ( '\x2800', '\x28FF') )
-    , ( "SupplementalArrows-B", ( '\x2900', '\x297F') )
-    , ( "MiscellaneousMathematicalSymbols-B",   ( '\x2980', '\x29FF') )
-    , ( "SupplementalMathematicalOperators",    ( '\x2A00', '\x2AFF') )
-    , ( "MiscellaneousSymbolsandArrows",        ( '\x2B00', '\x2BFF') )
-    , ( "Glagolitic",   ( '\x2C00', '\x2C5F') )
-    , ( "LatinExtended-C",      ( '\x2C60', '\x2C7F') )
-    , ( "Coptic",       ( '\x2C80', '\x2CFF') )
-    , ( "GeorgianSupplement",   ( '\x2D00', '\x2D2F') )
-    , ( "Tifinagh",     ( '\x2D30', '\x2D7F') )
-    , ( "EthiopicExtended",     ( '\x2D80', '\x2DDF') )
-    , ( "CyrillicExtended-A",   ( '\x2DE0', '\x2DFF') )
-    , ( "SupplementalPunctuation",      ( '\x2E00', '\x2E7F') )
-    , ( "CJKRadicalsSupplement",        ( '\x2E80', '\x2EFF') )
-    , ( "KangxiRadicals",       ( '\x2F00', '\x2FDF') )
-    , ( "IdeographicDescriptionCharacters",     ( '\x2FF0', '\x2FFF') )
-    , ( "CJKSymbolsandPunctuation",     ( '\x3000', '\x303F') )
-    , ( "Hiragana",     ( '\x3040', '\x309F') )
-    , ( "Katakana",     ( '\x30A0', '\x30FF') )
-    , ( "Bopomofo",     ( '\x3100', '\x312F') )
-    , ( "HangulCompatibilityJamo",      ( '\x3130', '\x318F') )
-    , ( "Kanbun",       ( '\x3190', '\x319F') )
-    , ( "BopomofoExtended",     ( '\x31A0', '\x31BF') )
-    , ( "CJKStrokes",   ( '\x31C0', '\x31EF') )
-    , ( "KatakanaPhoneticExtensions",   ( '\x31F0', '\x31FF') )
-    , ( "EnclosedCJKLettersandMonths",  ( '\x3200', '\x32FF') )
-    , ( "CJKCompatibility",     ( '\x3300', '\x33FF') )
-    , ( "CJKUnifiedIdeographsExtensionA",       ( '\x3400', '\x4DBF') )
-    , ( "YijingHexagramSymbols",        ( '\x4DC0', '\x4DFF') )
-    , ( "CJKUnifiedIdeographs", ( '\x4E00', '\x9FFF') )
-    , ( "YiSyllables",  ( '\xA000', '\xA48F') )
-    , ( "YiRadicals",   ( '\xA490', '\xA4CF') )
-    , ( "Lisu", ( '\xA4D0', '\xA4FF') )
-    , ( "Vai",  ( '\xA500', '\xA63F') )
-    , ( "CyrillicExtended-B",   ( '\xA640', '\xA69F') )
-    , ( "Bamum",        ( '\xA6A0', '\xA6FF') )
-    , ( "ModifierToneLetters",  ( '\xA700', '\xA71F') )
-    , ( "LatinExtended-D",      ( '\xA720', '\xA7FF') )
-    , ( "SylotiNagri",  ( '\xA800', '\xA82F') )
-    , ( "CommonIndicNumberForms",       ( '\xA830', '\xA83F') )
-    , ( "Phags-pa",     ( '\xA840', '\xA87F') )
-    , ( "Saurashtra",   ( '\xA880', '\xA8DF') )
-    , ( "DevanagariExtended",   ( '\xA8E0', '\xA8FF') )
-    , ( "KayahLi",      ( '\xA900', '\xA92F') )
-    , ( "Rejang",       ( '\xA930', '\xA95F') )
-    , ( "HangulJamoExtended-A", ( '\xA960', '\xA97F') )
-    , ( "Javanese",     ( '\xA980', '\xA9DF') )
-    , ( "Cham", ( '\xAA00', '\xAA5F') )
-    , ( "MyanmarExtended-A",    ( '\xAA60', '\xAA7F') )
-    , ( "TaiViet",      ( '\xAA80', '\xAADF') )
-    , ( "MeeteiMayek",  ( '\xABC0', '\xABFF') )
-    , ( "HangulSyllables",      ( '\xAC00', '\xD7AF') )
-    , ( "HangulJamoExtended-B", ( '\xD7B0', '\xD7FF') )
-    , ( "HighSurrogates",       ( '\xD800', '\xDB7F') )
-    , ( "HighPrivateUseSurrogates",     ( '\xDB80', '\xDBFF') )
-    , ( "LowSurrogates",        ( '\xDC00', '\xDFFF') )
-    , ( "PrivateUseArea",       ( '\xE000', '\xF8FF') )
-    , ( "CJKCompatibilityIdeographs",   ( '\xF900', '\xFAFF') )
-    , ( "AlphabeticPresentationForms",  ( '\xFB00', '\xFB4F') )
-    , ( "ArabicPresentationForms-A",    ( '\xFB50', '\xFDFF') )
-    , ( "VariationSelectors",   ( '\xFE00', '\xFE0F') )
-    , ( "VerticalForms",        ( '\xFE10', '\xFE1F') )
-    , ( "CombiningHalfMarks",   ( '\xFE20', '\xFE2F') )
-    , ( "CJKCompatibilityForms",        ( '\xFE30', '\xFE4F') )
-    , ( "SmallFormVariants",    ( '\xFE50', '\xFE6F') )
-    , ( "ArabicPresentationForms-B",    ( '\xFE70', '\xFEFF') )
-    , ( "HalfwidthandFullwidthForms",   ( '\xFF00', '\xFFEF') )
-    , ( "Specials",     ( '\xFFF0', '\xFFFF') )
-    , ( "LinearBSyllabary",     ( '\x10000', '\x1007F') )
-    , ( "LinearBIdeograms",     ( '\x10080', '\x100FF') )
-    , ( "AegeanNumbers",        ( '\x10100', '\x1013F') )
-    , ( "AncientGreekNumbers",  ( '\x10140', '\x1018F') )
-    , ( "AncientSymbols",       ( '\x10190', '\x101CF') )
-    , ( "PhaistosDisc", ( '\x101D0', '\x101FF') )
-    , ( "Lycian",       ( '\x10280', '\x1029F') )
-    , ( "Carian",       ( '\x102A0', '\x102DF') )
-    , ( "OldItalic",    ( '\x10300', '\x1032F') )
-    , ( "Gothic",       ( '\x10330', '\x1034F') )
-    , ( "Ugaritic",     ( '\x10380', '\x1039F') )
-    , ( "OldPersian",   ( '\x103A0', '\x103DF') )
-    , ( "Deseret",      ( '\x10400', '\x1044F') )
-    , ( "Shavian",      ( '\x10450', '\x1047F') )
-    , ( "Osmanya",      ( '\x10480', '\x104AF') )
-    , ( "CypriotSyllabary",     ( '\x10800', '\x1083F') )
-    , ( "ImperialAramaic",      ( '\x10840', '\x1085F') )
-    , ( "Phoenician",   ( '\x10900', '\x1091F') )
-    , ( "Lydian",       ( '\x10920', '\x1093F') )
-    , ( "Kharoshthi",   ( '\x10A00', '\x10A5F') )
-    , ( "OldSouthArabian",      ( '\x10A60', '\x10A7F') )
-    , ( "Avestan",      ( '\x10B00', '\x10B3F') )
-    , ( "InscriptionalParthian",        ( '\x10B40', '\x10B5F') )
-    , ( "InscriptionalPahlavi", ( '\x10B60', '\x10B7F') )
-    , ( "OldTurkic",    ( '\x10C00', '\x10C4F') )
-    , ( "RumiNumeralSymbols",   ( '\x10E60', '\x10E7F') )
-    , ( "Kaithi",       ( '\x11080', '\x110CF') )
-    , ( "Cuneiform",    ( '\x12000', '\x123FF') )
-    , ( "CuneiformNumbersandPunctuation",       ( '\x12400', '\x1247F') )
-    , ( "EgyptianHieroglyphs",  ( '\x13000', '\x1342F') )
-    , ( "ByzantineMusicalSymbols",      ( '\x1D000', '\x1D0FF') )
-    , ( "MusicalSymbols",       ( '\x1D100', '\x1D1FF') )
-    , ( "AncientGreekMusicalNotation",  ( '\x1D200', '\x1D24F') )
-    , ( "TaiXuanJingSymbols",   ( '\x1D300', '\x1D35F') )
-    , ( "CountingRodNumerals",  ( '\x1D360', '\x1D37F') )
-    , ( "MathematicalAlphanumericSymbols",      ( '\x1D400', '\x1D7FF') )
-    , ( "MahjongTiles", ( '\x1F000', '\x1F02F') )
-    , ( "DominoTiles",  ( '\x1F030', '\x1F09F') )
-    , ( "EnclosedAlphanumericSupplement",       ( '\x1F100', '\x1F1FF') )
-    , ( "EnclosedIdeographicSupplement",        ( '\x1F200', '\x1F2FF') )
-    , ( "CJKUnifiedIdeographsExtensionB",       ( '\x20000', '\x2A6DF') )
-    , ( "CJKUnifiedIdeographsExtensionC",       ( '\x2A700', '\x2B73F') )
-    , ( "CJKCompatibilityIdeographsSupplement", ( '\x2F800', '\x2FA1F') )
-    , ( "Tags", ( '\xE0000', '\xE007F') )
-    , ( "VariationSelectorsSupplement", ( '\xE0100', '\xE01EF') )
-    , ( "SupplementaryPrivateUseArea-A",        ( '\xF0000', '\xFFFFF') )
-    , ( "SupplementaryPrivateUseArea-B",        ( '\x100000', '\x10FFFF') )
-    ]
-
--- ------------------------------------------------------------
-
diff --git a/src/Text/XML/HXT/RelaxNG/Unicode/CharProps.hs b/src/Text/XML/HXT/RelaxNG/Unicode/CharProps.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/Unicode/CharProps.hs
+++ /dev/null
@@ -1,3945 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.Unicode.CharProps
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
-   Portability: portable
-   Version    : $Id$
-
-   Unicode character properties
-
-   don't edit this module
-   it's generated from 'http:\/\/www.unicode.org\/Public\/UNIDATA\/UnicodeData.txt'
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.Unicode.CharProps
-  ( isUnicodeC
-  , isUnicodeCc
-  , isUnicodeCf
-  , isUnicodeCo
-  , isUnicodeCs
-  , isUnicodeL
-  , isUnicodeLl
-  , isUnicodeLm
-  , isUnicodeLo
-  , isUnicodeLt
-  , isUnicodeLu
-  , isUnicodeM
-  , isUnicodeMc
-  , isUnicodeMe
-  , isUnicodeMn
-  , isUnicodeN
-  , isUnicodeNd
-  , isUnicodeNl
-  , isUnicodeNo
-  , isUnicodeP
-  , isUnicodePc
-  , isUnicodePd
-  , isUnicodePe
-  , isUnicodePf
-  , isUnicodePi
-  , isUnicodePo
-  , isUnicodePs
-  , isUnicodeS
-  , isUnicodeSc
-  , isUnicodeSk
-  , isUnicodeSm
-  , isUnicodeSo
-  , isUnicodeZ
-  , isUnicodeZl
-  , isUnicodeZp
-  , isUnicodeZs
-  )
-where
-
--- ------------------------------------------------------------
-
-isInList        :: Char -> [(Char, Char)] -> Bool
-isInList i      =
-   foldr (\(lb, ub) b -> i >= lb && (i <= ub || b)) False
-
--- ------------------------------------------------------------
-
-isUnicodeC      :: Char -> Bool
-isUnicodeC c
-  = isInList c
-    [ ('\NUL','\US')
-    , ('\DEL','\159')
-    , ('\173','\173')
-    , ('\1536','\1539')
-    , ('\1757','\1757')
-    , ('\1807','\1807')
-    , ('\6068','\6069')
-    , ('\8203','\8207')
-    , ('\8234','\8238')
-    , ('\8288','\8292')
-    , ('\8298','\8303')
-    , ('\55296','\55296')
-    , ('\56191','\56192')
-    , ('\56319','\56320')
-    , ('\57343','\57344')
-    , ('\63743','\63743')
-    , ('\65279','\65279')
-    , ('\65529','\65531')
-    , ('\69821','\69821')
-    , ('\119155','\119162')
-    , ('\917505','\917505')
-    , ('\917536','\917631')
-    , ('\983040','\983040')
-    , ('\1048573','\1048573')
-    , ('\1048576','\1048576')
-    , ('\1114109','\1114109')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeCc     :: Char -> Bool
-isUnicodeCc c
-  = isInList c
-    [ ('\NUL','\US')
-    , ('\DEL','\159')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeCf     :: Char -> Bool
-isUnicodeCf c
-  = isInList c
-    [ ('\173','\173')
-    , ('\1536','\1539')
-    , ('\1757','\1757')
-    , ('\1807','\1807')
-    , ('\6068','\6069')
-    , ('\8203','\8207')
-    , ('\8234','\8238')
-    , ('\8288','\8292')
-    , ('\8298','\8303')
-    , ('\65279','\65279')
-    , ('\65529','\65531')
-    , ('\69821','\69821')
-    , ('\119155','\119162')
-    , ('\917505','\917505')
-    , ('\917536','\917631')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeCo     :: Char -> Bool
-isUnicodeCo c
-  = isInList c
-    [ ('\57344','\57344')
-    , ('\63743','\63743')
-    , ('\983040','\983040')
-    , ('\1048573','\1048573')
-    , ('\1048576','\1048576')
-    , ('\1114109','\1114109')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeCs     :: Char -> Bool
-isUnicodeCs c
-  = isInList c
-    [ ('\55296','\55296')
-    , ('\56191','\56192')
-    , ('\56319','\56320')
-    , ('\57343','\57343')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeL      :: Char -> Bool
-isUnicodeL c
-  = isInList c
-    [ ('A','Z')
-    , ('a','z')
-    , ('\170','\170')
-    , ('\181','\181')
-    , ('\186','\186')
-    , ('\192','\214')
-    , ('\216','\246')
-    , ('\248','\705')
-    , ('\710','\721')
-    , ('\736','\740')
-    , ('\748','\748')
-    , ('\750','\750')
-    , ('\880','\884')
-    , ('\886','\887')
-    , ('\890','\893')
-    , ('\902','\902')
-    , ('\904','\906')
-    , ('\908','\908')
-    , ('\910','\929')
-    , ('\931','\1013')
-    , ('\1015','\1153')
-    , ('\1162','\1317')
-    , ('\1329','\1366')
-    , ('\1369','\1369')
-    , ('\1377','\1415')
-    , ('\1488','\1514')
-    , ('\1520','\1522')
-    , ('\1569','\1610')
-    , ('\1646','\1647')
-    , ('\1649','\1747')
-    , ('\1749','\1749')
-    , ('\1765','\1766')
-    , ('\1774','\1775')
-    , ('\1786','\1788')
-    , ('\1791','\1791')
-    , ('\1808','\1808')
-    , ('\1810','\1839')
-    , ('\1869','\1957')
-    , ('\1969','\1969')
-    , ('\1994','\2026')
-    , ('\2036','\2037')
-    , ('\2042','\2042')
-    , ('\2048','\2069')
-    , ('\2074','\2074')
-    , ('\2084','\2084')
-    , ('\2088','\2088')
-    , ('\2308','\2361')
-    , ('\2365','\2365')
-    , ('\2384','\2384')
-    , ('\2392','\2401')
-    , ('\2417','\2418')
-    , ('\2425','\2431')
-    , ('\2437','\2444')
-    , ('\2447','\2448')
-    , ('\2451','\2472')
-    , ('\2474','\2480')
-    , ('\2482','\2482')
-    , ('\2486','\2489')
-    , ('\2493','\2493')
-    , ('\2510','\2510')
-    , ('\2524','\2525')
-    , ('\2527','\2529')
-    , ('\2544','\2545')
-    , ('\2565','\2570')
-    , ('\2575','\2576')
-    , ('\2579','\2600')
-    , ('\2602','\2608')
-    , ('\2610','\2611')
-    , ('\2613','\2614')
-    , ('\2616','\2617')
-    , ('\2649','\2652')
-    , ('\2654','\2654')
-    , ('\2674','\2676')
-    , ('\2693','\2701')
-    , ('\2703','\2705')
-    , ('\2707','\2728')
-    , ('\2730','\2736')
-    , ('\2738','\2739')
-    , ('\2741','\2745')
-    , ('\2749','\2749')
-    , ('\2768','\2768')
-    , ('\2784','\2785')
-    , ('\2821','\2828')
-    , ('\2831','\2832')
-    , ('\2835','\2856')
-    , ('\2858','\2864')
-    , ('\2866','\2867')
-    , ('\2869','\2873')
-    , ('\2877','\2877')
-    , ('\2908','\2909')
-    , ('\2911','\2913')
-    , ('\2929','\2929')
-    , ('\2947','\2947')
-    , ('\2949','\2954')
-    , ('\2958','\2960')
-    , ('\2962','\2965')
-    , ('\2969','\2970')
-    , ('\2972','\2972')
-    , ('\2974','\2975')
-    , ('\2979','\2980')
-    , ('\2984','\2986')
-    , ('\2990','\3001')
-    , ('\3024','\3024')
-    , ('\3077','\3084')
-    , ('\3086','\3088')
-    , ('\3090','\3112')
-    , ('\3114','\3123')
-    , ('\3125','\3129')
-    , ('\3133','\3133')
-    , ('\3160','\3161')
-    , ('\3168','\3169')
-    , ('\3205','\3212')
-    , ('\3214','\3216')
-    , ('\3218','\3240')
-    , ('\3242','\3251')
-    , ('\3253','\3257')
-    , ('\3261','\3261')
-    , ('\3294','\3294')
-    , ('\3296','\3297')
-    , ('\3333','\3340')
-    , ('\3342','\3344')
-    , ('\3346','\3368')
-    , ('\3370','\3385')
-    , ('\3389','\3389')
-    , ('\3424','\3425')
-    , ('\3450','\3455')
-    , ('\3461','\3478')
-    , ('\3482','\3505')
-    , ('\3507','\3515')
-    , ('\3517','\3517')
-    , ('\3520','\3526')
-    , ('\3585','\3632')
-    , ('\3634','\3635')
-    , ('\3648','\3654')
-    , ('\3713','\3714')
-    , ('\3716','\3716')
-    , ('\3719','\3720')
-    , ('\3722','\3722')
-    , ('\3725','\3725')
-    , ('\3732','\3735')
-    , ('\3737','\3743')
-    , ('\3745','\3747')
-    , ('\3749','\3749')
-    , ('\3751','\3751')
-    , ('\3754','\3755')
-    , ('\3757','\3760')
-    , ('\3762','\3763')
-    , ('\3773','\3773')
-    , ('\3776','\3780')
-    , ('\3782','\3782')
-    , ('\3804','\3805')
-    , ('\3840','\3840')
-    , ('\3904','\3911')
-    , ('\3913','\3948')
-    , ('\3976','\3979')
-    , ('\4096','\4138')
-    , ('\4159','\4159')
-    , ('\4176','\4181')
-    , ('\4186','\4189')
-    , ('\4193','\4193')
-    , ('\4197','\4198')
-    , ('\4206','\4208')
-    , ('\4213','\4225')
-    , ('\4238','\4238')
-    , ('\4256','\4293')
-    , ('\4304','\4346')
-    , ('\4348','\4348')
-    , ('\4352','\4680')
-    , ('\4682','\4685')
-    , ('\4688','\4694')
-    , ('\4696','\4696')
-    , ('\4698','\4701')
-    , ('\4704','\4744')
-    , ('\4746','\4749')
-    , ('\4752','\4784')
-    , ('\4786','\4789')
-    , ('\4792','\4798')
-    , ('\4800','\4800')
-    , ('\4802','\4805')
-    , ('\4808','\4822')
-    , ('\4824','\4880')
-    , ('\4882','\4885')
-    , ('\4888','\4954')
-    , ('\4992','\5007')
-    , ('\5024','\5108')
-    , ('\5121','\5740')
-    , ('\5743','\5759')
-    , ('\5761','\5786')
-    , ('\5792','\5866')
-    , ('\5888','\5900')
-    , ('\5902','\5905')
-    , ('\5920','\5937')
-    , ('\5952','\5969')
-    , ('\5984','\5996')
-    , ('\5998','\6000')
-    , ('\6016','\6067')
-    , ('\6103','\6103')
-    , ('\6108','\6108')
-    , ('\6176','\6263')
-    , ('\6272','\6312')
-    , ('\6314','\6314')
-    , ('\6320','\6389')
-    , ('\6400','\6428')
-    , ('\6480','\6509')
-    , ('\6512','\6516')
-    , ('\6528','\6571')
-    , ('\6593','\6599')
-    , ('\6656','\6678')
-    , ('\6688','\6740')
-    , ('\6823','\6823')
-    , ('\6917','\6963')
-    , ('\6981','\6987')
-    , ('\7043','\7072')
-    , ('\7086','\7087')
-    , ('\7168','\7203')
-    , ('\7245','\7247')
-    , ('\7258','\7293')
-    , ('\7401','\7404')
-    , ('\7406','\7409')
-    , ('\7424','\7615')
-    , ('\7680','\7957')
-    , ('\7960','\7965')
-    , ('\7968','\8005')
-    , ('\8008','\8013')
-    , ('\8016','\8023')
-    , ('\8025','\8025')
-    , ('\8027','\8027')
-    , ('\8029','\8029')
-    , ('\8031','\8061')
-    , ('\8064','\8116')
-    , ('\8118','\8124')
-    , ('\8126','\8126')
-    , ('\8130','\8132')
-    , ('\8134','\8140')
-    , ('\8144','\8147')
-    , ('\8150','\8155')
-    , ('\8160','\8172')
-    , ('\8178','\8180')
-    , ('\8182','\8188')
-    , ('\8305','\8305')
-    , ('\8319','\8319')
-    , ('\8336','\8340')
-    , ('\8450','\8450')
-    , ('\8455','\8455')
-    , ('\8458','\8467')
-    , ('\8469','\8469')
-    , ('\8473','\8477')
-    , ('\8484','\8484')
-    , ('\8486','\8486')
-    , ('\8488','\8488')
-    , ('\8490','\8493')
-    , ('\8495','\8505')
-    , ('\8508','\8511')
-    , ('\8517','\8521')
-    , ('\8526','\8526')
-    , ('\8579','\8580')
-    , ('\11264','\11310')
-    , ('\11312','\11358')
-    , ('\11360','\11492')
-    , ('\11499','\11502')
-    , ('\11520','\11557')
-    , ('\11568','\11621')
-    , ('\11631','\11631')
-    , ('\11648','\11670')
-    , ('\11680','\11686')
-    , ('\11688','\11694')
-    , ('\11696','\11702')
-    , ('\11704','\11710')
-    , ('\11712','\11718')
-    , ('\11720','\11726')
-    , ('\11728','\11734')
-    , ('\11736','\11742')
-    , ('\11823','\11823')
-    , ('\12293','\12294')
-    , ('\12337','\12341')
-    , ('\12347','\12348')
-    , ('\12353','\12438')
-    , ('\12445','\12447')
-    , ('\12449','\12538')
-    , ('\12540','\12543')
-    , ('\12549','\12589')
-    , ('\12593','\12686')
-    , ('\12704','\12727')
-    , ('\12784','\12799')
-    , ('\13312','\13312')
-    , ('\19893','\19893')
-    , ('\19968','\19968')
-    , ('\40907','\40907')
-    , ('\40960','\42124')
-    , ('\42192','\42237')
-    , ('\42240','\42508')
-    , ('\42512','\42527')
-    , ('\42538','\42539')
-    , ('\42560','\42591')
-    , ('\42594','\42606')
-    , ('\42623','\42647')
-    , ('\42656','\42725')
-    , ('\42775','\42783')
-    , ('\42786','\42888')
-    , ('\42891','\42892')
-    , ('\43003','\43009')
-    , ('\43011','\43013')
-    , ('\43015','\43018')
-    , ('\43020','\43042')
-    , ('\43072','\43123')
-    , ('\43138','\43187')
-    , ('\43250','\43255')
-    , ('\43259','\43259')
-    , ('\43274','\43301')
-    , ('\43312','\43334')
-    , ('\43360','\43388')
-    , ('\43396','\43442')
-    , ('\43471','\43471')
-    , ('\43520','\43560')
-    , ('\43584','\43586')
-    , ('\43588','\43595')
-    , ('\43616','\43638')
-    , ('\43642','\43642')
-    , ('\43648','\43695')
-    , ('\43697','\43697')
-    , ('\43701','\43702')
-    , ('\43705','\43709')
-    , ('\43712','\43712')
-    , ('\43714','\43714')
-    , ('\43739','\43741')
-    , ('\43968','\44002')
-    , ('\44032','\44032')
-    , ('\55203','\55203')
-    , ('\55216','\55238')
-    , ('\55243','\55291')
-    , ('\63744','\64045')
-    , ('\64048','\64109')
-    , ('\64112','\64217')
-    , ('\64256','\64262')
-    , ('\64275','\64279')
-    , ('\64285','\64285')
-    , ('\64287','\64296')
-    , ('\64298','\64310')
-    , ('\64312','\64316')
-    , ('\64318','\64318')
-    , ('\64320','\64321')
-    , ('\64323','\64324')
-    , ('\64326','\64433')
-    , ('\64467','\64829')
-    , ('\64848','\64911')
-    , ('\64914','\64967')
-    , ('\65008','\65019')
-    , ('\65136','\65140')
-    , ('\65142','\65276')
-    , ('\65313','\65338')
-    , ('\65345','\65370')
-    , ('\65382','\65470')
-    , ('\65474','\65479')
-    , ('\65482','\65487')
-    , ('\65490','\65495')
-    , ('\65498','\65500')
-    , ('\65536','\65547')
-    , ('\65549','\65574')
-    , ('\65576','\65594')
-    , ('\65596','\65597')
-    , ('\65599','\65613')
-    , ('\65616','\65629')
-    , ('\65664','\65786')
-    , ('\66176','\66204')
-    , ('\66208','\66256')
-    , ('\66304','\66334')
-    , ('\66352','\66368')
-    , ('\66370','\66377')
-    , ('\66432','\66461')
-    , ('\66464','\66499')
-    , ('\66504','\66511')
-    , ('\66560','\66717')
-    , ('\67584','\67589')
-    , ('\67592','\67592')
-    , ('\67594','\67637')
-    , ('\67639','\67640')
-    , ('\67644','\67644')
-    , ('\67647','\67669')
-    , ('\67840','\67861')
-    , ('\67872','\67897')
-    , ('\68096','\68096')
-    , ('\68112','\68115')
-    , ('\68117','\68119')
-    , ('\68121','\68147')
-    , ('\68192','\68220')
-    , ('\68352','\68405')
-    , ('\68416','\68437')
-    , ('\68448','\68466')
-    , ('\68608','\68680')
-    , ('\69763','\69807')
-    , ('\73728','\74606')
-    , ('\77824','\78894')
-    , ('\119808','\119892')
-    , ('\119894','\119964')
-    , ('\119966','\119967')
-    , ('\119970','\119970')
-    , ('\119973','\119974')
-    , ('\119977','\119980')
-    , ('\119982','\119993')
-    , ('\119995','\119995')
-    , ('\119997','\120003')
-    , ('\120005','\120069')
-    , ('\120071','\120074')
-    , ('\120077','\120084')
-    , ('\120086','\120092')
-    , ('\120094','\120121')
-    , ('\120123','\120126')
-    , ('\120128','\120132')
-    , ('\120134','\120134')
-    , ('\120138','\120144')
-    , ('\120146','\120485')
-    , ('\120488','\120512')
-    , ('\120514','\120538')
-    , ('\120540','\120570')
-    , ('\120572','\120596')
-    , ('\120598','\120628')
-    , ('\120630','\120654')
-    , ('\120656','\120686')
-    , ('\120688','\120712')
-    , ('\120714','\120744')
-    , ('\120746','\120770')
-    , ('\120772','\120779')
-    , ('\131072','\131072')
-    , ('\173782','\173782')
-    , ('\173824','\173824')
-    , ('\177972','\177972')
-    , ('\194560','\195101')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeLl     :: Char -> Bool
-isUnicodeLl c
-  = isInList c
-    [ ('a','z')
-    , ('\170','\170')
-    , ('\181','\181')
-    , ('\186','\186')
-    , ('\223','\246')
-    , ('\248','\255')
-    , ('\257','\257')
-    , ('\259','\259')
-    , ('\261','\261')
-    , ('\263','\263')
-    , ('\265','\265')
-    , ('\267','\267')
-    , ('\269','\269')
-    , ('\271','\271')
-    , ('\273','\273')
-    , ('\275','\275')
-    , ('\277','\277')
-    , ('\279','\279')
-    , ('\281','\281')
-    , ('\283','\283')
-    , ('\285','\285')
-    , ('\287','\287')
-    , ('\289','\289')
-    , ('\291','\291')
-    , ('\293','\293')
-    , ('\295','\295')
-    , ('\297','\297')
-    , ('\299','\299')
-    , ('\301','\301')
-    , ('\303','\303')
-    , ('\305','\305')
-    , ('\307','\307')
-    , ('\309','\309')
-    , ('\311','\312')
-    , ('\314','\314')
-    , ('\316','\316')
-    , ('\318','\318')
-    , ('\320','\320')
-    , ('\322','\322')
-    , ('\324','\324')
-    , ('\326','\326')
-    , ('\328','\329')
-    , ('\331','\331')
-    , ('\333','\333')
-    , ('\335','\335')
-    , ('\337','\337')
-    , ('\339','\339')
-    , ('\341','\341')
-    , ('\343','\343')
-    , ('\345','\345')
-    , ('\347','\347')
-    , ('\349','\349')
-    , ('\351','\351')
-    , ('\353','\353')
-    , ('\355','\355')
-    , ('\357','\357')
-    , ('\359','\359')
-    , ('\361','\361')
-    , ('\363','\363')
-    , ('\365','\365')
-    , ('\367','\367')
-    , ('\369','\369')
-    , ('\371','\371')
-    , ('\373','\373')
-    , ('\375','\375')
-    , ('\378','\378')
-    , ('\380','\380')
-    , ('\382','\384')
-    , ('\387','\387')
-    , ('\389','\389')
-    , ('\392','\392')
-    , ('\396','\397')
-    , ('\402','\402')
-    , ('\405','\405')
-    , ('\409','\411')
-    , ('\414','\414')
-    , ('\417','\417')
-    , ('\419','\419')
-    , ('\421','\421')
-    , ('\424','\424')
-    , ('\426','\427')
-    , ('\429','\429')
-    , ('\432','\432')
-    , ('\436','\436')
-    , ('\438','\438')
-    , ('\441','\442')
-    , ('\445','\447')
-    , ('\454','\454')
-    , ('\457','\457')
-    , ('\460','\460')
-    , ('\462','\462')
-    , ('\464','\464')
-    , ('\466','\466')
-    , ('\468','\468')
-    , ('\470','\470')
-    , ('\472','\472')
-    , ('\474','\474')
-    , ('\476','\477')
-    , ('\479','\479')
-    , ('\481','\481')
-    , ('\483','\483')
-    , ('\485','\485')
-    , ('\487','\487')
-    , ('\489','\489')
-    , ('\491','\491')
-    , ('\493','\493')
-    , ('\495','\496')
-    , ('\499','\499')
-    , ('\501','\501')
-    , ('\505','\505')
-    , ('\507','\507')
-    , ('\509','\509')
-    , ('\511','\511')
-    , ('\513','\513')
-    , ('\515','\515')
-    , ('\517','\517')
-    , ('\519','\519')
-    , ('\521','\521')
-    , ('\523','\523')
-    , ('\525','\525')
-    , ('\527','\527')
-    , ('\529','\529')
-    , ('\531','\531')
-    , ('\533','\533')
-    , ('\535','\535')
-    , ('\537','\537')
-    , ('\539','\539')
-    , ('\541','\541')
-    , ('\543','\543')
-    , ('\545','\545')
-    , ('\547','\547')
-    , ('\549','\549')
-    , ('\551','\551')
-    , ('\553','\553')
-    , ('\555','\555')
-    , ('\557','\557')
-    , ('\559','\559')
-    , ('\561','\561')
-    , ('\563','\569')
-    , ('\572','\572')
-    , ('\575','\576')
-    , ('\578','\578')
-    , ('\583','\583')
-    , ('\585','\585')
-    , ('\587','\587')
-    , ('\589','\589')
-    , ('\591','\659')
-    , ('\661','\687')
-    , ('\881','\881')
-    , ('\883','\883')
-    , ('\887','\887')
-    , ('\891','\893')
-    , ('\912','\912')
-    , ('\940','\974')
-    , ('\976','\977')
-    , ('\981','\983')
-    , ('\985','\985')
-    , ('\987','\987')
-    , ('\989','\989')
-    , ('\991','\991')
-    , ('\993','\993')
-    , ('\995','\995')
-    , ('\997','\997')
-    , ('\999','\999')
-    , ('\1001','\1001')
-    , ('\1003','\1003')
-    , ('\1005','\1005')
-    , ('\1007','\1011')
-    , ('\1013','\1013')
-    , ('\1016','\1016')
-    , ('\1019','\1020')
-    , ('\1072','\1119')
-    , ('\1121','\1121')
-    , ('\1123','\1123')
-    , ('\1125','\1125')
-    , ('\1127','\1127')
-    , ('\1129','\1129')
-    , ('\1131','\1131')
-    , ('\1133','\1133')
-    , ('\1135','\1135')
-    , ('\1137','\1137')
-    , ('\1139','\1139')
-    , ('\1141','\1141')
-    , ('\1143','\1143')
-    , ('\1145','\1145')
-    , ('\1147','\1147')
-    , ('\1149','\1149')
-    , ('\1151','\1151')
-    , ('\1153','\1153')
-    , ('\1163','\1163')
-    , ('\1165','\1165')
-    , ('\1167','\1167')
-    , ('\1169','\1169')
-    , ('\1171','\1171')
-    , ('\1173','\1173')
-    , ('\1175','\1175')
-    , ('\1177','\1177')
-    , ('\1179','\1179')
-    , ('\1181','\1181')
-    , ('\1183','\1183')
-    , ('\1185','\1185')
-    , ('\1187','\1187')
-    , ('\1189','\1189')
-    , ('\1191','\1191')
-    , ('\1193','\1193')
-    , ('\1195','\1195')
-    , ('\1197','\1197')
-    , ('\1199','\1199')
-    , ('\1201','\1201')
-    , ('\1203','\1203')
-    , ('\1205','\1205')
-    , ('\1207','\1207')
-    , ('\1209','\1209')
-    , ('\1211','\1211')
-    , ('\1213','\1213')
-    , ('\1215','\1215')
-    , ('\1218','\1218')
-    , ('\1220','\1220')
-    , ('\1222','\1222')
-    , ('\1224','\1224')
-    , ('\1226','\1226')
-    , ('\1228','\1228')
-    , ('\1230','\1231')
-    , ('\1233','\1233')
-    , ('\1235','\1235')
-    , ('\1237','\1237')
-    , ('\1239','\1239')
-    , ('\1241','\1241')
-    , ('\1243','\1243')
-    , ('\1245','\1245')
-    , ('\1247','\1247')
-    , ('\1249','\1249')
-    , ('\1251','\1251')
-    , ('\1253','\1253')
-    , ('\1255','\1255')
-    , ('\1257','\1257')
-    , ('\1259','\1259')
-    , ('\1261','\1261')
-    , ('\1263','\1263')
-    , ('\1265','\1265')
-    , ('\1267','\1267')
-    , ('\1269','\1269')
-    , ('\1271','\1271')
-    , ('\1273','\1273')
-    , ('\1275','\1275')
-    , ('\1277','\1277')
-    , ('\1279','\1279')
-    , ('\1281','\1281')
-    , ('\1283','\1283')
-    , ('\1285','\1285')
-    , ('\1287','\1287')
-    , ('\1289','\1289')
-    , ('\1291','\1291')
-    , ('\1293','\1293')
-    , ('\1295','\1295')
-    , ('\1297','\1297')
-    , ('\1299','\1299')
-    , ('\1301','\1301')
-    , ('\1303','\1303')
-    , ('\1305','\1305')
-    , ('\1307','\1307')
-    , ('\1309','\1309')
-    , ('\1311','\1311')
-    , ('\1313','\1313')
-    , ('\1315','\1315')
-    , ('\1317','\1317')
-    , ('\1377','\1415')
-    , ('\7424','\7467')
-    , ('\7522','\7543')
-    , ('\7545','\7578')
-    , ('\7681','\7681')
-    , ('\7683','\7683')
-    , ('\7685','\7685')
-    , ('\7687','\7687')
-    , ('\7689','\7689')
-    , ('\7691','\7691')
-    , ('\7693','\7693')
-    , ('\7695','\7695')
-    , ('\7697','\7697')
-    , ('\7699','\7699')
-    , ('\7701','\7701')
-    , ('\7703','\7703')
-    , ('\7705','\7705')
-    , ('\7707','\7707')
-    , ('\7709','\7709')
-    , ('\7711','\7711')
-    , ('\7713','\7713')
-    , ('\7715','\7715')
-    , ('\7717','\7717')
-    , ('\7719','\7719')
-    , ('\7721','\7721')
-    , ('\7723','\7723')
-    , ('\7725','\7725')
-    , ('\7727','\7727')
-    , ('\7729','\7729')
-    , ('\7731','\7731')
-    , ('\7733','\7733')
-    , ('\7735','\7735')
-    , ('\7737','\7737')
-    , ('\7739','\7739')
-    , ('\7741','\7741')
-    , ('\7743','\7743')
-    , ('\7745','\7745')
-    , ('\7747','\7747')
-    , ('\7749','\7749')
-    , ('\7751','\7751')
-    , ('\7753','\7753')
-    , ('\7755','\7755')
-    , ('\7757','\7757')
-    , ('\7759','\7759')
-    , ('\7761','\7761')
-    , ('\7763','\7763')
-    , ('\7765','\7765')
-    , ('\7767','\7767')
-    , ('\7769','\7769')
-    , ('\7771','\7771')
-    , ('\7773','\7773')
-    , ('\7775','\7775')
-    , ('\7777','\7777')
-    , ('\7779','\7779')
-    , ('\7781','\7781')
-    , ('\7783','\7783')
-    , ('\7785','\7785')
-    , ('\7787','\7787')
-    , ('\7789','\7789')
-    , ('\7791','\7791')
-    , ('\7793','\7793')
-    , ('\7795','\7795')
-    , ('\7797','\7797')
-    , ('\7799','\7799')
-    , ('\7801','\7801')
-    , ('\7803','\7803')
-    , ('\7805','\7805')
-    , ('\7807','\7807')
-    , ('\7809','\7809')
-    , ('\7811','\7811')
-    , ('\7813','\7813')
-    , ('\7815','\7815')
-    , ('\7817','\7817')
-    , ('\7819','\7819')
-    , ('\7821','\7821')
-    , ('\7823','\7823')
-    , ('\7825','\7825')
-    , ('\7827','\7827')
-    , ('\7829','\7837')
-    , ('\7839','\7839')
-    , ('\7841','\7841')
-    , ('\7843','\7843')
-    , ('\7845','\7845')
-    , ('\7847','\7847')
-    , ('\7849','\7849')
-    , ('\7851','\7851')
-    , ('\7853','\7853')
-    , ('\7855','\7855')
-    , ('\7857','\7857')
-    , ('\7859','\7859')
-    , ('\7861','\7861')
-    , ('\7863','\7863')
-    , ('\7865','\7865')
-    , ('\7867','\7867')
-    , ('\7869','\7869')
-    , ('\7871','\7871')
-    , ('\7873','\7873')
-    , ('\7875','\7875')
-    , ('\7877','\7877')
-    , ('\7879','\7879')
-    , ('\7881','\7881')
-    , ('\7883','\7883')
-    , ('\7885','\7885')
-    , ('\7887','\7887')
-    , ('\7889','\7889')
-    , ('\7891','\7891')
-    , ('\7893','\7893')
-    , ('\7895','\7895')
-    , ('\7897','\7897')
-    , ('\7899','\7899')
-    , ('\7901','\7901')
-    , ('\7903','\7903')
-    , ('\7905','\7905')
-    , ('\7907','\7907')
-    , ('\7909','\7909')
-    , ('\7911','\7911')
-    , ('\7913','\7913')
-    , ('\7915','\7915')
-    , ('\7917','\7917')
-    , ('\7919','\7919')
-    , ('\7921','\7921')
-    , ('\7923','\7923')
-    , ('\7925','\7925')
-    , ('\7927','\7927')
-    , ('\7929','\7929')
-    , ('\7931','\7931')
-    , ('\7933','\7933')
-    , ('\7935','\7943')
-    , ('\7952','\7957')
-    , ('\7968','\7975')
-    , ('\7984','\7991')
-    , ('\8000','\8005')
-    , ('\8016','\8023')
-    , ('\8032','\8039')
-    , ('\8048','\8061')
-    , ('\8064','\8071')
-    , ('\8080','\8087')
-    , ('\8096','\8103')
-    , ('\8112','\8116')
-    , ('\8118','\8119')
-    , ('\8126','\8126')
-    , ('\8130','\8132')
-    , ('\8134','\8135')
-    , ('\8144','\8147')
-    , ('\8150','\8151')
-    , ('\8160','\8167')
-    , ('\8178','\8180')
-    , ('\8182','\8183')
-    , ('\8458','\8458')
-    , ('\8462','\8463')
-    , ('\8467','\8467')
-    , ('\8495','\8495')
-    , ('\8500','\8500')
-    , ('\8505','\8505')
-    , ('\8508','\8509')
-    , ('\8518','\8521')
-    , ('\8526','\8526')
-    , ('\8580','\8580')
-    , ('\11312','\11358')
-    , ('\11361','\11361')
-    , ('\11365','\11366')
-    , ('\11368','\11368')
-    , ('\11370','\11370')
-    , ('\11372','\11372')
-    , ('\11377','\11377')
-    , ('\11379','\11380')
-    , ('\11382','\11388')
-    , ('\11393','\11393')
-    , ('\11395','\11395')
-    , ('\11397','\11397')
-    , ('\11399','\11399')
-    , ('\11401','\11401')
-    , ('\11403','\11403')
-    , ('\11405','\11405')
-    , ('\11407','\11407')
-    , ('\11409','\11409')
-    , ('\11411','\11411')
-    , ('\11413','\11413')
-    , ('\11415','\11415')
-    , ('\11417','\11417')
-    , ('\11419','\11419')
-    , ('\11421','\11421')
-    , ('\11423','\11423')
-    , ('\11425','\11425')
-    , ('\11427','\11427')
-    , ('\11429','\11429')
-    , ('\11431','\11431')
-    , ('\11433','\11433')
-    , ('\11435','\11435')
-    , ('\11437','\11437')
-    , ('\11439','\11439')
-    , ('\11441','\11441')
-    , ('\11443','\11443')
-    , ('\11445','\11445')
-    , ('\11447','\11447')
-    , ('\11449','\11449')
-    , ('\11451','\11451')
-    , ('\11453','\11453')
-    , ('\11455','\11455')
-    , ('\11457','\11457')
-    , ('\11459','\11459')
-    , ('\11461','\11461')
-    , ('\11463','\11463')
-    , ('\11465','\11465')
-    , ('\11467','\11467')
-    , ('\11469','\11469')
-    , ('\11471','\11471')
-    , ('\11473','\11473')
-    , ('\11475','\11475')
-    , ('\11477','\11477')
-    , ('\11479','\11479')
-    , ('\11481','\11481')
-    , ('\11483','\11483')
-    , ('\11485','\11485')
-    , ('\11487','\11487')
-    , ('\11489','\11489')
-    , ('\11491','\11492')
-    , ('\11500','\11500')
-    , ('\11502','\11502')
-    , ('\11520','\11557')
-    , ('\42561','\42561')
-    , ('\42563','\42563')
-    , ('\42565','\42565')
-    , ('\42567','\42567')
-    , ('\42569','\42569')
-    , ('\42571','\42571')
-    , ('\42573','\42573')
-    , ('\42575','\42575')
-    , ('\42577','\42577')
-    , ('\42579','\42579')
-    , ('\42581','\42581')
-    , ('\42583','\42583')
-    , ('\42585','\42585')
-    , ('\42587','\42587')
-    , ('\42589','\42589')
-    , ('\42591','\42591')
-    , ('\42595','\42595')
-    , ('\42597','\42597')
-    , ('\42599','\42599')
-    , ('\42601','\42601')
-    , ('\42603','\42603')
-    , ('\42605','\42605')
-    , ('\42625','\42625')
-    , ('\42627','\42627')
-    , ('\42629','\42629')
-    , ('\42631','\42631')
-    , ('\42633','\42633')
-    , ('\42635','\42635')
-    , ('\42637','\42637')
-    , ('\42639','\42639')
-    , ('\42641','\42641')
-    , ('\42643','\42643')
-    , ('\42645','\42645')
-    , ('\42647','\42647')
-    , ('\42787','\42787')
-    , ('\42789','\42789')
-    , ('\42791','\42791')
-    , ('\42793','\42793')
-    , ('\42795','\42795')
-    , ('\42797','\42797')
-    , ('\42799','\42801')
-    , ('\42803','\42803')
-    , ('\42805','\42805')
-    , ('\42807','\42807')
-    , ('\42809','\42809')
-    , ('\42811','\42811')
-    , ('\42813','\42813')
-    , ('\42815','\42815')
-    , ('\42817','\42817')
-    , ('\42819','\42819')
-    , ('\42821','\42821')
-    , ('\42823','\42823')
-    , ('\42825','\42825')
-    , ('\42827','\42827')
-    , ('\42829','\42829')
-    , ('\42831','\42831')
-    , ('\42833','\42833')
-    , ('\42835','\42835')
-    , ('\42837','\42837')
-    , ('\42839','\42839')
-    , ('\42841','\42841')
-    , ('\42843','\42843')
-    , ('\42845','\42845')
-    , ('\42847','\42847')
-    , ('\42849','\42849')
-    , ('\42851','\42851')
-    , ('\42853','\42853')
-    , ('\42855','\42855')
-    , ('\42857','\42857')
-    , ('\42859','\42859')
-    , ('\42861','\42861')
-    , ('\42863','\42863')
-    , ('\42865','\42872')
-    , ('\42874','\42874')
-    , ('\42876','\42876')
-    , ('\42879','\42879')
-    , ('\42881','\42881')
-    , ('\42883','\42883')
-    , ('\42885','\42885')
-    , ('\42887','\42887')
-    , ('\42892','\42892')
-    , ('\64256','\64262')
-    , ('\64275','\64279')
-    , ('\65345','\65370')
-    , ('\66600','\66639')
-    , ('\119834','\119859')
-    , ('\119886','\119892')
-    , ('\119894','\119911')
-    , ('\119938','\119963')
-    , ('\119990','\119993')
-    , ('\119995','\119995')
-    , ('\119997','\120003')
-    , ('\120005','\120015')
-    , ('\120042','\120067')
-    , ('\120094','\120119')
-    , ('\120146','\120171')
-    , ('\120198','\120223')
-    , ('\120250','\120275')
-    , ('\120302','\120327')
-    , ('\120354','\120379')
-    , ('\120406','\120431')
-    , ('\120458','\120485')
-    , ('\120514','\120538')
-    , ('\120540','\120545')
-    , ('\120572','\120596')
-    , ('\120598','\120603')
-    , ('\120630','\120654')
-    , ('\120656','\120661')
-    , ('\120688','\120712')
-    , ('\120714','\120719')
-    , ('\120746','\120770')
-    , ('\120772','\120777')
-    , ('\120779','\120779')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeLm     :: Char -> Bool
-isUnicodeLm c
-  = isInList c
-    [ ('\688','\705')
-    , ('\710','\721')
-    , ('\736','\740')
-    , ('\748','\748')
-    , ('\750','\750')
-    , ('\884','\884')
-    , ('\890','\890')
-    , ('\1369','\1369')
-    , ('\1600','\1600')
-    , ('\1765','\1766')
-    , ('\2036','\2037')
-    , ('\2042','\2042')
-    , ('\2074','\2074')
-    , ('\2084','\2084')
-    , ('\2088','\2088')
-    , ('\2417','\2417')
-    , ('\3654','\3654')
-    , ('\3782','\3782')
-    , ('\4348','\4348')
-    , ('\6103','\6103')
-    , ('\6211','\6211')
-    , ('\6823','\6823')
-    , ('\7288','\7293')
-    , ('\7468','\7521')
-    , ('\7544','\7544')
-    , ('\7579','\7615')
-    , ('\8305','\8305')
-    , ('\8319','\8319')
-    , ('\8336','\8340')
-    , ('\11389','\11389')
-    , ('\11631','\11631')
-    , ('\11823','\11823')
-    , ('\12293','\12293')
-    , ('\12337','\12341')
-    , ('\12347','\12347')
-    , ('\12445','\12446')
-    , ('\12540','\12542')
-    , ('\40981','\40981')
-    , ('\42232','\42237')
-    , ('\42508','\42508')
-    , ('\42623','\42623')
-    , ('\42775','\42783')
-    , ('\42864','\42864')
-    , ('\42888','\42888')
-    , ('\43471','\43471')
-    , ('\43632','\43632')
-    , ('\43741','\43741')
-    , ('\65392','\65392')
-    , ('\65438','\65439')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeLo     :: Char -> Bool
-isUnicodeLo c
-  = isInList c
-    [ ('\443','\443')
-    , ('\448','\451')
-    , ('\660','\660')
-    , ('\1488','\1514')
-    , ('\1520','\1522')
-    , ('\1569','\1599')
-    , ('\1601','\1610')
-    , ('\1646','\1647')
-    , ('\1649','\1747')
-    , ('\1749','\1749')
-    , ('\1774','\1775')
-    , ('\1786','\1788')
-    , ('\1791','\1791')
-    , ('\1808','\1808')
-    , ('\1810','\1839')
-    , ('\1869','\1957')
-    , ('\1969','\1969')
-    , ('\1994','\2026')
-    , ('\2048','\2069')
-    , ('\2308','\2361')
-    , ('\2365','\2365')
-    , ('\2384','\2384')
-    , ('\2392','\2401')
-    , ('\2418','\2418')
-    , ('\2425','\2431')
-    , ('\2437','\2444')
-    , ('\2447','\2448')
-    , ('\2451','\2472')
-    , ('\2474','\2480')
-    , ('\2482','\2482')
-    , ('\2486','\2489')
-    , ('\2493','\2493')
-    , ('\2510','\2510')
-    , ('\2524','\2525')
-    , ('\2527','\2529')
-    , ('\2544','\2545')
-    , ('\2565','\2570')
-    , ('\2575','\2576')
-    , ('\2579','\2600')
-    , ('\2602','\2608')
-    , ('\2610','\2611')
-    , ('\2613','\2614')
-    , ('\2616','\2617')
-    , ('\2649','\2652')
-    , ('\2654','\2654')
-    , ('\2674','\2676')
-    , ('\2693','\2701')
-    , ('\2703','\2705')
-    , ('\2707','\2728')
-    , ('\2730','\2736')
-    , ('\2738','\2739')
-    , ('\2741','\2745')
-    , ('\2749','\2749')
-    , ('\2768','\2768')
-    , ('\2784','\2785')
-    , ('\2821','\2828')
-    , ('\2831','\2832')
-    , ('\2835','\2856')
-    , ('\2858','\2864')
-    , ('\2866','\2867')
-    , ('\2869','\2873')
-    , ('\2877','\2877')
-    , ('\2908','\2909')
-    , ('\2911','\2913')
-    , ('\2929','\2929')
-    , ('\2947','\2947')
-    , ('\2949','\2954')
-    , ('\2958','\2960')
-    , ('\2962','\2965')
-    , ('\2969','\2970')
-    , ('\2972','\2972')
-    , ('\2974','\2975')
-    , ('\2979','\2980')
-    , ('\2984','\2986')
-    , ('\2990','\3001')
-    , ('\3024','\3024')
-    , ('\3077','\3084')
-    , ('\3086','\3088')
-    , ('\3090','\3112')
-    , ('\3114','\3123')
-    , ('\3125','\3129')
-    , ('\3133','\3133')
-    , ('\3160','\3161')
-    , ('\3168','\3169')
-    , ('\3205','\3212')
-    , ('\3214','\3216')
-    , ('\3218','\3240')
-    , ('\3242','\3251')
-    , ('\3253','\3257')
-    , ('\3261','\3261')
-    , ('\3294','\3294')
-    , ('\3296','\3297')
-    , ('\3333','\3340')
-    , ('\3342','\3344')
-    , ('\3346','\3368')
-    , ('\3370','\3385')
-    , ('\3389','\3389')
-    , ('\3424','\3425')
-    , ('\3450','\3455')
-    , ('\3461','\3478')
-    , ('\3482','\3505')
-    , ('\3507','\3515')
-    , ('\3517','\3517')
-    , ('\3520','\3526')
-    , ('\3585','\3632')
-    , ('\3634','\3635')
-    , ('\3648','\3653')
-    , ('\3713','\3714')
-    , ('\3716','\3716')
-    , ('\3719','\3720')
-    , ('\3722','\3722')
-    , ('\3725','\3725')
-    , ('\3732','\3735')
-    , ('\3737','\3743')
-    , ('\3745','\3747')
-    , ('\3749','\3749')
-    , ('\3751','\3751')
-    , ('\3754','\3755')
-    , ('\3757','\3760')
-    , ('\3762','\3763')
-    , ('\3773','\3773')
-    , ('\3776','\3780')
-    , ('\3804','\3805')
-    , ('\3840','\3840')
-    , ('\3904','\3911')
-    , ('\3913','\3948')
-    , ('\3976','\3979')
-    , ('\4096','\4138')
-    , ('\4159','\4159')
-    , ('\4176','\4181')
-    , ('\4186','\4189')
-    , ('\4193','\4193')
-    , ('\4197','\4198')
-    , ('\4206','\4208')
-    , ('\4213','\4225')
-    , ('\4238','\4238')
-    , ('\4304','\4346')
-    , ('\4352','\4680')
-    , ('\4682','\4685')
-    , ('\4688','\4694')
-    , ('\4696','\4696')
-    , ('\4698','\4701')
-    , ('\4704','\4744')
-    , ('\4746','\4749')
-    , ('\4752','\4784')
-    , ('\4786','\4789')
-    , ('\4792','\4798')
-    , ('\4800','\4800')
-    , ('\4802','\4805')
-    , ('\4808','\4822')
-    , ('\4824','\4880')
-    , ('\4882','\4885')
-    , ('\4888','\4954')
-    , ('\4992','\5007')
-    , ('\5024','\5108')
-    , ('\5121','\5740')
-    , ('\5743','\5759')
-    , ('\5761','\5786')
-    , ('\5792','\5866')
-    , ('\5888','\5900')
-    , ('\5902','\5905')
-    , ('\5920','\5937')
-    , ('\5952','\5969')
-    , ('\5984','\5996')
-    , ('\5998','\6000')
-    , ('\6016','\6067')
-    , ('\6108','\6108')
-    , ('\6176','\6210')
-    , ('\6212','\6263')
-    , ('\6272','\6312')
-    , ('\6314','\6314')
-    , ('\6320','\6389')
-    , ('\6400','\6428')
-    , ('\6480','\6509')
-    , ('\6512','\6516')
-    , ('\6528','\6571')
-    , ('\6593','\6599')
-    , ('\6656','\6678')
-    , ('\6688','\6740')
-    , ('\6917','\6963')
-    , ('\6981','\6987')
-    , ('\7043','\7072')
-    , ('\7086','\7087')
-    , ('\7168','\7203')
-    , ('\7245','\7247')
-    , ('\7258','\7287')
-    , ('\7401','\7404')
-    , ('\7406','\7409')
-    , ('\8501','\8504')
-    , ('\11568','\11621')
-    , ('\11648','\11670')
-    , ('\11680','\11686')
-    , ('\11688','\11694')
-    , ('\11696','\11702')
-    , ('\11704','\11710')
-    , ('\11712','\11718')
-    , ('\11720','\11726')
-    , ('\11728','\11734')
-    , ('\11736','\11742')
-    , ('\12294','\12294')
-    , ('\12348','\12348')
-    , ('\12353','\12438')
-    , ('\12447','\12447')
-    , ('\12449','\12538')
-    , ('\12543','\12543')
-    , ('\12549','\12589')
-    , ('\12593','\12686')
-    , ('\12704','\12727')
-    , ('\12784','\12799')
-    , ('\13312','\13312')
-    , ('\19893','\19893')
-    , ('\19968','\19968')
-    , ('\40907','\40907')
-    , ('\40960','\40980')
-    , ('\40982','\42124')
-    , ('\42192','\42231')
-    , ('\42240','\42507')
-    , ('\42512','\42527')
-    , ('\42538','\42539')
-    , ('\42606','\42606')
-    , ('\42656','\42725')
-    , ('\43003','\43009')
-    , ('\43011','\43013')
-    , ('\43015','\43018')
-    , ('\43020','\43042')
-    , ('\43072','\43123')
-    , ('\43138','\43187')
-    , ('\43250','\43255')
-    , ('\43259','\43259')
-    , ('\43274','\43301')
-    , ('\43312','\43334')
-    , ('\43360','\43388')
-    , ('\43396','\43442')
-    , ('\43520','\43560')
-    , ('\43584','\43586')
-    , ('\43588','\43595')
-    , ('\43616','\43631')
-    , ('\43633','\43638')
-    , ('\43642','\43642')
-    , ('\43648','\43695')
-    , ('\43697','\43697')
-    , ('\43701','\43702')
-    , ('\43705','\43709')
-    , ('\43712','\43712')
-    , ('\43714','\43714')
-    , ('\43739','\43740')
-    , ('\43968','\44002')
-    , ('\44032','\44032')
-    , ('\55203','\55203')
-    , ('\55216','\55238')
-    , ('\55243','\55291')
-    , ('\63744','\64045')
-    , ('\64048','\64109')
-    , ('\64112','\64217')
-    , ('\64285','\64285')
-    , ('\64287','\64296')
-    , ('\64298','\64310')
-    , ('\64312','\64316')
-    , ('\64318','\64318')
-    , ('\64320','\64321')
-    , ('\64323','\64324')
-    , ('\64326','\64433')
-    , ('\64467','\64829')
-    , ('\64848','\64911')
-    , ('\64914','\64967')
-    , ('\65008','\65019')
-    , ('\65136','\65140')
-    , ('\65142','\65276')
-    , ('\65382','\65391')
-    , ('\65393','\65437')
-    , ('\65440','\65470')
-    , ('\65474','\65479')
-    , ('\65482','\65487')
-    , ('\65490','\65495')
-    , ('\65498','\65500')
-    , ('\65536','\65547')
-    , ('\65549','\65574')
-    , ('\65576','\65594')
-    , ('\65596','\65597')
-    , ('\65599','\65613')
-    , ('\65616','\65629')
-    , ('\65664','\65786')
-    , ('\66176','\66204')
-    , ('\66208','\66256')
-    , ('\66304','\66334')
-    , ('\66352','\66368')
-    , ('\66370','\66377')
-    , ('\66432','\66461')
-    , ('\66464','\66499')
-    , ('\66504','\66511')
-    , ('\66640','\66717')
-    , ('\67584','\67589')
-    , ('\67592','\67592')
-    , ('\67594','\67637')
-    , ('\67639','\67640')
-    , ('\67644','\67644')
-    , ('\67647','\67669')
-    , ('\67840','\67861')
-    , ('\67872','\67897')
-    , ('\68096','\68096')
-    , ('\68112','\68115')
-    , ('\68117','\68119')
-    , ('\68121','\68147')
-    , ('\68192','\68220')
-    , ('\68352','\68405')
-    , ('\68416','\68437')
-    , ('\68448','\68466')
-    , ('\68608','\68680')
-    , ('\69763','\69807')
-    , ('\73728','\74606')
-    , ('\77824','\78894')
-    , ('\131072','\131072')
-    , ('\173782','\173782')
-    , ('\173824','\173824')
-    , ('\177972','\177972')
-    , ('\194560','\195101')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeLt     :: Char -> Bool
-isUnicodeLt c
-  = isInList c
-    [ ('\453','\453')
-    , ('\456','\456')
-    , ('\459','\459')
-    , ('\498','\498')
-    , ('\8072','\8079')
-    , ('\8088','\8095')
-    , ('\8104','\8111')
-    , ('\8124','\8124')
-    , ('\8140','\8140')
-    , ('\8188','\8188')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeLu     :: Char -> Bool
-isUnicodeLu c
-  = isInList c
-    [ ('A','Z')
-    , ('\192','\214')
-    , ('\216','\222')
-    , ('\256','\256')
-    , ('\258','\258')
-    , ('\260','\260')
-    , ('\262','\262')
-    , ('\264','\264')
-    , ('\266','\266')
-    , ('\268','\268')
-    , ('\270','\270')
-    , ('\272','\272')
-    , ('\274','\274')
-    , ('\276','\276')
-    , ('\278','\278')
-    , ('\280','\280')
-    , ('\282','\282')
-    , ('\284','\284')
-    , ('\286','\286')
-    , ('\288','\288')
-    , ('\290','\290')
-    , ('\292','\292')
-    , ('\294','\294')
-    , ('\296','\296')
-    , ('\298','\298')
-    , ('\300','\300')
-    , ('\302','\302')
-    , ('\304','\304')
-    , ('\306','\306')
-    , ('\308','\308')
-    , ('\310','\310')
-    , ('\313','\313')
-    , ('\315','\315')
-    , ('\317','\317')
-    , ('\319','\319')
-    , ('\321','\321')
-    , ('\323','\323')
-    , ('\325','\325')
-    , ('\327','\327')
-    , ('\330','\330')
-    , ('\332','\332')
-    , ('\334','\334')
-    , ('\336','\336')
-    , ('\338','\338')
-    , ('\340','\340')
-    , ('\342','\342')
-    , ('\344','\344')
-    , ('\346','\346')
-    , ('\348','\348')
-    , ('\350','\350')
-    , ('\352','\352')
-    , ('\354','\354')
-    , ('\356','\356')
-    , ('\358','\358')
-    , ('\360','\360')
-    , ('\362','\362')
-    , ('\364','\364')
-    , ('\366','\366')
-    , ('\368','\368')
-    , ('\370','\370')
-    , ('\372','\372')
-    , ('\374','\374')
-    , ('\376','\377')
-    , ('\379','\379')
-    , ('\381','\381')
-    , ('\385','\386')
-    , ('\388','\388')
-    , ('\390','\391')
-    , ('\393','\395')
-    , ('\398','\401')
-    , ('\403','\404')
-    , ('\406','\408')
-    , ('\412','\413')
-    , ('\415','\416')
-    , ('\418','\418')
-    , ('\420','\420')
-    , ('\422','\423')
-    , ('\425','\425')
-    , ('\428','\428')
-    , ('\430','\431')
-    , ('\433','\435')
-    , ('\437','\437')
-    , ('\439','\440')
-    , ('\444','\444')
-    , ('\452','\452')
-    , ('\455','\455')
-    , ('\458','\458')
-    , ('\461','\461')
-    , ('\463','\463')
-    , ('\465','\465')
-    , ('\467','\467')
-    , ('\469','\469')
-    , ('\471','\471')
-    , ('\473','\473')
-    , ('\475','\475')
-    , ('\478','\478')
-    , ('\480','\480')
-    , ('\482','\482')
-    , ('\484','\484')
-    , ('\486','\486')
-    , ('\488','\488')
-    , ('\490','\490')
-    , ('\492','\492')
-    , ('\494','\494')
-    , ('\497','\497')
-    , ('\500','\500')
-    , ('\502','\504')
-    , ('\506','\506')
-    , ('\508','\508')
-    , ('\510','\510')
-    , ('\512','\512')
-    , ('\514','\514')
-    , ('\516','\516')
-    , ('\518','\518')
-    , ('\520','\520')
-    , ('\522','\522')
-    , ('\524','\524')
-    , ('\526','\526')
-    , ('\528','\528')
-    , ('\530','\530')
-    , ('\532','\532')
-    , ('\534','\534')
-    , ('\536','\536')
-    , ('\538','\538')
-    , ('\540','\540')
-    , ('\542','\542')
-    , ('\544','\544')
-    , ('\546','\546')
-    , ('\548','\548')
-    , ('\550','\550')
-    , ('\552','\552')
-    , ('\554','\554')
-    , ('\556','\556')
-    , ('\558','\558')
-    , ('\560','\560')
-    , ('\562','\562')
-    , ('\570','\571')
-    , ('\573','\574')
-    , ('\577','\577')
-    , ('\579','\582')
-    , ('\584','\584')
-    , ('\586','\586')
-    , ('\588','\588')
-    , ('\590','\590')
-    , ('\880','\880')
-    , ('\882','\882')
-    , ('\886','\886')
-    , ('\902','\902')
-    , ('\904','\906')
-    , ('\908','\908')
-    , ('\910','\911')
-    , ('\913','\929')
-    , ('\931','\939')
-    , ('\975','\975')
-    , ('\978','\980')
-    , ('\984','\984')
-    , ('\986','\986')
-    , ('\988','\988')
-    , ('\990','\990')
-    , ('\992','\992')
-    , ('\994','\994')
-    , ('\996','\996')
-    , ('\998','\998')
-    , ('\1000','\1000')
-    , ('\1002','\1002')
-    , ('\1004','\1004')
-    , ('\1006','\1006')
-    , ('\1012','\1012')
-    , ('\1015','\1015')
-    , ('\1017','\1018')
-    , ('\1021','\1071')
-    , ('\1120','\1120')
-    , ('\1122','\1122')
-    , ('\1124','\1124')
-    , ('\1126','\1126')
-    , ('\1128','\1128')
-    , ('\1130','\1130')
-    , ('\1132','\1132')
-    , ('\1134','\1134')
-    , ('\1136','\1136')
-    , ('\1138','\1138')
-    , ('\1140','\1140')
-    , ('\1142','\1142')
-    , ('\1144','\1144')
-    , ('\1146','\1146')
-    , ('\1148','\1148')
-    , ('\1150','\1150')
-    , ('\1152','\1152')
-    , ('\1162','\1162')
-    , ('\1164','\1164')
-    , ('\1166','\1166')
-    , ('\1168','\1168')
-    , ('\1170','\1170')
-    , ('\1172','\1172')
-    , ('\1174','\1174')
-    , ('\1176','\1176')
-    , ('\1178','\1178')
-    , ('\1180','\1180')
-    , ('\1182','\1182')
-    , ('\1184','\1184')
-    , ('\1186','\1186')
-    , ('\1188','\1188')
-    , ('\1190','\1190')
-    , ('\1192','\1192')
-    , ('\1194','\1194')
-    , ('\1196','\1196')
-    , ('\1198','\1198')
-    , ('\1200','\1200')
-    , ('\1202','\1202')
-    , ('\1204','\1204')
-    , ('\1206','\1206')
-    , ('\1208','\1208')
-    , ('\1210','\1210')
-    , ('\1212','\1212')
-    , ('\1214','\1214')
-    , ('\1216','\1217')
-    , ('\1219','\1219')
-    , ('\1221','\1221')
-    , ('\1223','\1223')
-    , ('\1225','\1225')
-    , ('\1227','\1227')
-    , ('\1229','\1229')
-    , ('\1232','\1232')
-    , ('\1234','\1234')
-    , ('\1236','\1236')
-    , ('\1238','\1238')
-    , ('\1240','\1240')
-    , ('\1242','\1242')
-    , ('\1244','\1244')
-    , ('\1246','\1246')
-    , ('\1248','\1248')
-    , ('\1250','\1250')
-    , ('\1252','\1252')
-    , ('\1254','\1254')
-    , ('\1256','\1256')
-    , ('\1258','\1258')
-    , ('\1260','\1260')
-    , ('\1262','\1262')
-    , ('\1264','\1264')
-    , ('\1266','\1266')
-    , ('\1268','\1268')
-    , ('\1270','\1270')
-    , ('\1272','\1272')
-    , ('\1274','\1274')
-    , ('\1276','\1276')
-    , ('\1278','\1278')
-    , ('\1280','\1280')
-    , ('\1282','\1282')
-    , ('\1284','\1284')
-    , ('\1286','\1286')
-    , ('\1288','\1288')
-    , ('\1290','\1290')
-    , ('\1292','\1292')
-    , ('\1294','\1294')
-    , ('\1296','\1296')
-    , ('\1298','\1298')
-    , ('\1300','\1300')
-    , ('\1302','\1302')
-    , ('\1304','\1304')
-    , ('\1306','\1306')
-    , ('\1308','\1308')
-    , ('\1310','\1310')
-    , ('\1312','\1312')
-    , ('\1314','\1314')
-    , ('\1316','\1316')
-    , ('\1329','\1366')
-    , ('\4256','\4293')
-    , ('\7680','\7680')
-    , ('\7682','\7682')
-    , ('\7684','\7684')
-    , ('\7686','\7686')
-    , ('\7688','\7688')
-    , ('\7690','\7690')
-    , ('\7692','\7692')
-    , ('\7694','\7694')
-    , ('\7696','\7696')
-    , ('\7698','\7698')
-    , ('\7700','\7700')
-    , ('\7702','\7702')
-    , ('\7704','\7704')
-    , ('\7706','\7706')
-    , ('\7708','\7708')
-    , ('\7710','\7710')
-    , ('\7712','\7712')
-    , ('\7714','\7714')
-    , ('\7716','\7716')
-    , ('\7718','\7718')
-    , ('\7720','\7720')
-    , ('\7722','\7722')
-    , ('\7724','\7724')
-    , ('\7726','\7726')
-    , ('\7728','\7728')
-    , ('\7730','\7730')
-    , ('\7732','\7732')
-    , ('\7734','\7734')
-    , ('\7736','\7736')
-    , ('\7738','\7738')
-    , ('\7740','\7740')
-    , ('\7742','\7742')
-    , ('\7744','\7744')
-    , ('\7746','\7746')
-    , ('\7748','\7748')
-    , ('\7750','\7750')
-    , ('\7752','\7752')
-    , ('\7754','\7754')
-    , ('\7756','\7756')
-    , ('\7758','\7758')
-    , ('\7760','\7760')
-    , ('\7762','\7762')
-    , ('\7764','\7764')
-    , ('\7766','\7766')
-    , ('\7768','\7768')
-    , ('\7770','\7770')
-    , ('\7772','\7772')
-    , ('\7774','\7774')
-    , ('\7776','\7776')
-    , ('\7778','\7778')
-    , ('\7780','\7780')
-    , ('\7782','\7782')
-    , ('\7784','\7784')
-    , ('\7786','\7786')
-    , ('\7788','\7788')
-    , ('\7790','\7790')
-    , ('\7792','\7792')
-    , ('\7794','\7794')
-    , ('\7796','\7796')
-    , ('\7798','\7798')
-    , ('\7800','\7800')
-    , ('\7802','\7802')
-    , ('\7804','\7804')
-    , ('\7806','\7806')
-    , ('\7808','\7808')
-    , ('\7810','\7810')
-    , ('\7812','\7812')
-    , ('\7814','\7814')
-    , ('\7816','\7816')
-    , ('\7818','\7818')
-    , ('\7820','\7820')
-    , ('\7822','\7822')
-    , ('\7824','\7824')
-    , ('\7826','\7826')
-    , ('\7828','\7828')
-    , ('\7838','\7838')
-    , ('\7840','\7840')
-    , ('\7842','\7842')
-    , ('\7844','\7844')
-    , ('\7846','\7846')
-    , ('\7848','\7848')
-    , ('\7850','\7850')
-    , ('\7852','\7852')
-    , ('\7854','\7854')
-    , ('\7856','\7856')
-    , ('\7858','\7858')
-    , ('\7860','\7860')
-    , ('\7862','\7862')
-    , ('\7864','\7864')
-    , ('\7866','\7866')
-    , ('\7868','\7868')
-    , ('\7870','\7870')
-    , ('\7872','\7872')
-    , ('\7874','\7874')
-    , ('\7876','\7876')
-    , ('\7878','\7878')
-    , ('\7880','\7880')
-    , ('\7882','\7882')
-    , ('\7884','\7884')
-    , ('\7886','\7886')
-    , ('\7888','\7888')
-    , ('\7890','\7890')
-    , ('\7892','\7892')
-    , ('\7894','\7894')
-    , ('\7896','\7896')
-    , ('\7898','\7898')
-    , ('\7900','\7900')
-    , ('\7902','\7902')
-    , ('\7904','\7904')
-    , ('\7906','\7906')
-    , ('\7908','\7908')
-    , ('\7910','\7910')
-    , ('\7912','\7912')
-    , ('\7914','\7914')
-    , ('\7916','\7916')
-    , ('\7918','\7918')
-    , ('\7920','\7920')
-    , ('\7922','\7922')
-    , ('\7924','\7924')
-    , ('\7926','\7926')
-    , ('\7928','\7928')
-    , ('\7930','\7930')
-    , ('\7932','\7932')
-    , ('\7934','\7934')
-    , ('\7944','\7951')
-    , ('\7960','\7965')
-    , ('\7976','\7983')
-    , ('\7992','\7999')
-    , ('\8008','\8013')
-    , ('\8025','\8025')
-    , ('\8027','\8027')
-    , ('\8029','\8029')
-    , ('\8031','\8031')
-    , ('\8040','\8047')
-    , ('\8120','\8123')
-    , ('\8136','\8139')
-    , ('\8152','\8155')
-    , ('\8168','\8172')
-    , ('\8184','\8187')
-    , ('\8450','\8450')
-    , ('\8455','\8455')
-    , ('\8459','\8461')
-    , ('\8464','\8466')
-    , ('\8469','\8469')
-    , ('\8473','\8477')
-    , ('\8484','\8484')
-    , ('\8486','\8486')
-    , ('\8488','\8488')
-    , ('\8490','\8493')
-    , ('\8496','\8499')
-    , ('\8510','\8511')
-    , ('\8517','\8517')
-    , ('\8579','\8579')
-    , ('\11264','\11310')
-    , ('\11360','\11360')
-    , ('\11362','\11364')
-    , ('\11367','\11367')
-    , ('\11369','\11369')
-    , ('\11371','\11371')
-    , ('\11373','\11376')
-    , ('\11378','\11378')
-    , ('\11381','\11381')
-    , ('\11390','\11392')
-    , ('\11394','\11394')
-    , ('\11396','\11396')
-    , ('\11398','\11398')
-    , ('\11400','\11400')
-    , ('\11402','\11402')
-    , ('\11404','\11404')
-    , ('\11406','\11406')
-    , ('\11408','\11408')
-    , ('\11410','\11410')
-    , ('\11412','\11412')
-    , ('\11414','\11414')
-    , ('\11416','\11416')
-    , ('\11418','\11418')
-    , ('\11420','\11420')
-    , ('\11422','\11422')
-    , ('\11424','\11424')
-    , ('\11426','\11426')
-    , ('\11428','\11428')
-    , ('\11430','\11430')
-    , ('\11432','\11432')
-    , ('\11434','\11434')
-    , ('\11436','\11436')
-    , ('\11438','\11438')
-    , ('\11440','\11440')
-    , ('\11442','\11442')
-    , ('\11444','\11444')
-    , ('\11446','\11446')
-    , ('\11448','\11448')
-    , ('\11450','\11450')
-    , ('\11452','\11452')
-    , ('\11454','\11454')
-    , ('\11456','\11456')
-    , ('\11458','\11458')
-    , ('\11460','\11460')
-    , ('\11462','\11462')
-    , ('\11464','\11464')
-    , ('\11466','\11466')
-    , ('\11468','\11468')
-    , ('\11470','\11470')
-    , ('\11472','\11472')
-    , ('\11474','\11474')
-    , ('\11476','\11476')
-    , ('\11478','\11478')
-    , ('\11480','\11480')
-    , ('\11482','\11482')
-    , ('\11484','\11484')
-    , ('\11486','\11486')
-    , ('\11488','\11488')
-    , ('\11490','\11490')
-    , ('\11499','\11499')
-    , ('\11501','\11501')
-    , ('\42560','\42560')
-    , ('\42562','\42562')
-    , ('\42564','\42564')
-    , ('\42566','\42566')
-    , ('\42568','\42568')
-    , ('\42570','\42570')
-    , ('\42572','\42572')
-    , ('\42574','\42574')
-    , ('\42576','\42576')
-    , ('\42578','\42578')
-    , ('\42580','\42580')
-    , ('\42582','\42582')
-    , ('\42584','\42584')
-    , ('\42586','\42586')
-    , ('\42588','\42588')
-    , ('\42590','\42590')
-    , ('\42594','\42594')
-    , ('\42596','\42596')
-    , ('\42598','\42598')
-    , ('\42600','\42600')
-    , ('\42602','\42602')
-    , ('\42604','\42604')
-    , ('\42624','\42624')
-    , ('\42626','\42626')
-    , ('\42628','\42628')
-    , ('\42630','\42630')
-    , ('\42632','\42632')
-    , ('\42634','\42634')
-    , ('\42636','\42636')
-    , ('\42638','\42638')
-    , ('\42640','\42640')
-    , ('\42642','\42642')
-    , ('\42644','\42644')
-    , ('\42646','\42646')
-    , ('\42786','\42786')
-    , ('\42788','\42788')
-    , ('\42790','\42790')
-    , ('\42792','\42792')
-    , ('\42794','\42794')
-    , ('\42796','\42796')
-    , ('\42798','\42798')
-    , ('\42802','\42802')
-    , ('\42804','\42804')
-    , ('\42806','\42806')
-    , ('\42808','\42808')
-    , ('\42810','\42810')
-    , ('\42812','\42812')
-    , ('\42814','\42814')
-    , ('\42816','\42816')
-    , ('\42818','\42818')
-    , ('\42820','\42820')
-    , ('\42822','\42822')
-    , ('\42824','\42824')
-    , ('\42826','\42826')
-    , ('\42828','\42828')
-    , ('\42830','\42830')
-    , ('\42832','\42832')
-    , ('\42834','\42834')
-    , ('\42836','\42836')
-    , ('\42838','\42838')
-    , ('\42840','\42840')
-    , ('\42842','\42842')
-    , ('\42844','\42844')
-    , ('\42846','\42846')
-    , ('\42848','\42848')
-    , ('\42850','\42850')
-    , ('\42852','\42852')
-    , ('\42854','\42854')
-    , ('\42856','\42856')
-    , ('\42858','\42858')
-    , ('\42860','\42860')
-    , ('\42862','\42862')
-    , ('\42873','\42873')
-    , ('\42875','\42875')
-    , ('\42877','\42878')
-    , ('\42880','\42880')
-    , ('\42882','\42882')
-    , ('\42884','\42884')
-    , ('\42886','\42886')
-    , ('\42891','\42891')
-    , ('\65313','\65338')
-    , ('\66560','\66599')
-    , ('\119808','\119833')
-    , ('\119860','\119885')
-    , ('\119912','\119937')
-    , ('\119964','\119964')
-    , ('\119966','\119967')
-    , ('\119970','\119970')
-    , ('\119973','\119974')
-    , ('\119977','\119980')
-    , ('\119982','\119989')
-    , ('\120016','\120041')
-    , ('\120068','\120069')
-    , ('\120071','\120074')
-    , ('\120077','\120084')
-    , ('\120086','\120092')
-    , ('\120120','\120121')
-    , ('\120123','\120126')
-    , ('\120128','\120132')
-    , ('\120134','\120134')
-    , ('\120138','\120144')
-    , ('\120172','\120197')
-    , ('\120224','\120249')
-    , ('\120276','\120301')
-    , ('\120328','\120353')
-    , ('\120380','\120405')
-    , ('\120432','\120457')
-    , ('\120488','\120512')
-    , ('\120546','\120570')
-    , ('\120604','\120628')
-    , ('\120662','\120686')
-    , ('\120720','\120744')
-    , ('\120778','\120778')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeM      :: Char -> Bool
-isUnicodeM c
-  = isInList c
-    [ ('\768','\879')
-    , ('\1155','\1161')
-    , ('\1425','\1469')
-    , ('\1471','\1471')
-    , ('\1473','\1474')
-    , ('\1476','\1477')
-    , ('\1479','\1479')
-    , ('\1552','\1562')
-    , ('\1611','\1630')
-    , ('\1648','\1648')
-    , ('\1750','\1756')
-    , ('\1758','\1764')
-    , ('\1767','\1768')
-    , ('\1770','\1773')
-    , ('\1809','\1809')
-    , ('\1840','\1866')
-    , ('\1958','\1968')
-    , ('\2027','\2035')
-    , ('\2070','\2073')
-    , ('\2075','\2083')
-    , ('\2085','\2087')
-    , ('\2089','\2093')
-    , ('\2304','\2307')
-    , ('\2364','\2364')
-    , ('\2366','\2382')
-    , ('\2385','\2389')
-    , ('\2402','\2403')
-    , ('\2433','\2435')
-    , ('\2492','\2492')
-    , ('\2494','\2500')
-    , ('\2503','\2504')
-    , ('\2507','\2509')
-    , ('\2519','\2519')
-    , ('\2530','\2531')
-    , ('\2561','\2563')
-    , ('\2620','\2620')
-    , ('\2622','\2626')
-    , ('\2631','\2632')
-    , ('\2635','\2637')
-    , ('\2641','\2641')
-    , ('\2672','\2673')
-    , ('\2677','\2677')
-    , ('\2689','\2691')
-    , ('\2748','\2748')
-    , ('\2750','\2757')
-    , ('\2759','\2761')
-    , ('\2763','\2765')
-    , ('\2786','\2787')
-    , ('\2817','\2819')
-    , ('\2876','\2876')
-    , ('\2878','\2884')
-    , ('\2887','\2888')
-    , ('\2891','\2893')
-    , ('\2902','\2903')
-    , ('\2914','\2915')
-    , ('\2946','\2946')
-    , ('\3006','\3010')
-    , ('\3014','\3016')
-    , ('\3018','\3021')
-    , ('\3031','\3031')
-    , ('\3073','\3075')
-    , ('\3134','\3140')
-    , ('\3142','\3144')
-    , ('\3146','\3149')
-    , ('\3157','\3158')
-    , ('\3170','\3171')
-    , ('\3202','\3203')
-    , ('\3260','\3260')
-    , ('\3262','\3268')
-    , ('\3270','\3272')
-    , ('\3274','\3277')
-    , ('\3285','\3286')
-    , ('\3298','\3299')
-    , ('\3330','\3331')
-    , ('\3390','\3396')
-    , ('\3398','\3400')
-    , ('\3402','\3405')
-    , ('\3415','\3415')
-    , ('\3426','\3427')
-    , ('\3458','\3459')
-    , ('\3530','\3530')
-    , ('\3535','\3540')
-    , ('\3542','\3542')
-    , ('\3544','\3551')
-    , ('\3570','\3571')
-    , ('\3633','\3633')
-    , ('\3636','\3642')
-    , ('\3655','\3662')
-    , ('\3761','\3761')
-    , ('\3764','\3769')
-    , ('\3771','\3772')
-    , ('\3784','\3789')
-    , ('\3864','\3865')
-    , ('\3893','\3893')
-    , ('\3895','\3895')
-    , ('\3897','\3897')
-    , ('\3902','\3903')
-    , ('\3953','\3972')
-    , ('\3974','\3975')
-    , ('\3984','\3991')
-    , ('\3993','\4028')
-    , ('\4038','\4038')
-    , ('\4139','\4158')
-    , ('\4182','\4185')
-    , ('\4190','\4192')
-    , ('\4194','\4196')
-    , ('\4199','\4205')
-    , ('\4209','\4212')
-    , ('\4226','\4237')
-    , ('\4239','\4239')
-    , ('\4250','\4253')
-    , ('\4959','\4959')
-    , ('\5906','\5908')
-    , ('\5938','\5940')
-    , ('\5970','\5971')
-    , ('\6002','\6003')
-    , ('\6070','\6099')
-    , ('\6109','\6109')
-    , ('\6155','\6157')
-    , ('\6313','\6313')
-    , ('\6432','\6443')
-    , ('\6448','\6459')
-    , ('\6576','\6592')
-    , ('\6600','\6601')
-    , ('\6679','\6683')
-    , ('\6741','\6750')
-    , ('\6752','\6780')
-    , ('\6783','\6783')
-    , ('\6912','\6916')
-    , ('\6964','\6980')
-    , ('\7019','\7027')
-    , ('\7040','\7042')
-    , ('\7073','\7082')
-    , ('\7204','\7223')
-    , ('\7376','\7378')
-    , ('\7380','\7400')
-    , ('\7405','\7405')
-    , ('\7410','\7410')
-    , ('\7616','\7654')
-    , ('\7677','\7679')
-    , ('\8400','\8432')
-    , ('\11503','\11505')
-    , ('\11744','\11775')
-    , ('\12330','\12335')
-    , ('\12441','\12442')
-    , ('\42607','\42610')
-    , ('\42620','\42621')
-    , ('\42736','\42737')
-    , ('\43010','\43010')
-    , ('\43014','\43014')
-    , ('\43019','\43019')
-    , ('\43043','\43047')
-    , ('\43136','\43137')
-    , ('\43188','\43204')
-    , ('\43232','\43249')
-    , ('\43302','\43309')
-    , ('\43335','\43347')
-    , ('\43392','\43395')
-    , ('\43443','\43456')
-    , ('\43561','\43574')
-    , ('\43587','\43587')
-    , ('\43596','\43597')
-    , ('\43643','\43643')
-    , ('\43696','\43696')
-    , ('\43698','\43700')
-    , ('\43703','\43704')
-    , ('\43710','\43711')
-    , ('\43713','\43713')
-    , ('\44003','\44010')
-    , ('\44012','\44013')
-    , ('\64286','\64286')
-    , ('\65024','\65039')
-    , ('\65056','\65062')
-    , ('\66045','\66045')
-    , ('\68097','\68099')
-    , ('\68101','\68102')
-    , ('\68108','\68111')
-    , ('\68152','\68154')
-    , ('\68159','\68159')
-    , ('\69760','\69762')
-    , ('\69808','\69818')
-    , ('\119141','\119145')
-    , ('\119149','\119154')
-    , ('\119163','\119170')
-    , ('\119173','\119179')
-    , ('\119210','\119213')
-    , ('\119362','\119364')
-    , ('\917760','\917999')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeMc     :: Char -> Bool
-isUnicodeMc c
-  = isInList c
-    [ ('\2307','\2307')
-    , ('\2366','\2368')
-    , ('\2377','\2380')
-    , ('\2382','\2382')
-    , ('\2434','\2435')
-    , ('\2494','\2496')
-    , ('\2503','\2504')
-    , ('\2507','\2508')
-    , ('\2519','\2519')
-    , ('\2563','\2563')
-    , ('\2622','\2624')
-    , ('\2691','\2691')
-    , ('\2750','\2752')
-    , ('\2761','\2761')
-    , ('\2763','\2764')
-    , ('\2818','\2819')
-    , ('\2878','\2878')
-    , ('\2880','\2880')
-    , ('\2887','\2888')
-    , ('\2891','\2892')
-    , ('\2903','\2903')
-    , ('\3006','\3007')
-    , ('\3009','\3010')
-    , ('\3014','\3016')
-    , ('\3018','\3020')
-    , ('\3031','\3031')
-    , ('\3073','\3075')
-    , ('\3137','\3140')
-    , ('\3202','\3203')
-    , ('\3262','\3262')
-    , ('\3264','\3268')
-    , ('\3271','\3272')
-    , ('\3274','\3275')
-    , ('\3285','\3286')
-    , ('\3330','\3331')
-    , ('\3390','\3392')
-    , ('\3398','\3400')
-    , ('\3402','\3404')
-    , ('\3415','\3415')
-    , ('\3458','\3459')
-    , ('\3535','\3537')
-    , ('\3544','\3551')
-    , ('\3570','\3571')
-    , ('\3902','\3903')
-    , ('\3967','\3967')
-    , ('\4139','\4140')
-    , ('\4145','\4145')
-    , ('\4152','\4152')
-    , ('\4155','\4156')
-    , ('\4182','\4183')
-    , ('\4194','\4196')
-    , ('\4199','\4205')
-    , ('\4227','\4228')
-    , ('\4231','\4236')
-    , ('\4239','\4239')
-    , ('\4250','\4252')
-    , ('\6070','\6070')
-    , ('\6078','\6085')
-    , ('\6087','\6088')
-    , ('\6435','\6438')
-    , ('\6441','\6443')
-    , ('\6448','\6449')
-    , ('\6451','\6456')
-    , ('\6576','\6592')
-    , ('\6600','\6601')
-    , ('\6681','\6683')
-    , ('\6741','\6741')
-    , ('\6743','\6743')
-    , ('\6753','\6753')
-    , ('\6755','\6756')
-    , ('\6765','\6770')
-    , ('\6916','\6916')
-    , ('\6965','\6965')
-    , ('\6971','\6971')
-    , ('\6973','\6977')
-    , ('\6979','\6980')
-    , ('\7042','\7042')
-    , ('\7073','\7073')
-    , ('\7078','\7079')
-    , ('\7082','\7082')
-    , ('\7204','\7211')
-    , ('\7220','\7221')
-    , ('\7393','\7393')
-    , ('\7410','\7410')
-    , ('\43043','\43044')
-    , ('\43047','\43047')
-    , ('\43136','\43137')
-    , ('\43188','\43203')
-    , ('\43346','\43347')
-    , ('\43395','\43395')
-    , ('\43444','\43445')
-    , ('\43450','\43451')
-    , ('\43453','\43456')
-    , ('\43567','\43568')
-    , ('\43571','\43572')
-    , ('\43597','\43597')
-    , ('\43643','\43643')
-    , ('\44003','\44004')
-    , ('\44006','\44007')
-    , ('\44009','\44010')
-    , ('\44012','\44012')
-    , ('\69762','\69762')
-    , ('\69808','\69810')
-    , ('\69815','\69816')
-    , ('\119141','\119142')
-    , ('\119149','\119154')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeMe     :: Char -> Bool
-isUnicodeMe c
-  = isInList c
-    [ ('\1160','\1161')
-    , ('\1758','\1758')
-    , ('\8413','\8416')
-    , ('\8418','\8420')
-    , ('\42608','\42610')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeMn     :: Char -> Bool
-isUnicodeMn c
-  = isInList c
-    [ ('\768','\879')
-    , ('\1155','\1159')
-    , ('\1425','\1469')
-    , ('\1471','\1471')
-    , ('\1473','\1474')
-    , ('\1476','\1477')
-    , ('\1479','\1479')
-    , ('\1552','\1562')
-    , ('\1611','\1630')
-    , ('\1648','\1648')
-    , ('\1750','\1756')
-    , ('\1759','\1764')
-    , ('\1767','\1768')
-    , ('\1770','\1773')
-    , ('\1809','\1809')
-    , ('\1840','\1866')
-    , ('\1958','\1968')
-    , ('\2027','\2035')
-    , ('\2070','\2073')
-    , ('\2075','\2083')
-    , ('\2085','\2087')
-    , ('\2089','\2093')
-    , ('\2304','\2306')
-    , ('\2364','\2364')
-    , ('\2369','\2376')
-    , ('\2381','\2381')
-    , ('\2385','\2389')
-    , ('\2402','\2403')
-    , ('\2433','\2433')
-    , ('\2492','\2492')
-    , ('\2497','\2500')
-    , ('\2509','\2509')
-    , ('\2530','\2531')
-    , ('\2561','\2562')
-    , ('\2620','\2620')
-    , ('\2625','\2626')
-    , ('\2631','\2632')
-    , ('\2635','\2637')
-    , ('\2641','\2641')
-    , ('\2672','\2673')
-    , ('\2677','\2677')
-    , ('\2689','\2690')
-    , ('\2748','\2748')
-    , ('\2753','\2757')
-    , ('\2759','\2760')
-    , ('\2765','\2765')
-    , ('\2786','\2787')
-    , ('\2817','\2817')
-    , ('\2876','\2876')
-    , ('\2879','\2879')
-    , ('\2881','\2884')
-    , ('\2893','\2893')
-    , ('\2902','\2902')
-    , ('\2914','\2915')
-    , ('\2946','\2946')
-    , ('\3008','\3008')
-    , ('\3021','\3021')
-    , ('\3134','\3136')
-    , ('\3142','\3144')
-    , ('\3146','\3149')
-    , ('\3157','\3158')
-    , ('\3170','\3171')
-    , ('\3260','\3260')
-    , ('\3263','\3263')
-    , ('\3270','\3270')
-    , ('\3276','\3277')
-    , ('\3298','\3299')
-    , ('\3393','\3396')
-    , ('\3405','\3405')
-    , ('\3426','\3427')
-    , ('\3530','\3530')
-    , ('\3538','\3540')
-    , ('\3542','\3542')
-    , ('\3633','\3633')
-    , ('\3636','\3642')
-    , ('\3655','\3662')
-    , ('\3761','\3761')
-    , ('\3764','\3769')
-    , ('\3771','\3772')
-    , ('\3784','\3789')
-    , ('\3864','\3865')
-    , ('\3893','\3893')
-    , ('\3895','\3895')
-    , ('\3897','\3897')
-    , ('\3953','\3966')
-    , ('\3968','\3972')
-    , ('\3974','\3975')
-    , ('\3984','\3991')
-    , ('\3993','\4028')
-    , ('\4038','\4038')
-    , ('\4141','\4144')
-    , ('\4146','\4151')
-    , ('\4153','\4154')
-    , ('\4157','\4158')
-    , ('\4184','\4185')
-    , ('\4190','\4192')
-    , ('\4209','\4212')
-    , ('\4226','\4226')
-    , ('\4229','\4230')
-    , ('\4237','\4237')
-    , ('\4253','\4253')
-    , ('\4959','\4959')
-    , ('\5906','\5908')
-    , ('\5938','\5940')
-    , ('\5970','\5971')
-    , ('\6002','\6003')
-    , ('\6071','\6077')
-    , ('\6086','\6086')
-    , ('\6089','\6099')
-    , ('\6109','\6109')
-    , ('\6155','\6157')
-    , ('\6313','\6313')
-    , ('\6432','\6434')
-    , ('\6439','\6440')
-    , ('\6450','\6450')
-    , ('\6457','\6459')
-    , ('\6679','\6680')
-    , ('\6742','\6742')
-    , ('\6744','\6750')
-    , ('\6752','\6752')
-    , ('\6754','\6754')
-    , ('\6757','\6764')
-    , ('\6771','\6780')
-    , ('\6783','\6783')
-    , ('\6912','\6915')
-    , ('\6964','\6964')
-    , ('\6966','\6970')
-    , ('\6972','\6972')
-    , ('\6978','\6978')
-    , ('\7019','\7027')
-    , ('\7040','\7041')
-    , ('\7074','\7077')
-    , ('\7080','\7081')
-    , ('\7212','\7219')
-    , ('\7222','\7223')
-    , ('\7376','\7378')
-    , ('\7380','\7392')
-    , ('\7394','\7400')
-    , ('\7405','\7405')
-    , ('\7616','\7654')
-    , ('\7677','\7679')
-    , ('\8400','\8412')
-    , ('\8417','\8417')
-    , ('\8421','\8432')
-    , ('\11503','\11505')
-    , ('\11744','\11775')
-    , ('\12330','\12335')
-    , ('\12441','\12442')
-    , ('\42607','\42607')
-    , ('\42620','\42621')
-    , ('\42736','\42737')
-    , ('\43010','\43010')
-    , ('\43014','\43014')
-    , ('\43019','\43019')
-    , ('\43045','\43046')
-    , ('\43204','\43204')
-    , ('\43232','\43249')
-    , ('\43302','\43309')
-    , ('\43335','\43345')
-    , ('\43392','\43394')
-    , ('\43443','\43443')
-    , ('\43446','\43449')
-    , ('\43452','\43452')
-    , ('\43561','\43566')
-    , ('\43569','\43570')
-    , ('\43573','\43574')
-    , ('\43587','\43587')
-    , ('\43596','\43596')
-    , ('\43696','\43696')
-    , ('\43698','\43700')
-    , ('\43703','\43704')
-    , ('\43710','\43711')
-    , ('\43713','\43713')
-    , ('\44005','\44005')
-    , ('\44008','\44008')
-    , ('\44013','\44013')
-    , ('\64286','\64286')
-    , ('\65024','\65039')
-    , ('\65056','\65062')
-    , ('\66045','\66045')
-    , ('\68097','\68099')
-    , ('\68101','\68102')
-    , ('\68108','\68111')
-    , ('\68152','\68154')
-    , ('\68159','\68159')
-    , ('\69760','\69761')
-    , ('\69811','\69814')
-    , ('\69817','\69818')
-    , ('\119143','\119145')
-    , ('\119163','\119170')
-    , ('\119173','\119179')
-    , ('\119210','\119213')
-    , ('\119362','\119364')
-    , ('\917760','\917999')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeN      :: Char -> Bool
-isUnicodeN c
-  = isInList c
-    [ ('0','9')
-    , ('\178','\179')
-    , ('\185','\185')
-    , ('\188','\190')
-    , ('\1632','\1641')
-    , ('\1776','\1785')
-    , ('\1984','\1993')
-    , ('\2406','\2415')
-    , ('\2534','\2543')
-    , ('\2548','\2553')
-    , ('\2662','\2671')
-    , ('\2790','\2799')
-    , ('\2918','\2927')
-    , ('\3046','\3058')
-    , ('\3174','\3183')
-    , ('\3192','\3198')
-    , ('\3302','\3311')
-    , ('\3430','\3445')
-    , ('\3664','\3673')
-    , ('\3792','\3801')
-    , ('\3872','\3891')
-    , ('\4160','\4169')
-    , ('\4240','\4249')
-    , ('\4969','\4988')
-    , ('\5870','\5872')
-    , ('\6112','\6121')
-    , ('\6128','\6137')
-    , ('\6160','\6169')
-    , ('\6470','\6479')
-    , ('\6608','\6618')
-    , ('\6784','\6793')
-    , ('\6800','\6809')
-    , ('\6992','\7001')
-    , ('\7088','\7097')
-    , ('\7232','\7241')
-    , ('\7248','\7257')
-    , ('\8304','\8304')
-    , ('\8308','\8313')
-    , ('\8320','\8329')
-    , ('\8528','\8578')
-    , ('\8581','\8585')
-    , ('\9312','\9371')
-    , ('\9450','\9471')
-    , ('\10102','\10131')
-    , ('\11517','\11517')
-    , ('\12295','\12295')
-    , ('\12321','\12329')
-    , ('\12344','\12346')
-    , ('\12690','\12693')
-    , ('\12832','\12841')
-    , ('\12881','\12895')
-    , ('\12928','\12937')
-    , ('\12977','\12991')
-    , ('\42528','\42537')
-    , ('\42726','\42735')
-    , ('\43056','\43061')
-    , ('\43216','\43225')
-    , ('\43264','\43273')
-    , ('\43472','\43481')
-    , ('\43600','\43609')
-    , ('\44016','\44025')
-    , ('\65296','\65305')
-    , ('\65799','\65843')
-    , ('\65856','\65912')
-    , ('\65930','\65930')
-    , ('\66336','\66339')
-    , ('\66369','\66369')
-    , ('\66378','\66378')
-    , ('\66513','\66517')
-    , ('\66720','\66729')
-    , ('\67672','\67679')
-    , ('\67862','\67867')
-    , ('\68160','\68167')
-    , ('\68221','\68222')
-    , ('\68440','\68447')
-    , ('\68472','\68479')
-    , ('\69216','\69246')
-    , ('\74752','\74850')
-    , ('\119648','\119665')
-    , ('\120782','\120831')
-    , ('\127232','\127242')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeNd     :: Char -> Bool
-isUnicodeNd c
-  = isInList c
-    [ ('0','9')
-    , ('\1632','\1641')
-    , ('\1776','\1785')
-    , ('\1984','\1993')
-    , ('\2406','\2415')
-    , ('\2534','\2543')
-    , ('\2662','\2671')
-    , ('\2790','\2799')
-    , ('\2918','\2927')
-    , ('\3046','\3055')
-    , ('\3174','\3183')
-    , ('\3302','\3311')
-    , ('\3430','\3439')
-    , ('\3664','\3673')
-    , ('\3792','\3801')
-    , ('\3872','\3881')
-    , ('\4160','\4169')
-    , ('\4240','\4249')
-    , ('\6112','\6121')
-    , ('\6160','\6169')
-    , ('\6470','\6479')
-    , ('\6608','\6618')
-    , ('\6784','\6793')
-    , ('\6800','\6809')
-    , ('\6992','\7001')
-    , ('\7088','\7097')
-    , ('\7232','\7241')
-    , ('\7248','\7257')
-    , ('\42528','\42537')
-    , ('\43216','\43225')
-    , ('\43264','\43273')
-    , ('\43472','\43481')
-    , ('\43600','\43609')
-    , ('\44016','\44025')
-    , ('\65296','\65305')
-    , ('\66720','\66729')
-    , ('\120782','\120831')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeNl     :: Char -> Bool
-isUnicodeNl c
-  = isInList c
-    [ ('\5870','\5872')
-    , ('\8544','\8578')
-    , ('\8581','\8584')
-    , ('\12295','\12295')
-    , ('\12321','\12329')
-    , ('\12344','\12346')
-    , ('\42726','\42735')
-    , ('\65856','\65908')
-    , ('\66369','\66369')
-    , ('\66378','\66378')
-    , ('\66513','\66517')
-    , ('\74752','\74850')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeNo     :: Char -> Bool
-isUnicodeNo c
-  = isInList c
-    [ ('\178','\179')
-    , ('\185','\185')
-    , ('\188','\190')
-    , ('\2548','\2553')
-    , ('\3056','\3058')
-    , ('\3192','\3198')
-    , ('\3440','\3445')
-    , ('\3882','\3891')
-    , ('\4969','\4988')
-    , ('\6128','\6137')
-    , ('\8304','\8304')
-    , ('\8308','\8313')
-    , ('\8320','\8329')
-    , ('\8528','\8543')
-    , ('\8585','\8585')
-    , ('\9312','\9371')
-    , ('\9450','\9471')
-    , ('\10102','\10131')
-    , ('\11517','\11517')
-    , ('\12690','\12693')
-    , ('\12832','\12841')
-    , ('\12881','\12895')
-    , ('\12928','\12937')
-    , ('\12977','\12991')
-    , ('\43056','\43061')
-    , ('\65799','\65843')
-    , ('\65909','\65912')
-    , ('\65930','\65930')
-    , ('\66336','\66339')
-    , ('\67672','\67679')
-    , ('\67862','\67867')
-    , ('\68160','\68167')
-    , ('\68221','\68222')
-    , ('\68440','\68447')
-    , ('\68472','\68479')
-    , ('\69216','\69246')
-    , ('\119648','\119665')
-    , ('\127232','\127242')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeP      :: Char -> Bool
-isUnicodeP c
-  = isInList c
-    [ ('!','#')
-    , ('%','*')
-    , (',','/')
-    , (':',';')
-    , ('?','@')
-    , ('[',']')
-    , ('_','_')
-    , ('{','{')
-    , ('}','}')
-    , ('\161','\161')
-    , ('\171','\171')
-    , ('\183','\183')
-    , ('\187','\187')
-    , ('\191','\191')
-    , ('\894','\894')
-    , ('\903','\903')
-    , ('\1370','\1375')
-    , ('\1417','\1418')
-    , ('\1470','\1470')
-    , ('\1472','\1472')
-    , ('\1475','\1475')
-    , ('\1478','\1478')
-    , ('\1523','\1524')
-    , ('\1545','\1546')
-    , ('\1548','\1549')
-    , ('\1563','\1563')
-    , ('\1566','\1567')
-    , ('\1642','\1645')
-    , ('\1748','\1748')
-    , ('\1792','\1805')
-    , ('\2039','\2041')
-    , ('\2096','\2110')
-    , ('\2404','\2405')
-    , ('\2416','\2416')
-    , ('\3572','\3572')
-    , ('\3663','\3663')
-    , ('\3674','\3675')
-    , ('\3844','\3858')
-    , ('\3898','\3901')
-    , ('\3973','\3973')
-    , ('\4048','\4052')
-    , ('\4170','\4175')
-    , ('\4347','\4347')
-    , ('\4961','\4968')
-    , ('\5120','\5120')
-    , ('\5741','\5742')
-    , ('\5787','\5788')
-    , ('\5867','\5869')
-    , ('\5941','\5942')
-    , ('\6100','\6102')
-    , ('\6104','\6106')
-    , ('\6144','\6154')
-    , ('\6468','\6469')
-    , ('\6622','\6623')
-    , ('\6686','\6687')
-    , ('\6816','\6822')
-    , ('\6824','\6829')
-    , ('\7002','\7008')
-    , ('\7227','\7231')
-    , ('\7294','\7295')
-    , ('\7379','\7379')
-    , ('\8208','\8231')
-    , ('\8240','\8259')
-    , ('\8261','\8273')
-    , ('\8275','\8286')
-    , ('\8317','\8318')
-    , ('\8333','\8334')
-    , ('\9001','\9002')
-    , ('\10088','\10101')
-    , ('\10181','\10182')
-    , ('\10214','\10223')
-    , ('\10627','\10648')
-    , ('\10712','\10715')
-    , ('\10748','\10749')
-    , ('\11513','\11516')
-    , ('\11518','\11519')
-    , ('\11776','\11822')
-    , ('\11824','\11825')
-    , ('\12289','\12291')
-    , ('\12296','\12305')
-    , ('\12308','\12319')
-    , ('\12336','\12336')
-    , ('\12349','\12349')
-    , ('\12448','\12448')
-    , ('\12539','\12539')
-    , ('\42238','\42239')
-    , ('\42509','\42511')
-    , ('\42611','\42611')
-    , ('\42622','\42622')
-    , ('\42738','\42743')
-    , ('\43124','\43127')
-    , ('\43214','\43215')
-    , ('\43256','\43258')
-    , ('\43310','\43311')
-    , ('\43359','\43359')
-    , ('\43457','\43469')
-    , ('\43486','\43487')
-    , ('\43612','\43615')
-    , ('\43742','\43743')
-    , ('\44011','\44011')
-    , ('\64830','\64831')
-    , ('\65040','\65049')
-    , ('\65072','\65106')
-    , ('\65108','\65121')
-    , ('\65123','\65123')
-    , ('\65128','\65128')
-    , ('\65130','\65131')
-    , ('\65281','\65283')
-    , ('\65285','\65290')
-    , ('\65292','\65295')
-    , ('\65306','\65307')
-    , ('\65311','\65312')
-    , ('\65339','\65341')
-    , ('\65343','\65343')
-    , ('\65371','\65371')
-    , ('\65373','\65373')
-    , ('\65375','\65381')
-    , ('\65792','\65793')
-    , ('\66463','\66463')
-    , ('\66512','\66512')
-    , ('\67671','\67671')
-    , ('\67871','\67871')
-    , ('\67903','\67903')
-    , ('\68176','\68184')
-    , ('\68223','\68223')
-    , ('\68409','\68415')
-    , ('\69819','\69820')
-    , ('\69822','\69825')
-    , ('\74864','\74867')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodePc     :: Char -> Bool
-isUnicodePc c
-  = isInList c
-    [ ('_','_')
-    , ('\8255','\8256')
-    , ('\8276','\8276')
-    , ('\65075','\65076')
-    , ('\65101','\65103')
-    , ('\65343','\65343')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodePd     :: Char -> Bool
-isUnicodePd c
-  = isInList c
-    [ ('-','-')
-    , ('\1418','\1418')
-    , ('\1470','\1470')
-    , ('\5120','\5120')
-    , ('\6150','\6150')
-    , ('\8208','\8213')
-    , ('\11799','\11799')
-    , ('\11802','\11802')
-    , ('\12316','\12316')
-    , ('\12336','\12336')
-    , ('\12448','\12448')
-    , ('\65073','\65074')
-    , ('\65112','\65112')
-    , ('\65123','\65123')
-    , ('\65293','\65293')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodePe     :: Char -> Bool
-isUnicodePe c
-  = isInList c
-    [ (')',')')
-    , (']',']')
-    , ('}','}')
-    , ('\3899','\3899')
-    , ('\3901','\3901')
-    , ('\5788','\5788')
-    , ('\8262','\8262')
-    , ('\8318','\8318')
-    , ('\8334','\8334')
-    , ('\9002','\9002')
-    , ('\10089','\10089')
-    , ('\10091','\10091')
-    , ('\10093','\10093')
-    , ('\10095','\10095')
-    , ('\10097','\10097')
-    , ('\10099','\10099')
-    , ('\10101','\10101')
-    , ('\10182','\10182')
-    , ('\10215','\10215')
-    , ('\10217','\10217')
-    , ('\10219','\10219')
-    , ('\10221','\10221')
-    , ('\10223','\10223')
-    , ('\10628','\10628')
-    , ('\10630','\10630')
-    , ('\10632','\10632')
-    , ('\10634','\10634')
-    , ('\10636','\10636')
-    , ('\10638','\10638')
-    , ('\10640','\10640')
-    , ('\10642','\10642')
-    , ('\10644','\10644')
-    , ('\10646','\10646')
-    , ('\10648','\10648')
-    , ('\10713','\10713')
-    , ('\10715','\10715')
-    , ('\10749','\10749')
-    , ('\11811','\11811')
-    , ('\11813','\11813')
-    , ('\11815','\11815')
-    , ('\11817','\11817')
-    , ('\12297','\12297')
-    , ('\12299','\12299')
-    , ('\12301','\12301')
-    , ('\12303','\12303')
-    , ('\12305','\12305')
-    , ('\12309','\12309')
-    , ('\12311','\12311')
-    , ('\12313','\12313')
-    , ('\12315','\12315')
-    , ('\12318','\12319')
-    , ('\64831','\64831')
-    , ('\65048','\65048')
-    , ('\65078','\65078')
-    , ('\65080','\65080')
-    , ('\65082','\65082')
-    , ('\65084','\65084')
-    , ('\65086','\65086')
-    , ('\65088','\65088')
-    , ('\65090','\65090')
-    , ('\65092','\65092')
-    , ('\65096','\65096')
-    , ('\65114','\65114')
-    , ('\65116','\65116')
-    , ('\65118','\65118')
-    , ('\65289','\65289')
-    , ('\65341','\65341')
-    , ('\65373','\65373')
-    , ('\65376','\65376')
-    , ('\65379','\65379')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodePf     :: Char -> Bool
-isUnicodePf c
-  = isInList c
-    [ ('\187','\187')
-    , ('\8217','\8217')
-    , ('\8221','\8221')
-    , ('\8250','\8250')
-    , ('\11779','\11779')
-    , ('\11781','\11781')
-    , ('\11786','\11786')
-    , ('\11789','\11789')
-    , ('\11805','\11805')
-    , ('\11809','\11809')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodePi     :: Char -> Bool
-isUnicodePi c
-  = isInList c
-    [ ('\171','\171')
-    , ('\8216','\8216')
-    , ('\8219','\8220')
-    , ('\8223','\8223')
-    , ('\8249','\8249')
-    , ('\11778','\11778')
-    , ('\11780','\11780')
-    , ('\11785','\11785')
-    , ('\11788','\11788')
-    , ('\11804','\11804')
-    , ('\11808','\11808')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodePo     :: Char -> Bool
-isUnicodePo c
-  = isInList c
-    [ ('!','#')
-    , ('%','\'')
-    , ('*','*')
-    , (',',',')
-    , ('.','/')
-    , (':',';')
-    , ('?','@')
-    , ('\\','\\')
-    , ('\161','\161')
-    , ('\183','\183')
-    , ('\191','\191')
-    , ('\894','\894')
-    , ('\903','\903')
-    , ('\1370','\1375')
-    , ('\1417','\1417')
-    , ('\1472','\1472')
-    , ('\1475','\1475')
-    , ('\1478','\1478')
-    , ('\1523','\1524')
-    , ('\1545','\1546')
-    , ('\1548','\1549')
-    , ('\1563','\1563')
-    , ('\1566','\1567')
-    , ('\1642','\1645')
-    , ('\1748','\1748')
-    , ('\1792','\1805')
-    , ('\2039','\2041')
-    , ('\2096','\2110')
-    , ('\2404','\2405')
-    , ('\2416','\2416')
-    , ('\3572','\3572')
-    , ('\3663','\3663')
-    , ('\3674','\3675')
-    , ('\3844','\3858')
-    , ('\3973','\3973')
-    , ('\4048','\4052')
-    , ('\4170','\4175')
-    , ('\4347','\4347')
-    , ('\4961','\4968')
-    , ('\5741','\5742')
-    , ('\5867','\5869')
-    , ('\5941','\5942')
-    , ('\6100','\6102')
-    , ('\6104','\6106')
-    , ('\6144','\6149')
-    , ('\6151','\6154')
-    , ('\6468','\6469')
-    , ('\6622','\6623')
-    , ('\6686','\6687')
-    , ('\6816','\6822')
-    , ('\6824','\6829')
-    , ('\7002','\7008')
-    , ('\7227','\7231')
-    , ('\7294','\7295')
-    , ('\7379','\7379')
-    , ('\8214','\8215')
-    , ('\8224','\8231')
-    , ('\8240','\8248')
-    , ('\8251','\8254')
-    , ('\8257','\8259')
-    , ('\8263','\8273')
-    , ('\8275','\8275')
-    , ('\8277','\8286')
-    , ('\11513','\11516')
-    , ('\11518','\11519')
-    , ('\11776','\11777')
-    , ('\11782','\11784')
-    , ('\11787','\11787')
-    , ('\11790','\11798')
-    , ('\11800','\11801')
-    , ('\11803','\11803')
-    , ('\11806','\11807')
-    , ('\11818','\11822')
-    , ('\11824','\11825')
-    , ('\12289','\12291')
-    , ('\12349','\12349')
-    , ('\12539','\12539')
-    , ('\42238','\42239')
-    , ('\42509','\42511')
-    , ('\42611','\42611')
-    , ('\42622','\42622')
-    , ('\42738','\42743')
-    , ('\43124','\43127')
-    , ('\43214','\43215')
-    , ('\43256','\43258')
-    , ('\43310','\43311')
-    , ('\43359','\43359')
-    , ('\43457','\43469')
-    , ('\43486','\43487')
-    , ('\43612','\43615')
-    , ('\43742','\43743')
-    , ('\44011','\44011')
-    , ('\65040','\65046')
-    , ('\65049','\65049')
-    , ('\65072','\65072')
-    , ('\65093','\65094')
-    , ('\65097','\65100')
-    , ('\65104','\65106')
-    , ('\65108','\65111')
-    , ('\65119','\65121')
-    , ('\65128','\65128')
-    , ('\65130','\65131')
-    , ('\65281','\65283')
-    , ('\65285','\65287')
-    , ('\65290','\65290')
-    , ('\65292','\65292')
-    , ('\65294','\65295')
-    , ('\65306','\65307')
-    , ('\65311','\65312')
-    , ('\65340','\65340')
-    , ('\65377','\65377')
-    , ('\65380','\65381')
-    , ('\65792','\65793')
-    , ('\66463','\66463')
-    , ('\66512','\66512')
-    , ('\67671','\67671')
-    , ('\67871','\67871')
-    , ('\67903','\67903')
-    , ('\68176','\68184')
-    , ('\68223','\68223')
-    , ('\68409','\68415')
-    , ('\69819','\69820')
-    , ('\69822','\69825')
-    , ('\74864','\74867')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodePs     :: Char -> Bool
-isUnicodePs c
-  = isInList c
-    [ ('(','(')
-    , ('[','[')
-    , ('{','{')
-    , ('\3898','\3898')
-    , ('\3900','\3900')
-    , ('\5787','\5787')
-    , ('\8218','\8218')
-    , ('\8222','\8222')
-    , ('\8261','\8261')
-    , ('\8317','\8317')
-    , ('\8333','\8333')
-    , ('\9001','\9001')
-    , ('\10088','\10088')
-    , ('\10090','\10090')
-    , ('\10092','\10092')
-    , ('\10094','\10094')
-    , ('\10096','\10096')
-    , ('\10098','\10098')
-    , ('\10100','\10100')
-    , ('\10181','\10181')
-    , ('\10214','\10214')
-    , ('\10216','\10216')
-    , ('\10218','\10218')
-    , ('\10220','\10220')
-    , ('\10222','\10222')
-    , ('\10627','\10627')
-    , ('\10629','\10629')
-    , ('\10631','\10631')
-    , ('\10633','\10633')
-    , ('\10635','\10635')
-    , ('\10637','\10637')
-    , ('\10639','\10639')
-    , ('\10641','\10641')
-    , ('\10643','\10643')
-    , ('\10645','\10645')
-    , ('\10647','\10647')
-    , ('\10712','\10712')
-    , ('\10714','\10714')
-    , ('\10748','\10748')
-    , ('\11810','\11810')
-    , ('\11812','\11812')
-    , ('\11814','\11814')
-    , ('\11816','\11816')
-    , ('\12296','\12296')
-    , ('\12298','\12298')
-    , ('\12300','\12300')
-    , ('\12302','\12302')
-    , ('\12304','\12304')
-    , ('\12308','\12308')
-    , ('\12310','\12310')
-    , ('\12312','\12312')
-    , ('\12314','\12314')
-    , ('\12317','\12317')
-    , ('\64830','\64830')
-    , ('\65047','\65047')
-    , ('\65077','\65077')
-    , ('\65079','\65079')
-    , ('\65081','\65081')
-    , ('\65083','\65083')
-    , ('\65085','\65085')
-    , ('\65087','\65087')
-    , ('\65089','\65089')
-    , ('\65091','\65091')
-    , ('\65095','\65095')
-    , ('\65113','\65113')
-    , ('\65115','\65115')
-    , ('\65117','\65117')
-    , ('\65288','\65288')
-    , ('\65339','\65339')
-    , ('\65371','\65371')
-    , ('\65375','\65375')
-    , ('\65378','\65378')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeS      :: Char -> Bool
-isUnicodeS c
-  = isInList c
-    [ ('$','$')
-    , ('+','+')
-    , ('<','>')
-    , ('^','^')
-    , ('`','`')
-    , ('|','|')
-    , ('~','~')
-    , ('\162','\169')
-    , ('\172','\172')
-    , ('\174','\177')
-    , ('\180','\180')
-    , ('\182','\182')
-    , ('\184','\184')
-    , ('\215','\215')
-    , ('\247','\247')
-    , ('\706','\709')
-    , ('\722','\735')
-    , ('\741','\747')
-    , ('\749','\749')
-    , ('\751','\767')
-    , ('\885','\885')
-    , ('\900','\901')
-    , ('\1014','\1014')
-    , ('\1154','\1154')
-    , ('\1542','\1544')
-    , ('\1547','\1547')
-    , ('\1550','\1551')
-    , ('\1769','\1769')
-    , ('\1789','\1790')
-    , ('\2038','\2038')
-    , ('\2546','\2547')
-    , ('\2554','\2555')
-    , ('\2801','\2801')
-    , ('\2928','\2928')
-    , ('\3059','\3066')
-    , ('\3199','\3199')
-    , ('\3313','\3314')
-    , ('\3449','\3449')
-    , ('\3647','\3647')
-    , ('\3841','\3843')
-    , ('\3859','\3863')
-    , ('\3866','\3871')
-    , ('\3892','\3892')
-    , ('\3894','\3894')
-    , ('\3896','\3896')
-    , ('\4030','\4037')
-    , ('\4039','\4044')
-    , ('\4046','\4047')
-    , ('\4053','\4056')
-    , ('\4254','\4255')
-    , ('\4960','\4960')
-    , ('\5008','\5017')
-    , ('\6107','\6107')
-    , ('\6464','\6464')
-    , ('\6624','\6655')
-    , ('\7009','\7018')
-    , ('\7028','\7036')
-    , ('\8125','\8125')
-    , ('\8127','\8129')
-    , ('\8141','\8143')
-    , ('\8157','\8159')
-    , ('\8173','\8175')
-    , ('\8189','\8190')
-    , ('\8260','\8260')
-    , ('\8274','\8274')
-    , ('\8314','\8316')
-    , ('\8330','\8332')
-    , ('\8352','\8376')
-    , ('\8448','\8449')
-    , ('\8451','\8454')
-    , ('\8456','\8457')
-    , ('\8468','\8468')
-    , ('\8470','\8472')
-    , ('\8478','\8483')
-    , ('\8485','\8485')
-    , ('\8487','\8487')
-    , ('\8489','\8489')
-    , ('\8494','\8494')
-    , ('\8506','\8507')
-    , ('\8512','\8516')
-    , ('\8522','\8525')
-    , ('\8527','\8527')
-    , ('\8592','\9000')
-    , ('\9003','\9192')
-    , ('\9216','\9254')
-    , ('\9280','\9290')
-    , ('\9372','\9449')
-    , ('\9472','\9933')
-    , ('\9935','\9953')
-    , ('\9955','\9955')
-    , ('\9960','\9983')
-    , ('\9985','\9988')
-    , ('\9990','\9993')
-    , ('\9996','\10023')
-    , ('\10025','\10059')
-    , ('\10061','\10061')
-    , ('\10063','\10066')
-    , ('\10070','\10078')
-    , ('\10081','\10087')
-    , ('\10132','\10132')
-    , ('\10136','\10159')
-    , ('\10161','\10174')
-    , ('\10176','\10180')
-    , ('\10183','\10186')
-    , ('\10188','\10188')
-    , ('\10192','\10213')
-    , ('\10224','\10626')
-    , ('\10649','\10711')
-    , ('\10716','\10747')
-    , ('\10750','\11084')
-    , ('\11088','\11097')
-    , ('\11493','\11498')
-    , ('\11904','\11929')
-    , ('\11931','\12019')
-    , ('\12032','\12245')
-    , ('\12272','\12283')
-    , ('\12292','\12292')
-    , ('\12306','\12307')
-    , ('\12320','\12320')
-    , ('\12342','\12343')
-    , ('\12350','\12351')
-    , ('\12443','\12444')
-    , ('\12688','\12689')
-    , ('\12694','\12703')
-    , ('\12736','\12771')
-    , ('\12800','\12830')
-    , ('\12842','\12880')
-    , ('\12896','\12927')
-    , ('\12938','\12976')
-    , ('\12992','\13054')
-    , ('\13056','\13311')
-    , ('\19904','\19967')
-    , ('\42128','\42182')
-    , ('\42752','\42774')
-    , ('\42784','\42785')
-    , ('\42889','\42890')
-    , ('\43048','\43051')
-    , ('\43062','\43065')
-    , ('\43639','\43641')
-    , ('\64297','\64297')
-    , ('\65020','\65021')
-    , ('\65122','\65122')
-    , ('\65124','\65126')
-    , ('\65129','\65129')
-    , ('\65284','\65284')
-    , ('\65291','\65291')
-    , ('\65308','\65310')
-    , ('\65342','\65342')
-    , ('\65344','\65344')
-    , ('\65372','\65372')
-    , ('\65374','\65374')
-    , ('\65504','\65510')
-    , ('\65512','\65518')
-    , ('\65532','\65533')
-    , ('\65794','\65794')
-    , ('\65847','\65855')
-    , ('\65913','\65929')
-    , ('\65936','\65947')
-    , ('\66000','\66044')
-    , ('\118784','\119029')
-    , ('\119040','\119078')
-    , ('\119081','\119140')
-    , ('\119146','\119148')
-    , ('\119171','\119172')
-    , ('\119180','\119209')
-    , ('\119214','\119261')
-    , ('\119296','\119361')
-    , ('\119365','\119365')
-    , ('\119552','\119638')
-    , ('\120513','\120513')
-    , ('\120539','\120539')
-    , ('\120571','\120571')
-    , ('\120597','\120597')
-    , ('\120629','\120629')
-    , ('\120655','\120655')
-    , ('\120687','\120687')
-    , ('\120713','\120713')
-    , ('\120745','\120745')
-    , ('\120771','\120771')
-    , ('\126976','\127019')
-    , ('\127024','\127123')
-    , ('\127248','\127278')
-    , ('\127281','\127281')
-    , ('\127293','\127293')
-    , ('\127295','\127295')
-    , ('\127298','\127298')
-    , ('\127302','\127302')
-    , ('\127306','\127310')
-    , ('\127319','\127319')
-    , ('\127327','\127327')
-    , ('\127353','\127353')
-    , ('\127355','\127356')
-    , ('\127359','\127359')
-    , ('\127370','\127373')
-    , ('\127376','\127376')
-    , ('\127488','\127488')
-    , ('\127504','\127537')
-    , ('\127552','\127560')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeSc     :: Char -> Bool
-isUnicodeSc c
-  = isInList c
-    [ ('$','$')
-    , ('\162','\165')
-    , ('\1547','\1547')
-    , ('\2546','\2547')
-    , ('\2555','\2555')
-    , ('\2801','\2801')
-    , ('\3065','\3065')
-    , ('\3647','\3647')
-    , ('\6107','\6107')
-    , ('\8352','\8376')
-    , ('\43064','\43064')
-    , ('\65020','\65020')
-    , ('\65129','\65129')
-    , ('\65284','\65284')
-    , ('\65504','\65505')
-    , ('\65509','\65510')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeSk     :: Char -> Bool
-isUnicodeSk c
-  = isInList c
-    [ ('^','^')
-    , ('`','`')
-    , ('\168','\168')
-    , ('\175','\175')
-    , ('\180','\180')
-    , ('\184','\184')
-    , ('\706','\709')
-    , ('\722','\735')
-    , ('\741','\747')
-    , ('\749','\749')
-    , ('\751','\767')
-    , ('\885','\885')
-    , ('\900','\901')
-    , ('\8125','\8125')
-    , ('\8127','\8129')
-    , ('\8141','\8143')
-    , ('\8157','\8159')
-    , ('\8173','\8175')
-    , ('\8189','\8190')
-    , ('\12443','\12444')
-    , ('\42752','\42774')
-    , ('\42784','\42785')
-    , ('\42889','\42890')
-    , ('\65342','\65342')
-    , ('\65344','\65344')
-    , ('\65507','\65507')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeSm     :: Char -> Bool
-isUnicodeSm c
-  = isInList c
-    [ ('+','+')
-    , ('<','>')
-    , ('|','|')
-    , ('~','~')
-    , ('\172','\172')
-    , ('\177','\177')
-    , ('\215','\215')
-    , ('\247','\247')
-    , ('\1014','\1014')
-    , ('\1542','\1544')
-    , ('\8260','\8260')
-    , ('\8274','\8274')
-    , ('\8314','\8316')
-    , ('\8330','\8332')
-    , ('\8512','\8516')
-    , ('\8523','\8523')
-    , ('\8592','\8596')
-    , ('\8602','\8603')
-    , ('\8608','\8608')
-    , ('\8611','\8611')
-    , ('\8614','\8614')
-    , ('\8622','\8622')
-    , ('\8654','\8655')
-    , ('\8658','\8658')
-    , ('\8660','\8660')
-    , ('\8692','\8959')
-    , ('\8968','\8971')
-    , ('\8992','\8993')
-    , ('\9084','\9084')
-    , ('\9115','\9139')
-    , ('\9180','\9185')
-    , ('\9655','\9655')
-    , ('\9665','\9665')
-    , ('\9720','\9727')
-    , ('\9839','\9839')
-    , ('\10176','\10180')
-    , ('\10183','\10186')
-    , ('\10188','\10188')
-    , ('\10192','\10213')
-    , ('\10224','\10239')
-    , ('\10496','\10626')
-    , ('\10649','\10711')
-    , ('\10716','\10747')
-    , ('\10750','\11007')
-    , ('\11056','\11076')
-    , ('\11079','\11084')
-    , ('\64297','\64297')
-    , ('\65122','\65122')
-    , ('\65124','\65126')
-    , ('\65291','\65291')
-    , ('\65308','\65310')
-    , ('\65372','\65372')
-    , ('\65374','\65374')
-    , ('\65506','\65506')
-    , ('\65513','\65516')
-    , ('\120513','\120513')
-    , ('\120539','\120539')
-    , ('\120571','\120571')
-    , ('\120597','\120597')
-    , ('\120629','\120629')
-    , ('\120655','\120655')
-    , ('\120687','\120687')
-    , ('\120713','\120713')
-    , ('\120745','\120745')
-    , ('\120771','\120771')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeSo     :: Char -> Bool
-isUnicodeSo c
-  = isInList c
-    [ ('\166','\167')
-    , ('\169','\169')
-    , ('\174','\174')
-    , ('\176','\176')
-    , ('\182','\182')
-    , ('\1154','\1154')
-    , ('\1550','\1551')
-    , ('\1769','\1769')
-    , ('\1789','\1790')
-    , ('\2038','\2038')
-    , ('\2554','\2554')
-    , ('\2928','\2928')
-    , ('\3059','\3064')
-    , ('\3066','\3066')
-    , ('\3199','\3199')
-    , ('\3313','\3314')
-    , ('\3449','\3449')
-    , ('\3841','\3843')
-    , ('\3859','\3863')
-    , ('\3866','\3871')
-    , ('\3892','\3892')
-    , ('\3894','\3894')
-    , ('\3896','\3896')
-    , ('\4030','\4037')
-    , ('\4039','\4044')
-    , ('\4046','\4047')
-    , ('\4053','\4056')
-    , ('\4254','\4255')
-    , ('\4960','\4960')
-    , ('\5008','\5017')
-    , ('\6464','\6464')
-    , ('\6624','\6655')
-    , ('\7009','\7018')
-    , ('\7028','\7036')
-    , ('\8448','\8449')
-    , ('\8451','\8454')
-    , ('\8456','\8457')
-    , ('\8468','\8468')
-    , ('\8470','\8472')
-    , ('\8478','\8483')
-    , ('\8485','\8485')
-    , ('\8487','\8487')
-    , ('\8489','\8489')
-    , ('\8494','\8494')
-    , ('\8506','\8507')
-    , ('\8522','\8522')
-    , ('\8524','\8525')
-    , ('\8527','\8527')
-    , ('\8597','\8601')
-    , ('\8604','\8607')
-    , ('\8609','\8610')
-    , ('\8612','\8613')
-    , ('\8615','\8621')
-    , ('\8623','\8653')
-    , ('\8656','\8657')
-    , ('\8659','\8659')
-    , ('\8661','\8691')
-    , ('\8960','\8967')
-    , ('\8972','\8991')
-    , ('\8994','\9000')
-    , ('\9003','\9083')
-    , ('\9085','\9114')
-    , ('\9140','\9179')
-    , ('\9186','\9192')
-    , ('\9216','\9254')
-    , ('\9280','\9290')
-    , ('\9372','\9449')
-    , ('\9472','\9654')
-    , ('\9656','\9664')
-    , ('\9666','\9719')
-    , ('\9728','\9838')
-    , ('\9840','\9933')
-    , ('\9935','\9953')
-    , ('\9955','\9955')
-    , ('\9960','\9983')
-    , ('\9985','\9988')
-    , ('\9990','\9993')
-    , ('\9996','\10023')
-    , ('\10025','\10059')
-    , ('\10061','\10061')
-    , ('\10063','\10066')
-    , ('\10070','\10078')
-    , ('\10081','\10087')
-    , ('\10132','\10132')
-    , ('\10136','\10159')
-    , ('\10161','\10174')
-    , ('\10240','\10495')
-    , ('\11008','\11055')
-    , ('\11077','\11078')
-    , ('\11088','\11097')
-    , ('\11493','\11498')
-    , ('\11904','\11929')
-    , ('\11931','\12019')
-    , ('\12032','\12245')
-    , ('\12272','\12283')
-    , ('\12292','\12292')
-    , ('\12306','\12307')
-    , ('\12320','\12320')
-    , ('\12342','\12343')
-    , ('\12350','\12351')
-    , ('\12688','\12689')
-    , ('\12694','\12703')
-    , ('\12736','\12771')
-    , ('\12800','\12830')
-    , ('\12842','\12880')
-    , ('\12896','\12927')
-    , ('\12938','\12976')
-    , ('\12992','\13054')
-    , ('\13056','\13311')
-    , ('\19904','\19967')
-    , ('\42128','\42182')
-    , ('\43048','\43051')
-    , ('\43062','\43063')
-    , ('\43065','\43065')
-    , ('\43639','\43641')
-    , ('\65021','\65021')
-    , ('\65508','\65508')
-    , ('\65512','\65512')
-    , ('\65517','\65518')
-    , ('\65532','\65533')
-    , ('\65794','\65794')
-    , ('\65847','\65855')
-    , ('\65913','\65929')
-    , ('\65936','\65947')
-    , ('\66000','\66044')
-    , ('\118784','\119029')
-    , ('\119040','\119078')
-    , ('\119081','\119140')
-    , ('\119146','\119148')
-    , ('\119171','\119172')
-    , ('\119180','\119209')
-    , ('\119214','\119261')
-    , ('\119296','\119361')
-    , ('\119365','\119365')
-    , ('\119552','\119638')
-    , ('\126976','\127019')
-    , ('\127024','\127123')
-    , ('\127248','\127278')
-    , ('\127281','\127281')
-    , ('\127293','\127293')
-    , ('\127295','\127295')
-    , ('\127298','\127298')
-    , ('\127302','\127302')
-    , ('\127306','\127310')
-    , ('\127319','\127319')
-    , ('\127327','\127327')
-    , ('\127353','\127353')
-    , ('\127355','\127356')
-    , ('\127359','\127359')
-    , ('\127370','\127373')
-    , ('\127376','\127376')
-    , ('\127488','\127488')
-    , ('\127504','\127537')
-    , ('\127552','\127560')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeZ      :: Char -> Bool
-isUnicodeZ c
-  = isInList c
-    [ (' ',' ')
-    , ('\160','\160')
-    , ('\5760','\5760')
-    , ('\6158','\6158')
-    , ('\8192','\8202')
-    , ('\8232','\8233')
-    , ('\8239','\8239')
-    , ('\8287','\8287')
-    , ('\12288','\12288')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeZl     :: Char -> Bool
-isUnicodeZl c
-  = isInList c
-    [ ('\8232','\8232')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeZp     :: Char -> Bool
-isUnicodeZp c
-  = isInList c
-    [ ('\8233','\8233')
-    ]
-
--- ------------------------------------------------------------
-
-isUnicodeZs     :: Char -> Bool
-isUnicodeZs c
-  = isInList c
-    [ (' ',' ')
-    , ('\160','\160')
-    , ('\5760','\5760')
-    , ('\6158','\6158')
-    , ('\8192','\8202')
-    , ('\8239','\8239')
-    , ('\8287','\8287')
-    , ('\12288','\12288')
-    ]
-
--- ------------------------------------------------------------
-
diff --git a/src/Text/XML/HXT/RelaxNG/Utils.hs b/src/Text/XML/HXT/RelaxNG/Utils.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/Utils.hs
+++ /dev/null
@@ -1,161 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.Utils
-   Copyright  : Copyright (C) 2008 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : stable
-   Portability: portable
-
-   Helper functions for RelaxNG validation
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.Utils
-    ( isRelaxAnyURI
-    , compareURI
-    , normalizeURI
-    , isNumber
-    , isNmtoken
-    , isName
-    , formatStringList
-    , formatStringListPatt
-    , formatStringListId
-    , formatStringListQuot
-    , formatStringListPairs
-    , formatStringListArr
-    )
-where
-
-import Text.ParserCombinators.Parsec
-
-import Text.XML.HXT.Parser.XmlTokenParser
-    ( skipS0
-    , nmtoken
-    , name
-    )
-
-import Network.URI
-    ( isURI
-    , isRelativeReference
-    , parseURI
-    , URI(..)
-    )
-
-import Data.Maybe
-    ( fromMaybe
-    )
-
-import Data.Char
-    ( toLower
-    )
-
-
--- ------------------------------------------------------------
-
-
--- | Tests whether a URI matches the Relax NG anyURI symbol
-
-isRelaxAnyURI :: String -> Bool
-isRelaxAnyURI s
-    = s == "" ||
-      ( isURI s && not (isRelativeReference s) &&
-        ( let (URI _ _ path _ frag) = fromMaybe (URI "" Nothing "" "" "") $ parseURI s
-          in (frag == "" && path /= "")
-        )
-      )
-
-
--- | Tests whether two URIs are equal after 'normalizeURI' is performed
-
-compareURI :: String -> String -> Bool
-compareURI uri1 uri2
-    = normalizeURI uri1 == normalizeURI uri2
-
-
--- |  Converts all letters to the corresponding lower-case letter
--- and removes a trailing \"\/\"
-
-normalizeURI :: String -> String
-normalizeURI ""
-    = ""
-normalizeURI uri
-    = map toLower ( if last uri == '/'
-                    then init uri
-                    else uri
-                  )
-
-checkByParsing  :: Parser String -> String -> Bool
-checkByParsing p s
-    = either (const False) (const True) (parse p' "" s)
-      where
-      p' = do
-           r <- p
-           eof
-           return r
-
--- | Tests whether a string matches a number [-](0-9)*
-isNumber :: String -> Bool
-isNumber
-    = checkByParsing parseNumber'
-    where
-    parseNumber' :: Parser String
-    parseNumber'
-        = do
-          skipS0
-          m <- option "" (string "-")
-          n <- many1 digit
-          skipS0
-          return $ m ++ n
-
-isNmtoken       :: String -> Bool
-isNmtoken    = checkByParsing nmtoken
-
-isName  :: String -> Bool
-isName  = checkByParsing name
-
-{- |
-
-Formats a list of strings into a single string.
-The first parameter formats the elements, the 2. is inserted
-between two elements.
-
-example:
-
-> formatStringList show ", " ["foo", "bar", "baz"] -> "foo", "bar", "baz"
-
--}
-
-formatStringListPatt :: [String] -> String
-formatStringListPatt
-    = formatStringList (++ "-") ", "
-
-formatStringListPairs :: [(String,String)] -> String
-formatStringListPairs
-    = formatStringList id ", "
-      . map (\ (a, b) -> a ++ " = " ++ show b)
-
-formatStringListQuot :: [String] -> String
-formatStringListQuot
-    = formatStringList show ", "
-
-formatStringListId :: [String] -> String
-formatStringListId
-    = formatStringList id ", "
-
-formatStringListArr :: [String] -> String
-formatStringListArr
-    = formatStringList show " -> "
-
-formatStringList :: (String -> String) -> String -> [String] -> String
-formatStringList _sf _sp []
-    = ""
-formatStringList sf spacer l
-    = reverse $ drop (length spacer) $ reverse $
-      foldr (\e -> ((if e /= "" then sf e ++ spacer else "") ++)) "" l
-
--- ----------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/Validation.hs b/src/Text/XML/HXT/RelaxNG/Validation.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/Validation.hs
+++ /dev/null
@@ -1,617 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.Validation
-   Copyright  : Copyright (C) 2008 Torben Kuseler, Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : stable
-   Portability: portable
-
-   Validation of a XML document with respect to a valid Relax NG schema in simple form.
-   Copied and modified from \"An algorithm for RELAX NG validation\" by James Clark
-   (<http://www.thaiopensource.com/relaxng/derivative.html>).
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.Validation
-    ( validateWithRelaxAndHandleErrors
-    , validateDocWithRelax
-    , validateRelax
-    , validateXMLDoc
-    , readForRelax
-    , normalizeForRelaxValidation
-    , contains
-    )
-where
-
-import Control.Arrow.ListArrows
-
-import           Text.XML.HXT.DOM.Interface
-import qualified Text.XML.HXT.DOM.XmlNode as XN
-import           Text.XML.HXT.DOM.Unicode
-    ( isXmlSpaceChar
-    )
-
-
-import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
-
-import Text.XML.HXT.Arrow.Edit
-    ( canonicalizeAllNodes
-    , collapseAllXText
-    )
-
-import Text.XML.HXT.Arrow.ProcessDocument
-    ( propagateAndValidateNamespaces
-    , getDocumentContents
-    , parseXmlDocument
-    )
-
-import Text.XML.HXT.RelaxNG.DataTypes
-import Text.XML.HXT.RelaxNG.CreatePattern
-import Text.XML.HXT.RelaxNG.PatternToString
-import Text.XML.HXT.RelaxNG.DataTypeLibraries
-import Text.XML.HXT.RelaxNG.Utils
-    ( formatStringListQuot
-    , compareURI
-    )
-
-import Data.Maybe
-    ( fromJust
-    )
-
-{-
-import qualified Debug.Trace as T
--}
-
--- ------------------------------------------------------------
-
-validateWithRelaxAndHandleErrors        :: IOSArrow XmlTree XmlTree -> IOSArrow XmlTree XmlTree
-validateWithRelaxAndHandleErrors theSchema
-    = validateWithRelax theSchema
-      >>>
-      handleErrors
-
-validateWithRelax       :: IOSArrow XmlTree XmlTree -> IOSArrow XmlTree XmlTree
-validateWithRelax theSchema
-    = traceMsg 2 "validate with Relax NG schema"
-      >>>
-      ( ( normalizeForRelaxValidation           -- prepare the document for validation
-          >>>
-          getChildren
-          >>>
-          isElem                                -- and select the root element
-        )
-        &&&
-        theSchema
-      )
-      >>>
-      arr2A validateRelax                       -- compute vaidation errors as a document
-
-handleErrors    :: IOSArrow XmlTree XmlTree
-handleErrors
-    = traceDoc "error found when validating with Relax NG schema"
-      >>>
-      ( getChildren                             -- prepare error format
-        >>>
-        getText
-        >>>
-        arr ("Relax NG validation: " ++)
-        >>>
-        mkError c_err
-      )
-      >>>
-      filterErrorMsg                            -- issue errors and set system status
-
-
-{- |
-   normalize a document for validation with Relax NG: remove all namespace declaration attributes,
-   remove all processing instructions and merge all sequences of text nodes into a single text node
--}
-
-normalizeForRelaxValidation :: ArrowXml a => a XmlTree XmlTree
-normalizeForRelaxValidation
-  = processTopDownWithAttrl
-    (
-     ( none `when`                      -- remove all namespace attributes
-       ( isAttr
-         >>>
-         getNamespaceUri
-         >>>
-         isA (compareURI xmlnsNamespace)
-       )
-     )
-     >>>
-     (none `when` isPi)                 -- processing instructions
-    )
-    >>>
-    collapseAllXText                    -- all text node sequences are merged into a single text node
-
--- ------------------------------------------------------------
-
-{- | Validates a xml document with respect to a Relax NG schema
-
-   * 1.parameter  :  the arrow for computing the Relax NG schema
-
-   - 2.parameter  :  list of options for reading and validating
-
-   - 3.parameter  :  XML document URI
-
-   - arrow-input  :  ignored
-
-   - arrow-output :  list of errors or 'none'
--}
-
-validateDocWithRelax :: IOSArrow XmlTree XmlTree -> Attributes -> String -> IOSArrow XmlTree XmlTree
-validateDocWithRelax theSchema al doc
-  = ( if null doc
-      then root [] []
-      else readForRelax al doc
-    )
-    >>>
-    validateWithRelax theSchema
-    >>>
-    perform handleErrors
-
-
-{- | Validates a xml document with respect to a Relax NG schema
-
-   * 1.parameter  :  XML document
-
-   - arrow-input  :  Relax NG schema
-
-   - arrow-output :  list of errors or 'none'
--}
-
-validateRelax :: XmlTree -> IOSArrow XmlTree XmlTree
-validateRelax xmlDoc
-  = fromLA
-    ( createPatternFromXmlTree
-      >>>
-      arr (\p -> childDeriv ("",[]) p xmlDoc)
-      >>>
-      ( (not . nullable)
-        `guardsP`
-        root [] [ (take 1024 . show) ^>> mkText ]       -- pattern may be recursive, so the string representation
-                                                        -- is truncated to 1024 chars to assure termination
-      )
-    )
-
--- ------------------------------------------------------------
-
-readForRelax    :: Attributes -> String -> IOSArrow b XmlTree
-readForRelax options schema
-    = getDocumentContents options schema
-      >>>
-      parseXmlDocument False
-      >>>
-      canonicalizeAllNodes
-      >>>
-      propagateAndValidateNamespaces
-
--- ------------------------------------------------------------
-
-{- old stuff -}
-
-validateXMLDoc :: Attributes -> String -> IOSArrow XmlTree XmlTree
-validateXMLDoc al xmlDoc
-  = validateRelax
-    $<
-    ( readForRelax al xmlDoc
-      >>>
-      normalizeForRelaxValidation
-      >>>
-      getChildren
-    )
-
-
--- ------------------------------------------------------------
---
--- | tests whether a 'NameClass' contains a particular 'QName'
-
-contains :: NameClass -> QName -> Bool
-contains AnyName _                      = True
-contains (AnyNameExcept nc)    n        = not (contains nc n)
-contains (NsName ns1)          qn       = ns1 == namespaceUri qn
-contains (NsNameExcept ns1 nc) qn       = ns1 == namespaceUri qn && not (contains nc qn)
-contains (Name ns1 ln1)        qn       = (ns1 == namespaceUri qn) && (ln1 == localPart qn)
-contains (NameClassChoice nc1 nc2) n    = (contains nc1 n) || (contains nc2 n)
-contains (NCError _) _                  = False
-
-
--- ------------------------------------------------------------
---
--- | tests whether a pattern matches the empty sequence
-nullable:: Pattern -> Bool
-nullable (Group p1 p2)          = nullable p1 && nullable p2
-nullable (Interleave p1 p2)     = nullable p1 && nullable p2
-nullable (Choice p1 p2)         = nullable p1 || nullable p2
-nullable (OneOrMore p)          = nullable p
-nullable (Element _ _)          = False
-nullable (Attribute _ _)        = False
-nullable (List _)               = False
-nullable (Value _ _ _)          = False
-nullable (Data _ _)             = False
-nullable (DataExcept _ _ _)     = False
-nullable (NotAllowed _)         = False
-nullable Empty                  = True
-nullable Text                   = True
-nullable (After _ _)            = False
-
-
--- ------------------------------------------------------------
---
--- | computes the derivative of a pattern with respect to a XML-Child and a 'Context'
-
-childDeriv :: Context -> Pattern -> XmlTree -> Pattern
-
-childDeriv cx p t
-    | XN.isText t       = textDeriv cx p . fromJust . XN.getText $ t
-    | XN.isElem t       = endTagDeriv p4
-    | otherwise         = notAllowed "Call to childDeriv with wrong arguments"
-    where
-    children    =            XN.getChildren $ t
-    qn          = fromJust . XN.getElemName $ t
-    atts        = fromJust . XN.getAttrl    $ t
-    cx1         = ("",[])
-    p1          = startTagOpenDeriv p qn
-    p2          = attsDeriv cx1 p1 atts
-    p3          = startTagCloseDeriv p2
-    p4          = childrenDeriv cx1 p3 children
-
--- ------------------------------------------------------------
---
--- | computes the derivative of a pattern with respect to a text node
-
-textDeriv :: Context -> Pattern -> String -> Pattern
-
-textDeriv cx (Choice p1 p2) s
-    = choice (textDeriv cx p1 s) (textDeriv cx p2 s)
-
-textDeriv cx (Interleave p1 p2) s
-    = choice
-      (interleave (textDeriv cx p1 s) p2)
-      (interleave p1 (textDeriv cx p2 s))
-
-textDeriv cx (Group p1 p2) s
-    = let
-      p = group (textDeriv cx p1 s) p2
-      in
-      if nullable p1
-      then choice p (textDeriv cx p2 s)
-      else p
-
-textDeriv cx (After p1 p2) s
-    = after (textDeriv cx p1 s) p2
-
-textDeriv cx (OneOrMore p) s
-    = group (textDeriv cx p s) (choice (OneOrMore p) Empty)
-
-textDeriv _ Text _
-    = Text
-
-textDeriv cx1 (Value (uri, s) value cx2) s1
-    = case datatypeEqual uri s value cx2 s1 cx1
-      of
-      Nothing     -> Empty
-      Just errStr -> notAllowed errStr
-
-textDeriv cx (Data (uri, s) params) s1
-    = case datatypeAllows uri s params s1 cx
-      of
-      Nothing     -> Empty
-      Just errStr -> notAllowed2 errStr
-
-textDeriv cx (DataExcept (uri, s) params p) s1
-    = case (datatypeAllows uri s params s1 cx)
-      of
-      Nothing     -> if not $ nullable $ textDeriv cx p s1
-                     then Empty
-                     else notAllowed
-                              ( "Any value except " ++
-                                show (show p) ++
-                                " expected, but value " ++
-                                show (show s1) ++
-                                " found"
-                              )
-      Just errStr -> notAllowed errStr
-
-textDeriv cx (List p) s
-    = if nullable (listDeriv cx p (words s))
-      then Empty
-      else notAllowed
-               ( "List with value(s) " ++
-                 show p ++
-                 " expected, but value(s) " ++
-                 formatStringListQuot (words s) ++
-                 " found"
-               )
-
-textDeriv _ n@(NotAllowed _) _
-    = n
-
-textDeriv _ p s
-    = notAllowed
-      ( "Pattern " ++ show (getPatternName p) ++
-        " expected, but text " ++ show s ++ " found"
-      )
-
-
--- ------------------------------------------------------------
---
--- | To compute the derivative of a pattern with respect to a list of strings,
--- simply compute the derivative with respect to each member of the list in turn.
-
-listDeriv :: Context -> Pattern -> [String] -> Pattern
-
-listDeriv _ p []
-    = p
-
-listDeriv cx p (x:xs)
-    = listDeriv cx (textDeriv cx p x) xs
-
-
--- ------------------------------------------------------------
---
--- | computes the derivative of a pattern with respect to a start tag open
-
-startTagOpenDeriv :: Pattern -> QName -> Pattern
-
-startTagOpenDeriv (Choice p1 p2) qn
-    = choice (startTagOpenDeriv p1 qn) (startTagOpenDeriv p2 qn)
-
-startTagOpenDeriv (Element nc p) qn
-    | contains nc qn
-        = after p Empty
-    | otherwise
-        = notAllowed $
-          "Element with name " ++ nameClassToString nc ++
-            " expected, but " ++ universalName qn ++ " found"
-
-startTagOpenDeriv (Interleave p1 p2) qn
-    = choice
-      (applyAfter (flip interleave p2) (startTagOpenDeriv p1 qn))
-      (applyAfter (interleave p1) (startTagOpenDeriv p2 qn))
-
-startTagOpenDeriv (OneOrMore p) qn
-    = applyAfter
-      (flip group (choice (OneOrMore p) Empty))
-      (startTagOpenDeriv p qn)
-
-startTagOpenDeriv (Group p1 p2) qn
-    = let
-      x = applyAfter (flip group p2) (startTagOpenDeriv p1 qn)
-      in
-      if nullable p1
-      then choice x (startTagOpenDeriv p2 qn)
-      else x
-
-startTagOpenDeriv (After p1 p2) qn
-    = applyAfter (flip after p2) (startTagOpenDeriv p1 qn)
-
-startTagOpenDeriv n@(NotAllowed _) _
-    = n
-
-startTagOpenDeriv p qn
-    = notAllowed ( show p ++ " expected, but Element " ++ universalName qn ++ " found" )
-
--- ------------------------------------------------------------
-
--- auxiliary functions for tracing
-{-
-attsDeriv' cx p ts
-    = T.trace ("attsDeriv: p=" ++ (take 1000 . show) p ++ ", t=" ++ showXts ts) $
-      T.trace ("res= " ++ (take 1000 . show) res) res
-    where
-    res = attsDeriv cx p ts
-
-attDeriv' cx p t
-    = T.trace ("attDeriv: p=" ++ (take 1000 . show) p ++ ", t=" ++ showXts [t]) $
-      T.trace ("res= " ++ (take 1000 . show) res) res
-    where
-    res = attDeriv cx p t
--}
-
--- | To compute the derivative of a pattern with respect to a sequence of attributes,
--- simply compute the derivative with respect to each attribute in turn.
-
-attsDeriv :: Context -> Pattern -> XmlTrees -> Pattern
-
-attsDeriv _ p []
-    = p
-attsDeriv cx p (t : ts)
-    | XN.isAttr t
-        = attsDeriv cx (attDeriv cx p t) ts
-    | otherwise
-        = notAllowed "Call to attsDeriv with wrong arguments"
-
-attDeriv :: Context -> Pattern -> XmlTree -> Pattern
-
-attDeriv cx (After p1 p2) att
-    = after (attDeriv cx p1 att) p2
-
-attDeriv cx (Choice p1 p2) att
-    = choice (attDeriv cx p1 att) (attDeriv cx p2 att)
-
-attDeriv cx (Group p1 p2) att
-    = choice
-      (group (attDeriv cx p1 att) p2)
-      (group p1 (attDeriv cx p2 att))
-
-attDeriv cx (Interleave p1 p2) att
-    = choice
-      (interleave (attDeriv cx p1 att) p2)
-      (interleave p1 (attDeriv cx p2 att))
-
-attDeriv cx (OneOrMore p) att
-    = group
-      (attDeriv cx p att)
-      (choice (OneOrMore p) Empty)
-
-attDeriv cx (Attribute nc p) att
-    | isa
-      &&
-      not (contains nc qn)
-        = notAllowed1 $
-          "Attribute with name " ++ nameClassToString nc
-          ++ " expected, but " ++ universalName qn ++ " found"
-    | isa
-      &&
-      ( ( nullable p
-          &&
-          whitespace val
-        )
-        || nullable p'
-      )
-        = Empty
-    | isa
-        = err' p'
-    where
-    isa =            XN.isAttr      $ att
-    qn  = fromJust . XN.getAttrName $ att
-    av  =            XN.getChildren $ att
-    val = showXts av
-    p'  = textDeriv cx p val
-
-    err' (NotAllowed (ErrMsg _l es))
-        = err'' (": " ++ head es)
-    err' _
-        = err'' ""
-    err'' e
-        = notAllowed2 $
-          "Attribute value \"" ++ val ++
-          "\" does not match datatype spec " ++ show p ++ e
-
-attDeriv _ n@(NotAllowed _) _
-    = n
-
-attDeriv _ _p att
-    = notAllowed $
-      "No matching pattern for attribute '" ++  showXts [att] ++ "' found"
-
--- ------------------------------------------------------------
---
--- | computes the derivative of a pattern with respect to a start tag close
-
-startTagCloseDeriv :: Pattern -> Pattern
-
-startTagCloseDeriv (After p1 p2)
-    = after (startTagCloseDeriv p1) p2
-
-startTagCloseDeriv (Choice p1 p2)
-    = choice
-      (startTagCloseDeriv p1)
-      (startTagCloseDeriv p2)
-
-startTagCloseDeriv (Group p1 p2)
-    = group
-      (startTagCloseDeriv p1)
-      (startTagCloseDeriv p2)
-
-startTagCloseDeriv (Interleave p1 p2)
-    = interleave
-      (startTagCloseDeriv p1)
-      (startTagCloseDeriv p2)
-
-startTagCloseDeriv (OneOrMore p)
-    = oneOrMore (startTagCloseDeriv p)
-
-startTagCloseDeriv (Attribute nc _)
-    = notAllowed1 $
-      "Attribut with name, " ++ show nc ++
-      " expected, but no more attributes found"
-
-startTagCloseDeriv p
-    = p
-
-
--- ------------------------------------------------------------
---
--- | Computing the derivative of a pattern with respect to a list of children involves
--- computing the derivative with respect to each pattern in turn, except
--- that whitespace requires special treatment.
-
-childrenDeriv :: Context -> Pattern -> XmlTrees -> Pattern
-childrenDeriv _cx p@(NotAllowed _) _
-    = p
-
-childrenDeriv cx p []
-    = childrenDeriv cx p [XN.mkText ""]
-
-childrenDeriv cx p [tt]
-    | ist
-      &&
-      whitespace s
-        = choice p p1
-    | ist
-        = p1
-    where
-    ist =            XN.isText    tt
-    s   = fromJust . XN.getText $ tt
-    p1  = childDeriv cx p tt
-
-childrenDeriv cx p children
-    = stripChildrenDeriv cx p children
-
-stripChildrenDeriv :: Context -> Pattern -> XmlTrees -> Pattern
-stripChildrenDeriv _ p []
-    = p
-
-stripChildrenDeriv cx p (h:t)
-    = stripChildrenDeriv cx
-      ( if strip h
-        then p
-        else (childDeriv cx p h)
-      ) t
-
-
--- ------------------------------------------------------------
---
--- | computes the derivative of a pattern with respect to a end tag
-
-endTagDeriv :: Pattern -> Pattern
-endTagDeriv (Choice p1 p2)
-    = choice (endTagDeriv p1) (endTagDeriv p2)
-
-endTagDeriv (After p1 p2)
-    | nullable p1
-        = p2
-    | otherwise
-        = notAllowed $
-          show p1 ++ " expected"
-
-endTagDeriv n@(NotAllowed _)
-    = n
-
-endTagDeriv _
-    = notAllowed "Call to endTagDeriv with wrong arguments"
-
--- ------------------------------------------------------------
---
--- | applies a function (first parameter) to the second part of a after pattern
-
-applyAfter :: (Pattern -> Pattern) -> Pattern -> Pattern
-
-applyAfter f (After p1 p2)      = after p1 (f p2)
-applyAfter f (Choice p1 p2)     = choice (applyAfter f p1) (applyAfter f p2)
-applyAfter _ n@(NotAllowed _)   = n
-applyAfter _ _                  = notAllowed "Call to applyAfter with wrong arguments"
-
--- --------------------
-
--- mothers little helpers
-
-strip           :: XmlTree -> Bool
-strip           = maybe False whitespace . XN.getText
-
-whitespace      :: String -> Bool
-whitespace      = all isXmlSpaceChar
-
-showXts         :: XmlTrees -> String
-showXts         = concat . runLA (xshow $ arrL id)
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/Validator.hs b/src/Text/XML/HXT/RelaxNG/Validator.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/Validator.hs
+++ /dev/null
@@ -1,308 +0,0 @@
--- |
--- This module exports the core functions from the basic validation und simplification libraries.
--- It also exports some helper functions for easier access to the validation functionality.
-
-module Text.XML.HXT.RelaxNG.Validator
-  ( validateDocumentWithRelaxSchema
-  , validateDocumentWithRelax
-
-  , validate
-  , validateSchema
-  , validateWithSpezification
-  , validateSchemaWithSpezification
-  , validateWithoutSpezification
-  , module Text.XML.HXT.RelaxNG.Validation
-  , module Text.XML.HXT.RelaxNG.Simplification
-  )
-where
-
-import Control.Arrow.ListArrows
-
-import Text.XML.HXT.DOM.Interface
-import Text.XML.HXT.Arrow.XmlArrow
-import Text.XML.HXT.Arrow.XmlIOStateArrow
-
-import Text.XML.HXT.RelaxNG.Validation
-import Text.XML.HXT.RelaxNG.Simplification
-import Text.XML.HXT.RelaxNG.Schema        as S
-
--- ------------------------------------------------------------
-
-{- |
-   validate a document with a Relax NG schema
-
-   * 1.parameter  : the option list for validation
-
-   - 2.parameter  : the URI of the Relax NG Schema
-
-   - arrow-input  : the document to be validated, namespaces must have been processed
-
-   - arrow-output : the input document, or in case of validation errors, an empty document with status information in the root
-
-options evaluated by validateDocumentWithRelaxSchema:
-
-    * 'a_check_restrictions'   : check Relax NG schema restrictions when simplifying the schema (default: on)
-
-    - 'a_validate_externalRef' : validate a Relax NG schema referenced by a externalRef-Pattern (default: on)
-
-    - 'a_validate_include'     : validate a Relax NG schema referenced by a include-Pattern (default: on)
-
-all other options are propagated to the read functions for schema input
-
-example:
-
-> validateDocumentWithRelaxSchema [(a_check_restrictions, "0")] "testSchema.rng"
-
-
--}
-
-validateDocumentWithRelaxSchema :: Attributes -> String -> IOStateArrow s XmlTree XmlTree
-validateDocumentWithRelaxSchema userOptions relaxSchema
-    = withOtherUserState ()
-      $
-      ( ( validate' $< validSchema )    -- try to validate, only possible if schema is o.k.
-        `orElse`
-        this
-      )
-      `when`
-      documentStatusOk                  -- only do something when document status is ok
-    where
-    validate' schema
-        = setDocumentStatusFromSystemState "read and build Relax NG schema"
-          >>>
-          validateDocumentWithRelax schema
-
-    validSchema
-        = traceMsg 2 ( "read Relax NG schema document: " ++ show relaxSchema )
-          >>>
-          readForRelax remainingOptions relaxSchema
-          >>>
-          perform ( let checkSchema = True in           -- test option in al
-                    if checkSchema
-                    then validateWithRelaxAndHandleErrors S.relaxSchemaArrow
-                    else none
-                  )
-          >>>
-          traceMsg 2 "create simplified schema"
-          >>>
-          createSimpleForm remainingOptions
-            ( hasOption a_check_restrictions   )
-            ( hasOption a_validate_externalRef )
-            ( hasOption a_validate_include     )
-          >>>
-          traceDoc "simplified schema"
-          >>>
-          perform ( getErrors
-                    >>>
-                    handleSimplificationErrors
-                  )
-    hasOption n
-        = optionIsSet n options
-
-    options = addEntries userOptions defaultOptions
-
-    defaultOptions
-        = [ ( a_check_restrictions,     v_1 )
-          , ( a_validate_externalRef,   v_1 )
-          , ( a_validate_include,       v_1 )
-          ]
-
-    remainingOptions
-         = filter (not . flip hasEntry defaultOptions . fst) options
-
-
-
-handleSimplificationErrors      :: IOSArrow XmlTree XmlTree
-handleSimplificationErrors
-    = traceDoc "simplification errors"
-      >>>
-      getChildren >>> getAttrValue "desc"
-      >>>
-      arr ("Relax NG validation: " ++)
-      >>>
-      mkError c_err
-      >>>
-      filterErrorMsg
-
-
-{- | validate an XML document with respect to a Relax NG schema
-
-   * 1.parameter  : the valid and simplified schema as XML tree
-
-   - arrow-input  : the document to be validated
-
-   - arrow-output : the validated and unchanged document or the empty document with status information set in the root node
--}
-
-validateDocumentWithRelax       :: XmlTree -> IOSArrow XmlTree XmlTree
-validateDocumentWithRelax schema
-    = ( traceMsg 1 "validate document with Relax NG schema"
-        >>>
-        perform ( validateWithRelaxAndHandleErrors (constA schema) )
-        >>>
-        setDocumentStatusFromSystemState "validate document with Relax NG schema"
-      )
-      `when` documentStatusOk                           -- only do something when document status is ok
-
-
-{- |
-   normalize a document for Relax NG validation,
-   call the 'Text.XML.HXT.RelaxNG.Validation.validateRelax' function for doing the hard work,
-   and issue errors
-
-   * 1.parameter  : the arrow for computing the schema
-
-   - arrow-input  : the document to be validated
-
-   - arrow-output : nothing
--}
-
--- ------------------------------------------------------------
-
-{- | Document validation
-
-Validates a xml document with respect to a Relax NG schema.
-
-First, the schema is validated with respect to the Relax NG Spezification. If no error is found, the xml document is validated with respect to the schema.
-
-   * 1.parameter :  list of options; namespace progagation is always done
-
-   - 2.parameter :  XML document
-
-   - 3.parameter :  Relax NG schema file
-
-available options:
-
-    * 'a_do_not_check_restrictions' : do not check Relax NG schema restrictions (includes do-not-validate-externalRef, do-not-validate-include)
-
-    - 'a_do_not_validate_externalRef' : do not validate a Relax NG schema referenced by a externalRef-Pattern
-
-    - 'a_validate_externalRef' : validate a Relax NG schema referenced by a externalRef-Pattern (default)
-
-    - 'a_do_not_validate_include' : do not validate a Relax NG schema referenced by a include-Pattern
-
-    - 'a_validate_include' : validate a Relax NG schema referenced by a include-Pattern (default)
-
-    - 'a_output_changes' : output Pattern transformations in case of an error
-
-    - 'a_do_not_collect_errors' : stop Relax NG simplification after the first error has occurred
-
-    - all 'Text.XML.HXT.Arrow.ReadDocument.readDocument' options
-
-example:
-
-> validate [(a_do_not_check_restrictions, "1")] "test.xml" "testSchema.rng"
-
--}
-validate :: Attributes -> String -> String -> IOSArrow n XmlTree
-validate al xmlDocument relaxSchema
-  = S.relaxSchemaArrow
-    >>>
-    validateWithSpezification al xmlDocument relaxSchema
-
-
-
-
-{- | Relax NG schema validation
-
-Validates a Relax NG schema with respect to the Relax NG Spezification.
-
-   * 1.parameter :  list of available options (see also: 'validate')
-
-   - 2.parameter :  Relax NG schema file
-
--}
-validateSchema :: Attributes -> String -> IOSArrow n XmlTree
-validateSchema al relaxSchema
-  = validate al "" relaxSchema
-
-
-
-{- | Document validation
-
-Validates a xml document with respect to a Relax NG schema. Similar to 'validate', but the Relax NG Specification is not created. Can be used, to check a list of documents more efficiently.
-
-   * 1.parameter :  list of available options (see also: 'validate')
-
-   - 2.parameter :  XML document
-
-   - 3.parameter :  Relax NG schema file
-
-   - arrow-input  :  Relax NG Specification in simple form
-
-example:
-
-> Text.XML.HXT.RelaxNG.Schema.relaxSchemaArrow
-> >>>
-> ( validateWithSpezification [] "foo.xml" "foo.rng"
->   &&&
->   validateWithSpezification [] "bar.xml" "bar.rng"
-> )
-
-
--}
-validateWithSpezification :: Attributes -> String -> String -> IOSArrow XmlTree XmlTree
-validateWithSpezification al xmlDocument relaxSchema
-  = -- validation of the schema with respect to the specification
-    -- returns a list of errors or none if the schema is correct
-
-    ( validateRelax $< ( readForRelax al relaxSchema
-                         >>>
-                         getChildren
-                       )
-    )
-    `orElse`
-
-    -- validation of the xml document with respect to the schema
-    -- returns a list of errors or none if the xml document is correct
-
-    validateWithoutSpezification al xmlDocument relaxSchema
-
-{- | Relax NG schema validation
-
-    see 'validateSchema' and 'validateWithSpezification'
-
-   * 1.parameter :  list of available options (see also: 'validate')
-
-   - 2.parameter :  Relax NG schema file
-
-   - arrow-input  :  Relax NG Specification in simple form
--}
-
-validateSchemaWithSpezification :: Attributes -> String -> IOSArrow XmlTree XmlTree
-validateSchemaWithSpezification al relaxSchema
-  = validateWithSpezification al "" relaxSchema
-
-
-
-{- | Document validation
-
-Validates a xml document with respect to a Relax NG schema, but the schema is @not@ validated with respect to a specification first. Should be used only for valid Relax NG schemes.
-
-   * 1.parameter :  list of available options (see also: 'validate')
-
-   - 2.parameter :  XML document
-
-   - 3.parameter :  Relax NG schema file
-
--}
-
-
-validateWithoutSpezification :: Attributes -> String -> String -> IOSArrow n XmlTree
-validateWithoutSpezification al xmlDocument relaxSchema
-  = readForRelax al relaxSchema
-    >>>
-    createSimpleForm al True True True
-    >>>
-    ( ( getErrors >>> perform handleSimplificationErrors )              -- issue errors in schema simplification
-      `orElse`
-      ( if null xmlDocument                                             -- no errors: validate document
-        then none
-        else validateRelax $< ( readForRelax al xmlDocument
-                                >>>
-                                normalizeForRelaxValidation
-                                >>>
-                                getChildren
-                              )
-      )
-    )
diff --git a/src/Text/XML/HXT/RelaxNG/XmlSchema/DataTypeLibW3C.hs b/src/Text/XML/HXT/RelaxNG/XmlSchema/DataTypeLibW3C.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/XmlSchema/DataTypeLibW3C.hs
+++ /dev/null
@@ -1,610 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.XmlSchema.DataTypeLibW3C
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
-   Portability: portable
-   Version    : $Id$
-
-   Datatype library for the W3C XML schema datatypes
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.XmlSchema.DataTypeLibW3C
-  ( w3cNS
-  , w3cDatatypeLib
-
-  , xsd_string                  -- data type names
-  , xsd_normalizedString
-  , xsd_token
-  , xsd_language
-  , xsd_NMTOKEN
-  , xsd_NMTOKENS
-  , xsd_Name
-  , xsd_NCName
-  , xsd_ID
-  , xsd_IDREF
-  , xsd_IDREFS
-  , xsd_ENTITY
-  , xsd_ENTITIES
-  , xsd_anyURI
-  , xsd_QName
-  , xsd_NOTATION
-  , xsd_hexBinary
-  , xsd_base64Binary
-  , xsd_decimal
-
-  , xsd_length                  -- facet names
-  , xsd_maxLength
-  , xsd_minLength
-  , xsd_maxExclusive
-  , xsd_minExclusive
-  , xsd_maxInclusive
-  , xsd_minInclusive
-  , xsd_totalDigits
-  , xsd_fractionDigits
-  , xsd_pattern
-  , xsd_enumeration
-  )
-where
-
-import Data.Maybe
-import Data.Ratio
-
-import Network.URI                              ( isURIReference )
-
-import Text.XML.HXT.DOM.QualifiedName           ( isWellformedQualifiedName
-                                                , isNCName
-                                                )
-import Text.XML.HXT.RelaxNG.DataTypeLibUtils
-import Text.XML.HXT.RelaxNG.XmlSchema.Regex     ( Regex
-                                                , matchWithRE
-                                                )
-import Text.XML.HXT.RelaxNG.XmlSchema.RegexParser
-                                                ( parseRegex
-                                                )
-
--- ------------------------------------------------------------
-
--- | Namespace of the W3C XML schema datatype library
-
-w3cNS   :: String
-w3cNS   = "http://www.w3.org/2001/XMLSchema-datatypes"
-
-
-xsd_string
- , xsd_normalizedString
- , xsd_token
- , xsd_language
- , xsd_NMTOKEN
- , xsd_NMTOKENS
- , xsd_Name
- , xsd_NCName
- , xsd_ID
- , xsd_IDREF
- , xsd_IDREFS
- , xsd_ENTITY
- , xsd_ENTITIES
- , xsd_anyURI
- , xsd_QName
- , xsd_NOTATION
- , xsd_hexBinary
- , xsd_base64Binary
- , xsd_decimal
- , xsd_integer
- , xsd_nonPositiveInteger
- , xsd_negativeInteger
- , xsd_nonNegativeInteger
- , xsd_positiveInteger
- , xsd_long
- , xsd_int
- , xsd_short
- , xsd_byte
- , xsd_unsignedLong
- , xsd_unsignedInt
- , xsd_unsignedShort
- , xsd_unsignedByte :: String
-
-xsd_string              = "string"
-xsd_normalizedString    = "normalizedString"
-xsd_token               = "token"
-xsd_language            = "language"
-xsd_NMTOKEN             = "NMTOKEN"
-xsd_NMTOKENS            = "NMTOKENS"
-xsd_Name                = "Name"
-xsd_NCName              = "NCName"
-xsd_ID                  = "ID"
-xsd_IDREF               = "IDREF"
-xsd_IDREFS              = "IDREFS"
-xsd_ENTITY              = "ENTITY"
-xsd_ENTITIES            = "ENTITIES"
-xsd_anyURI              = "anyURI"
-xsd_QName               = "QName"
-xsd_NOTATION            = "NOTATION"
-xsd_hexBinary           = "hexBinary"
-xsd_base64Binary        = "base64Binary"
-xsd_decimal             = "decimal"
-xsd_integer             = "integer"
-xsd_nonPositiveInteger  = "nonPositiveInteger"
-xsd_negativeInteger     = "negativeInteger"
-xsd_nonNegativeInteger  = "nonNegativeInteger"
-xsd_positiveInteger     = "positiveInteger"
-xsd_long                = "long"
-xsd_int                 = "int"
-xsd_short               = "short"
-xsd_byte                = "byte"
-xsd_unsignedLong        = "unsignedLong"
-xsd_unsignedInt         = "unsignedInt"
-xsd_unsignedShort       = "unsignedShort"
-xsd_unsignedByte        = "unsignedByte"
-
-
-xsd_length
- , xsd_maxLength
- , xsd_minLength
- , xsd_maxExclusive
- , xsd_minExclusive
- , xsd_maxInclusive
- , xsd_minInclusive
- , xsd_totalDigits
- , xsd_fractionDigits
- , xsd_pattern
- , xsd_enumeration :: String
-
-xsd_length              = rng_length
-xsd_maxLength           = rng_maxLength
-xsd_minLength           = rng_minLength
-
-xsd_maxExclusive        = rng_maxExclusive
-xsd_minExclusive        = rng_minExclusive
-xsd_maxInclusive        = rng_maxInclusive
-xsd_minInclusive        = rng_minInclusive
-
-xsd_totalDigits         = "totalDigits"
-xsd_fractionDigits      = "fractionDigits"
-
-xsd_pattern             = "pattern"
-xsd_enumeration         = "enumeration"
-
--- ----------------------------------------
-
--- | The main entry point to the W3C XML schema datatype library.
---
--- The 'DTC' constructor exports the list of supported datatypes and params.
--- It also exports the specialized functions to validate a XML instance value with
--- respect to a datatype.
-w3cDatatypeLib :: DatatypeLibrary
-w3cDatatypeLib = (w3cNS, DTC datatypeAllowsW3C datatypeEqualW3C w3cDatatypes)
-
-
--- | All supported datatypes of the library
-w3cDatatypes :: AllowedDatatypes
-w3cDatatypes = [ (xsd_string,                   stringParams)
-               , (xsd_normalizedString,         stringParams)
-               , (xsd_token,                    stringParams)
-               , (xsd_language,                 stringParams)
-               , (xsd_NMTOKEN,                  stringParams)
-               , (xsd_NMTOKENS,                 listParams  )
-               , (xsd_Name,                     stringParams)
-               , (xsd_NCName,                   stringParams)
-               , (xsd_ID,                       stringParams)
-               , (xsd_IDREF,                    stringParams)
-               , (xsd_IDREFS,                   listParams  )
-               , (xsd_ENTITY,                   stringParams)
-               , (xsd_ENTITIES,                 listParams  )
-               , (xsd_anyURI,                   stringParams)
-               , (xsd_QName,                    stringParams)
-               , (xsd_NOTATION,                 stringParams)
-               , (xsd_hexBinary,                stringParams)
-               , (xsd_base64Binary,             stringParams)
-               , (xsd_decimal,                  decimalParams)
-               , (xsd_integer,                  integerParams)
-               , (xsd_nonPositiveInteger,       integerParams)
-               , (xsd_negativeInteger,          integerParams)
-               , (xsd_nonNegativeInteger,       integerParams)
-               , (xsd_positiveInteger,          integerParams)
-               , (xsd_long,                     integerParams)
-               , (xsd_int,                      integerParams)
-               , (xsd_short,                    integerParams)
-               , (xsd_byte,                     integerParams)
-               , (xsd_unsignedLong,             integerParams)
-               , (xsd_unsignedInt,              integerParams)
-               , (xsd_unsignedShort,            integerParams)
-               , (xsd_unsignedByte,             integerParams)
-               ]
-
--- ----------------------------------------
-
--- | List of allowed params for the string datatypes
-stringParams    :: AllowedParams
-stringParams    = xsd_pattern : map fst fctTableString
-
--- ----------------------------------------
-
-patternValid    :: ParamList -> CheckString
-patternValid params
-    = foldr (>>>) ok . map paramPatternValid $ params
-      where
-      paramPatternValid (pn, pv)
-          | pn == xsd_pattern   = assert (patParamValid pv) (errorMsgParam pn pv)
-          | otherwise           = ok
-
-patParamValid :: String -> String -> Bool
-patParamValid regex a
-    = case parseRegex regex of
-      (Left _  )        -> False
-      (Right ex)        -> isNothing . matchWithRE ex $ a
-
--- ----------------------------------------
-
--- | List of allowed params for the decimal datatypes
-
-decimalParams   :: AllowedParams
-decimalParams   = xsd_pattern : map fst fctTableDecimal
-
-fctTableDecimal :: [(String, String -> Rational -> Bool)]
-fctTableDecimal
-    = [ (xsd_maxExclusive,   cvd (>))
-      , (xsd_minExclusive,   cvd (<))
-      , (xsd_maxInclusive,   cvd (>=))
-      , (xsd_minInclusive,   cvd (<=))
-      , (xsd_totalDigits,    cvi (\ l v ->    totalDigits v == l))
-      , (xsd_fractionDigits, cvi (\ l v -> fractionDigits v == l))
-      ]
-    where
-    cvd         :: (Rational -> Rational -> Bool) -> (String -> Rational -> Bool)
-    cvd op      = \ x y -> isDecimal x && readDecimal x `op` y
-
-    cvi         :: (Int -> Rational -> Bool) -> (String -> Rational -> Bool)
-    cvi op      = \ x y -> isNumber x && read x `op` y
-
-decimalValid    :: ParamList -> CheckA Rational Rational
-decimalValid params
-    = foldr (>>>) ok . map paramDecimalValid $ params
-    where
-    paramDecimalValid (pn, pv)
-        = assert
-          ((fromMaybe (const . const $ True) . lookup pn $ fctTableDecimal) pv)
-          (errorMsgParam pn pv . showDecimal)
-
--- ----------------------------------------
-
--- | List of allowed params for the decimal and integer datatypes
-
-integerParams   :: AllowedParams
-integerParams   = xsd_pattern : map fst fctTableInteger
-
-fctTableInteger :: [(String, String -> Integer -> Bool)]
-fctTableInteger
-    = [ (xsd_maxExclusive,   cvi (>))
-      , (xsd_minExclusive,   cvi (<))
-      , (xsd_maxInclusive,   cvi (>=))
-      , (xsd_minInclusive,   cvi (<=))
-      , (xsd_totalDigits,    cvi (\ l v -> totalD v == toInteger l))
-      ]
-    where
-    cvi         :: (Integer -> Integer -> Bool) -> (String -> Integer -> Bool)
-    cvi op      = \ x y -> isNumber x && read x `op` y
-
-    totalD i
-        | i < 0     = totalD (0-i)
-        | otherwise = toInteger . length . show $ i
-
-integerValid    :: DatatypeName -> ParamList -> CheckA Integer Integer
-integerValid datatype params
-    = assertInRange
-      >>>
-      (foldr (>>>) ok . map paramIntegerValid $ params)
-    where
-    assertInRange       :: CheckA Integer Integer
-    assertInRange
-        = assert
-          (fromMaybe (const True) . lookup datatype $ integerRangeTable)
-          (\ v -> ( "Datatype " ++ show datatype ++
-                    " with value = " ++ show v ++
-                    " not in integer value range"
-                  )
-          )
-    paramIntegerValid (pn, pv)
-        = assert
-          ((fromMaybe (const . const $ True) . lookup pn $ fctTableInteger) pv)
-          (errorMsgParam pn pv . show)
-
-integerRangeTable       :: [(String, Integer -> Bool)]
-integerRangeTable       = [ (xsd_integer,               const True)
-                          , (xsd_nonPositiveInteger,    (<=0)   )
-                          , (xsd_negativeInteger,       ( <0)   )
-                          , (xsd_nonNegativeInteger,    (>=0)   )
-                          , (xsd_positiveInteger,       ( >0)   )
-                          , (xsd_long,                  inR 9223372036854775808)
-                          , (xsd_int,                   inR 2147483648)
-                          , (xsd_short,                 inR 32768)
-                          , (xsd_byte,                  inR 128)
-                          , (xsd_unsignedLong,          inP 18446744073709551616)
-                          , (xsd_unsignedInt,           inP 4294967296)
-                          , (xsd_unsignedShort,         inP 65536)
-                          , (xsd_unsignedByte,          inP 256)
-                          ]
-                          where
-                          inR b i       = (0 - b) <= i && i < b
-                          inP b i       = 0 <= i       && i < b
-
--- ----------------------------------------
-
--- | List of allowed params for the list datatypes
-
-listParams      :: AllowedParams
-listParams      = xsd_pattern : map fst fctTableList
-
-listValid       :: DatatypeName -> ParamList -> CheckString
-listValid d     = stringValidFT fctTableList d 0 (-1)
-
--- ----------------------------------------
-
-isNameList      :: (String -> Bool) -> String -> Bool
-isNameList p w
-    = not (null ts) && all p ts
-      where
-      ts = words w
-
--- ----------------------------------------
-
-rex             :: String -> Regex
-rex             = either undefined id . parseRegex
-
-isRex           :: Regex -> String -> Bool
-isRex ex        = isNothing . matchWithRE ex
-
--- ----------------------------------------
-
-rexLanguage
-  , rexHexBinary
-  , rexBase64Binary
-  , rexDecimal
-  , rexInteger  :: Regex
-
-rexLanguage     = rex "[A-Za-z]{1,8}(-[A-Za-z]{1,8})*"
-rexHexBinary    = rex "([A-Fa-f0-9]{2})*"
-rexBase64Binary = rex $
-                  "(" ++ b64 ++ "{4})*((" ++ b64 ++ "{2}==)|(" ++ b64 ++ "{3}=)|)"
-                  where
-                  b64     = "[A-Za-z0-9+/]"
-rexDecimal      = rex "(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))"
-rexInteger      = rex "(\\+|-)?[0-9]+"
-
-isLanguage
-  , isHexBinary
-  , isBase64Binary
-  , isDecimal
-  , isInteger   :: String -> Bool
-
-isLanguage      = isRex rexLanguage
-isHexBinary     = isRex rexHexBinary
-isBase64Binary  = isRex rexBase64Binary
-isDecimal       = isRex rexDecimal
-isInteger       = isRex rexInteger
-
--- ----------------------------------------
-
-normBase64      :: String -> String
-normBase64      = filter isB64
-                  where
-                  isB64 c = ( 'A' <= c && c <= 'Z')
-                            ||
-                            ( 'a' <= c && c <= 'z')
-                            ||
-                            ( '0' <= c && c <= '9')
-                            ||
-                            c == '+'
-                            ||
-                            c == '/'
-                            ||
-                            c == '='
-
--- ----------------------------------------
-
-readDecimal
-  , readDecimal'        :: String -> Rational
-
-readDecimal ('+':s)     = readDecimal' s
-readDecimal ('-':s)     = negate (readDecimal' s)
-readDecimal      s      = readDecimal' s
-
-readDecimal' s
-    | f == 0    = (n % 1)
-    | otherwise = (n % 1) + (f % (10 ^ (toInteger (length fs))))
-    where
-    (ns, fs') = span (/= '.') s
-    fs = drop 1 fs'
-
-    f :: Integer
-    f | null fs         = 0
-      | otherwise       = read fs
-    n :: Integer
-    n | null ns         = 0
-      | otherwise       = read ns
-
-totalDigits
-  , totalDigits'
-  , fractionDigits      :: Rational -> Int
-
-totalDigits r
-    | r == 0                    = 0
-    | r < 0                     = totalDigits' . negate  $ r
-    | otherwise                 = totalDigits'           $ r
-
-totalDigits' r
-    | denominator r == 1        = length . show . numerator  $ r
-    | r < (1%1)                 = (\ x -> x-1) . totalDigits' . (+ (1%1))    $ r
-    | otherwise                 = totalDigits' . (* (10 % 1)) $ r
-
-fractionDigits r
-    | denominator r == 1        = 0
-    | otherwise                 = (+1) . fractionDigits . (* (10 % 1)) $ r
-
-showDecimal
-  , showDecimal'                :: Rational -> String
-
-showDecimal d
-    | d < 0     = ('-':) . showDecimal' . negate    $ d
-    | d < 1     = drop 1 . showDecimal' . (+ (1%1)) $ d
-    | otherwise =          showDecimal'             $ d
-
-showDecimal' d
-    | denominator d == 1        = show . numerator $ d
-    | otherwise                 = times10 0        $ d
-    where
-    times10 i' d'
-        | denominator d' == 1   = let
-                                  (x, y) = splitAt i' . reverse . show . numerator $ d'
-                                  in
-                                  reverse y ++ "." ++ reverse x
-        | otherwise             = times10 (i' + 1) (d' * (10 % 1))
-
--- ----------------------------------------
-
--- | Tests whether a XML instance value matches a data-pattern.
--- (see also: 'stringValid')
-
-datatypeAllowsW3C :: DatatypeAllows
-datatypeAllowsW3C d params value _
-    = performCheck check value
-    where
-    validString normFct
-        = validPattern
-          >>>
-          arr normFct
-          >>>
-          validLength
-
-    validNormString
-        = validString normalizeWhitespace
-
-    validPattern
-        = patternValid params
-
-    validLength
-        = stringValid d 0 (-1) params
-
-    validList
-        = validPattern
-          >>>
-          arr normalizeWhitespace
-          >>>
-          validListLength
-
-    validListLength
-        = listValid d params
-
-    validName isN
-        = assertW3C isN
-
-    validNCName
-        = validNormString >>> validName isNCName
-
-    validQName
-        = validNormString >>> validName isWellformedQualifiedName
-
-    validDecimal
-        = arr normalizeWhitespace
-          >>>
-          assertW3C isDecimal
-          >>>
-          checkWith readDecimal (decimalValid params)
-
-    validInteger inRange
-        = validPattern
-          >>>
-          arr normalizeWhitespace
-          >>>
-          assertW3C isInteger
-          >>>
-          checkWith read (integerValid inRange params)
-
-    check       :: CheckString
-    check       = fromMaybe notFound . lookup d $ checks
-
-    notFound    = failure $ errorMsgDataTypeNotAllowed w3cNS d params
-
-    checks      :: [(String, CheckA String String)]
-    checks      = [ (xsd_string,                validString id)
-                  , (xsd_normalizedString,      validString normalizeBlanks)
-                  , (xsd_token,                 validNormString)
-                  , (xsd_language,              validNormString >>> assertW3C isLanguage)
-                  , (xsd_NMTOKEN,               validNormString >>> validName isNmtoken)
-                  , (xsd_NMTOKENS,              validList       >>> validName (isNameList isNmtoken))
-                  , (xsd_Name,                  validNormString >>> validName isName)
-                  , (xsd_NCName,                validNCName)
-                  , (xsd_ID,                    validNCName)
-                  , (xsd_IDREF,                 validNCName)
-                  , (xsd_IDREFS,                validList       >>> validName (isNameList isNCName))
-                  , (xsd_ENTITY,                validNCName)
-                  , (xsd_ENTITIES,              validList       >>> validName (isNameList isNCName))
-                  , (xsd_anyURI,                validName isURIReference >>> validString escapeURI)
-                  , (xsd_QName,                 validQName)
-                  , (xsd_NOTATION,              validQName)
-                  , (xsd_hexBinary,             validString id         >>> assertW3C isHexBinary)
-                  , (xsd_base64Binary,          validString normBase64 >>> assertW3C isBase64Binary)
-                  , (xsd_decimal,               validPattern >>> validDecimal)
-                  , (xsd_integer,               validInteger xsd_integer)
-                  , (xsd_nonPositiveInteger,    validInteger xsd_nonPositiveInteger)
-                  , (xsd_negativeInteger,       validInteger xsd_negativeInteger)
-                  , (xsd_nonNegativeInteger,    validInteger xsd_nonNegativeInteger)
-                  , (xsd_positiveInteger,       validInteger xsd_positiveInteger)
-                  , (xsd_long,                  validInteger xsd_long)
-                  , (xsd_int,                   validInteger xsd_int)
-                  , (xsd_short,                 validInteger xsd_short)
-                  , (xsd_byte,                  validInteger xsd_byte)
-                  , (xsd_unsignedLong,          validInteger xsd_unsignedLong)
-                  , (xsd_unsignedInt,           validInteger xsd_unsignedInt)
-                  , (xsd_unsignedShort,         validInteger xsd_unsignedShort)
-                  , (xsd_unsignedByte,          validInteger xsd_unsignedByte)
-                  ]
-    assertW3C p = assert p errW3C
-    errW3C      = errorMsgDataLibQName w3cNS d
-
--- ----------------------------------------
-
--- | Tests whether a XML instance value matches a value-pattern.
-
-datatypeEqualW3C :: DatatypeEqual
-datatypeEqualW3C d s1 _ s2 _
-    = performCheck check (s1, s2)
-    where
-    check       :: CheckA (String, String) (String, String)
-    check       = maybe notFound found . lookup d $ norm
-
-    notFound    = failure $ const (errorMsgDataTypeNotAllowed0 w3cNS d)
-
-    found nf    = arr (\ (x1, x2) -> (nf x1, nf x2))                    -- normalize both values
-                  >>>
-                  assert (uncurry (==)) (uncurry $ errorMsgEqual d)     -- and check on (==)
-
-    norm = [ (xsd_string,               id                      )
-           , (xsd_normalizedString,     normalizeBlanks         )
-           , (xsd_token,                normalizeWhitespace     )
-           , (xsd_language,             normalizeWhitespace     )
-           , (xsd_NMTOKEN,              normalizeWhitespace     )
-           , (xsd_NMTOKENS,             normalizeWhitespace     )
-           , (xsd_Name,                 normalizeWhitespace     )
-           , (xsd_NCName,               normalizeWhitespace     )
-           , (xsd_ID,                   normalizeWhitespace     )
-           , (xsd_IDREF,                normalizeWhitespace     )
-           , (xsd_IDREFS,               normalizeWhitespace     )
-           , (xsd_ENTITY,               normalizeWhitespace     )
-           , (xsd_ENTITIES,             normalizeWhitespace     )
-           , (xsd_anyURI,               escapeURI . normalizeWhitespace )
-           , (xsd_QName,                normalizeWhitespace     )
-           , (xsd_NOTATION,             normalizeWhitespace     )
-           , (xsd_hexBinary,            id                      )
-           , (xsd_base64Binary,         normBase64              )
-           , (xsd_decimal,              show . readDecimal . normalizeWhitespace        )
-           ]
-
--- ----------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/XmlSchema/Regex.hs b/src/Text/XML/HXT/RelaxNG/XmlSchema/Regex.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/XmlSchema/Regex.hs
+++ /dev/null
@@ -1,317 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.XmlSchema.Regex
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
-   Portability: portable
-
-   W3C XML Schema Regular Expression Matcher
-
-   Grammar can be found under <http://www.w3.org/TR/xmlschema11-2/#regexs>
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.XmlSchema.Regex
-    ( Regex
-    , chars
-    , charRngs
-    , mkZero
-    , mkUnit
-    , mkSym
-    , mkSym1
-    , mkSymRng
-    , mkDot
-    , mkStar
-    , mkAlt
-    , mkSeq
-    , mkRep
-    , mkRng
-    , mkOpt
-    , mkDif
-    , mkCompl
-    , isZero
-    , nullable
-    , delta
-    , matchWithRE
-    , (<&&>)
-    , (<||>)
-    )
-where
-
-import Data.List        ( foldl' )
-
--- ------------------------------------------------------------
-
-data Regex      = Zero String
-                | Unit
-                | Sym (Char -> Bool)
-                | Dot
-                | Star Regex
-                | Alt Regex Regex
-                | Seq Regex Regex
-                | Rep Int Regex         -- 1 or more repetitions
-                | Rng Int Int Regex     -- n..m repetitions
-                | Dif Regex Regex       -- r1 - r2
-
--- ------------------------------------------------------------
-
-{- just for documentation
-
-class Inv a where
-    inv         :: a -> Bool
-
-instance Inv Regex where
-    inv (Zero _)        = True
-    inv Unit            = True
-    inv (Sym p)         = not . null . chars $ p
-    inv Dot             = True
-    inv (Star e)        = inv e
-    inv (Alt e1 e2)     = inv e1 &&
-                          inv e2
-    inv (Seq e1 e2)     = inv e1 &&
-                          inv e2
-    inv (Rep i e)       = i > 0 && inv e
-    inv (Rng i j e)     = (i < j || (i == j && i > 1)) &&
-                          inv e
-    inv (Dif e1 e2)     = inv e1 &&
-                          inv e2
--}
-
--- ------------------------------------------------------------
--- | enumerate all chars specified by a predicate
---
--- this function is expensive, it should only be used for testing
-
-chars                           :: (Char -> Bool) -> [Char]
-chars p                         = filter p $ [minBound .. maxBound]
-
-charRngs                        :: [Char] -> [(Char, Char)]
-charRngs []                     = []
-charRngs (x:xs)                 = charRng x xs
-                                where
-                                charRng y []            = (x,y) : []
-                                charRng y xs'@(x1:xs1)
-                                    | x1 == succ y      = charRng x1 xs1
-                                    | otherwise         = (x,y) : charRngs xs'
-
--- ------------------------------------------------------------
---
--- smart constructors
-
-mkZero                          :: String -> Regex
-mkZero                          = Zero
-{-# INLINE mkZero #-}
-
-mkUnit                          :: Regex
-mkUnit                          = Unit
-{-# INLINE mkUnit #-}
-
-mkSym                           :: (Char -> Bool) -> Regex
-mkSym                           = Sym
-{-# INLINE mkSym #-}
-
-mkSym1                          :: Char -> Regex
-mkSym1  c                       = mkSym (==c)
-
-mkSymRng                        :: Char -> Char -> Regex
-mkSymRng c1 c2
-    | c1 == minBound &&
-      c2 == maxBound            = mkDot
-    | c1 <= c2                  = mkSym  $ (>= c1) <&&> (<= c2)
-    | otherwise                 = mkZero $ "empty char range"
-
-mkDot                           :: Regex
-mkDot                           = Dot
-{-# INLINE mkDot #-}
-
-mkStar                          :: Regex -> Regex
-mkStar (Zero _)                 = mkUnit                -- {}* == ()
-mkStar e@Unit                   = e                     -- ()* == ()
-mkStar e@(Star _e1)             = e                     -- (r*)* == r*
-mkStar (Rep 1 e1)               = mkStar e1             -- (r+)* == r*
-mkStar e@(Alt _ _)              = Star (rmStar e)       -- (a*|b)* == (a|b)*
-mkStar e                        = Star e
-
-rmStar                          :: Regex -> Regex
-rmStar (Alt e1 e2)              = mkAlt (rmStar e1) (rmStar e2)
-rmStar (Star e1)                = rmStar e1
-rmStar (Rep 1 e1)               = rmStar e1
-rmStar e1                       = e1
-
-mkAlt                                   :: Regex -> Regex -> Regex
-mkAlt e1            (Zero _)            = e1                            -- e1 u {} = e1
-mkAlt (Zero _)      e2                  = e2                            -- {} u e2 = e2
-mkAlt e1@(Star Dot) _e2                 = e1                            -- A* u e1 = A*
-mkAlt _e1           e2@(Star Dot)       = e2                            -- e1 u A* = A*
-mkAlt (Sym p1)      (Sym p2)            = mkSym $ p1 <||> p2            -- melting of predicates
-mkAlt e1            e2@(Sym _)          = mkAlt e2 e1                   -- symmetry: predicates always first
-mkAlt e1@(Sym _)    (Alt e2@(Sym _) e3) = mkAlt (mkAlt e1 e2) e3        -- prepare melting of predicates
-mkAlt (Alt e1 e2)   e3                  = mkAlt e1 (mkAlt e2 e3)        -- associativity
-mkAlt e1 e2                             = Alt e1 e2
-
-mkSeq                           :: Regex -> Regex -> Regex
-mkSeq e1@(Zero _) _e2           = e1
-mkSeq _e1         e2@(Zero _)   = e2
-mkSeq Unit        e2            = e2
-mkSeq e1          Unit          = e1
-mkSeq (Seq e1 e2) e3            = mkSeq e1 (mkSeq e2 e3)
-mkSeq e1 e2                     = Seq e1 e2
-
-mkRep           :: Int -> Regex -> Regex
-mkRep 0 e                       = mkStar e
-mkRep _ e@(Zero _)              = e
-mkRep _ e@Unit                  = e
-mkRep i e                       = Rep i e
-
-mkRng   :: Int -> Int -> Regex -> Regex
-mkRng 0  0  _e                  = mkUnit
-mkRng 1  1  e                   = e
-mkRng lb ub _e
-    | lb > ub                   = Zero $
-                                  "illegal range " ++
-                                  show lb ++ ".." ++ show ub
-mkRng _l _u e@(Zero _)          = e
-mkRng _l _u e@Unit              = e
-mkRng lb ub e                   = Rng lb ub e
-
-mkOpt                           :: Regex -> Regex
-mkOpt                           = mkRng 0 1
-
-mkDif   :: Regex -> Regex -> Regex
-mkDif e1@(Zero _) _e2           = e1
-mkDif e1          (Zero _)      = e1
-mkDif _e1         (Star Dot)    = mkZero "empty set in difference expr"
-mkDif Dot         (Sym p)       = mkSym (not . p)
-mkDif (Sym _)     Dot           = mkZero "empty set of chars in difference expr"
-mkDif (Sym p1)    (Sym p2)
-    | null . chars $ (\ x -> p1 x && not (p2 x))
-                                = mkZero "empty set of chars in difference expr"
-mkDif e1          e2            = Dif e1 e2
-
-mkCompl                         :: Regex -> Regex
-mkCompl                         = mkDif mkDot
-
--- ------------------------------------------------------------
-
-instance Show Regex where
-    show (Zero s)       = "{err:" ++ s ++ "}"
-    show Unit           = "()"
-    show (Sym p)
-        | null (tail cs) &&
-          rng1 (head cs)
-                        = escRng . head $ cs
-        | otherwise     = "[" ++ concat cs' ++ "]"
-                          where
-                          rng1 (x,y)    = x == y
-                          cs            = charRngs . chars $ p
-                          cs'           = map escRng cs
-                          escRng (x, y)
-                              | x == y  = esc x
-                              | succ x == y
-                                        = esc x        ++ esc y
-                              | otherwise
-                                        = esc x ++ "-" ++ esc y
-                          esc x
-                              | x `elem` "\\-[]{}()*+?.^"
-                                        = '\\':x:""
-                              | x >= ' ' && x <= '~'
-                                        = x:""
-                              | otherwise
-                                        = "&#" ++ show (fromEnum x) ++ ";"
-    show Dot            = "."
-    show (Star e)       = "(" ++ show e ++ ")*"
-    show (Alt e1 e2)    = "(" ++ show e1 ++ "|" ++ show e2 ++ ")"
-    show (Seq e1 e2)    = show e1 ++ show e2
-    show (Rep 1 e)      = "(" ++ show e ++ ")+"
-    show (Rep i e)      = "(" ++ show e ++ "){" ++ show i ++ ",}"
-    show (Rng 0 1 e)    = "(" ++ show e ++ ")?"
-    show (Rng i j e)    = "(" ++ show e ++ "){" ++ show i ++ "," ++ show j ++ "}"
-    show (Dif e1 e2)    = "(" ++ show e1 ++ "-" ++ show e2 ++ ")"
-
--- ------------------------------------------------------------
-
-isZero                  :: Regex -> Bool
-isZero (Zero _)         = True
-isZero _                = False
-{-# INLINE isZero #-}
-
-nullable                :: Regex -> Bool
-nullable (Zero _)       = False
-nullable Unit           = True
-nullable (Sym _p)       = False         -- assumption: p holds for at least one char
-nullable Dot            = False
-nullable (Star _)       = True
-nullable (Alt e1 e2)    = nullable e1 ||
-                          nullable e2
-nullable (Seq e1 e2)    = nullable e1 &&
-                          nullable e2
-nullable (Rep _i e)     = nullable e
-nullable (Rng i _ e)    = i == 0 ||
-                          nullable e
-nullable (Dif e1 e2)    = nullable e1 &&
-                          not (nullable e2)
-
--- ------------------------------------------------------------
-
-delta   :: Regex -> Char -> Regex
-delta e@(Zero _)  _     = e
-delta Unit        c     = mkZero $
-                          "unexpected char " ++ show c
-delta (Sym p)     c
-    | p c               = mkUnit
-    | otherwise         = mkZero $
-                          "unexpected char " ++ show c ++ ", expected: " ++ oneof ++ chars'
-                          where
-                          (cs, ds) = splitAt 40 (chars p)
-                          oneof
-                              | null (tail cs) = ""
-                              | otherwise      = "one of "
-                          chars'
-                              | null (tail cs) = "'" ++ cs ++ "'"
-                              | null ds   = "[" ++ cs ++ "]"
-                              | otherwise = "[" ++ cs ++ "...]"
-
-delta Dot         _     = mkUnit
-delta e@(Star e1) c     = mkSeq (delta e1 c) e
-delta (Alt e1 e2) c     = mkAlt (delta e1 c) (delta e2 c)
-delta (Seq e1 e2) c
-    | nullable e1       = mkAlt (mkSeq (delta e1 c) e2) (delta e2 c)
-    | otherwise         = mkSeq (delta e1 c) e2
-delta (Rep i e)   c     = mkSeq (delta e c) (mkRep (i-1) e)
-delta (Rng i j e) c     = mkSeq (delta e c) (mkRng ((i-1) `max` 0) (j-1) e)
-delta (Dif e1 e2) c     = mkDif (delta e1 c) (delta e2 c)
-
--- ------------------------------------------------------------
-
-delta'          :: Regex -> String -> Regex
-delta'          = foldl' delta
-
-matchWithRE             :: Regex -> String -> Maybe String
-matchWithRE e
-    = res . delta' e
-    where
-    res (Zero err)      = Just err
-    res re
-        | nullable re   = Nothing       -- o.k.
-        | otherwise     = Just $ "input does not match " ++ show e
-
--- ------------------------------------------------------------
-
-(<&&>)          :: (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool)
-f <&&> g        = \ x -> f x && g x             -- liftA2 (&&)
-
-{-# INLINE (<&&>) #-}
-
-
-(<||>)          :: (Char -> Bool) -> (Char -> Bool) -> (Char -> Bool)
-f <||> g        = \ x -> f x || g x             -- liftA2 (||)
-
-{-# INLINE (<||>) #-}
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/RelaxNG/XmlSchema/RegexMatch.hs b/src/Text/XML/HXT/RelaxNG/XmlSchema/RegexMatch.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/XmlSchema/RegexMatch.hs
+++ /dev/null
@@ -1,241 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.XmlSchema.RegexMatch
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
-   Portability: portable
-
-   Convenient functions for W3C XML Schema Regular Expression Matcher.
-   For internals see 'Text.XML.HXT.RelaxNG.XmlSchema.Regex'
-
-   Grammar can be found under <http://www.w3.org/TR/xmlschema11-2/#regexs>
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.XmlSchema.RegexMatch
-    ( matchRE
-    , splitRE
-    , sedRE
-    , tokenizeRE
-    , tokenizeRE'
-
-    , match
-    , tokenize
-    , tokenize'
-    , sed
-    , split
-
-    , splitRegex
-    )
-where
-
-import Data.Maybe
-
-import Text.XML.HXT.RelaxNG.XmlSchema.Regex
-import Text.XML.HXT.RelaxNG.XmlSchema.RegexParser
-
-{-
-import qualified Debug.Trace as T
--}
-
--- ------------------------------------------------------------
-
-splitRegex              :: Regex -> String -> Maybe (String, String)
-splitRegex re ""
-    | nullable re       = Just ("", "")
-    | otherwise         = Nothing
-
-splitRegex re inp@(c : inp')
-    | isZero   re       = Nothing
-    | otherwise         = evalRes . splitRegex {- (T.trace (show re') re') -} re' $ inp'
-    where
-    re' = delta re c
-    evalRes Nothing
-        | nullable re   = Just ("", inp)
-        | otherwise     = Nothing
-
-    evalRes (Just (tok, rest))
-                        = Just (c : tok, rest)
-
--- ------------------------------------------------------------
-
--- | split a string by taking the longest prefix matching a regular expression
---
--- @Nothing@ is returned in case of a syntactically wrong regex string
--- or in case there is no matching prefix, else the pair of prefix and rest is returned
---
--- examples:
---
--- > splitRE "a*b" "abc" = Just ("ab","c")
--- > splitRE "a*"  "bc"  = Just ("", "bc")
--- > splitRE "a+"  "bc"  = Nothing
--- > splitRE "["   "abc" = Nothing
-
-splitRE :: String -> String -> Maybe (String, String)
-splitRE re input
-    = either (const Nothing) (flip splitRegex input) . parseRegex $ re
-
--- | convenient function for splitRE
---
--- syntax errors in R.E. are interpreted as no matching prefix found
-
-split           :: String -> String -> (String, String)
-split re input
-    = fromMaybe ("", input) . splitRE re $ input
-
--- ------------------------------------------------------------
-
--- | split a string into tokens (words) by giving a regular expression
--- which all tokens must match
---
--- This can be used for simple tokenizers.
--- The words in the result list contain at least one char.
--- All none matching chars are discarded. If the given regex contains syntax errors,
--- @Nothing@ is returned
---
--- examples:
---
--- > tokenizeRE "a*b" ""         = Just []
--- > tokenizeRE "a*b" "abc"      = Just ["ab"]
--- > tokenizeRE "a*b" "abaab ab" = Just ["ab","aab","ab"]
--- >
--- > tokenizeRE "[a-z]{2,}|[0-9]{2,}|[0-9]+[.][0-9]+" "ab123 456.7abc"
--- >                                = Just ["ab","123","456.7","abc"]
--- >
--- > tokenizeRE "[a-z]*|[0-9]{2,}|[0-9]+[.][0-9]+" "cab123 456.7abc"
--- >                                = Just ["cab","123","456.7","abc"]
--- >
--- > tokenizeRE "[^ \t\n\r]*" "abc def\t\n\rxyz"
--- >                                = Just ["abc","def","xyz"]
--- >
--- > tokenizeRE "[^ \t\n\r]*"    = words
-
-tokenizeRE      :: String -> String -> Maybe [String]
-tokenizeRE regex input
-    = either (const Nothing) (Just . flip token' input) $ parseRegex regex
-    where
-    token'      :: Regex -> String -> [String]
-    token' re inp
-        | null inp      = []
-        | otherwise     = evalRes . splitRegex re $ inp
-        where
-        token''         = token' re
-        evalRes Nothing = token'' (tail inp)            -- re does not match any prefix
-        evalRes (Just (tok, rest))
-            | null tok  = token'' (tail rest)           -- re is nullable and only the empty prefix matches
-            | otherwise = tok : token'' rest            -- token found, tokenize the rest
-
--- | convenient function for tokenizeRE a string
---
--- syntax errors in R.E. result in an empty list
-
-tokenize        :: String -> String -> [String]
-tokenize re
-    = fromMaybe [] . tokenizeRE re
-
--- ------------------------------------------------------------
-
--- | split a string into tokens and delimierter by giving a regular expression
--- wich all tokens must match
---
--- This is a generalisation of the above 'tokenizeRE' functions.
--- The none matching char sequences are marked with @Left@, the matching ones are marked with @Right@
---
--- If the regular expression contains syntax errors @Nothing@ is returned
---
--- The following Law holds:
---
--- > concat . map (either id id) . fromJust . tokenizeRE' re == id
-
-tokenizeRE'     :: String -> String -> Maybe [Either String String]
-tokenizeRE' regex input
-    = either (const Nothing) (Just . flip token' input) $ parseRegex regex
-    where
-    token'      :: Regex -> String -> [Either String String]
-    token' re
-        = tok2 ""
-        where
-        tok2 :: String -> String -> [Either String String]
-        tok2 noMatchPrefix inp
-            | null inp  = addNoMatch []
-            | otherwise = evalRes . splitRegex re $ inp
-            where
-            addNoMatch res
-                | null noMatchPrefix    = res
-                | otherwise             = (Left . reverse $ noMatchPrefix) : res
-
-            evalRes Nothing             = tok2 (head inp : noMatchPrefix) (tail inp)            -- re does not match any prefix
-            evalRes (Just (tok, rest))
-                | null tok              = tok2 (head rest : noMatchPrefix) (tail rest)          -- re is nullable and only the empty prefix matches
-                | otherwise             = addNoMatch . (Right tok :) . tok2 "" $ rest           -- token found, tokenize the rest
-
--- | convenient function for tokenizeRE'
---
--- When the regular expression contains errors @[Left input]@ is returned, that means tokens are found
-
-tokenize'       :: String -> String -> [Either String String]
-tokenize' regex input
-    = fromMaybe [Left input] . tokenizeRE' regex $ input
-
--- ------------------------------------------------------------
-
--- | sed like editing function
---
--- All matching tokens are edited by the 1. argument, the editing function,
--- all other chars remain as they are
---
--- examples:
---
--- > sedRE (const "b") "a" "xaxax"       = Just "xbxbx"
--- > sedRE (\ x -> x ++ x) "a" "xax"     = Just "xaax"
--- > sedRE undefined       "[" undefined = Nothing
-
-sedRE           :: (String -> String) -> String -> String -> Maybe String
-sedRE edit regex input
-    = maybe Nothing (Just . concatMap (either id edit)) $ tokenizeRE' regex input
-
--- | convenient function for sedRE
---
--- When the regular expression contains errors, sed is the identity, else
--- the funtionality is like 'sedRE'
---
--- > sed undefined "["  == id
-
-sed             :: (String -> String) -> String -> String -> String
-sed edit regex input
-    = fromMaybe input . sedRE edit regex $ input
-
--- ------------------------------------------------------------
-
--- | match a string with a regular expression
---
--- First argument is the regex, second the input string,
--- if the regex is not well formed, @Nothing@ is returned,
--- else @Just@ the match result
---
--- Examples:
---
--- > matchRE "x*" "xxx" = Just True
--- > matchRE "x" "xxx"  = Just False
--- > matchRE "[" "xxx"  = Nothing
-
-matchRE :: String -> String -> Maybe Bool
-matchRE regex input
-    = either (const Nothing) (Just . isNothing . flip matchWithRE input) $ parseRegex regex
-
-
--- | convenient function for matchRE
---
--- syntax errors in R.E. are interpreted as no match found
-
-match           :: String -> String -> Bool
-match re        = fromMaybe False . matchRE re
-
--- ------------------------------------------------------------
-
diff --git a/src/Text/XML/HXT/RelaxNG/XmlSchema/RegexParser.hs b/src/Text/XML/HXT/RelaxNG/XmlSchema/RegexParser.hs
deleted file mode 100644
--- a/src/Text/XML/HXT/RelaxNG/XmlSchema/RegexParser.hs
+++ /dev/null
@@ -1,354 +0,0 @@
--- ------------------------------------------------------------
-
-{- |
-   Module     : Text.XML.HXT.RelaxNG.XmlSchema.RegexParser
-   Copyright  : Copyright (C) 2005 Uwe Schmidt
-   License    : MIT
-
-   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
-   Stability  : experimental
-   Portability: portable
-
-   W3C XML Schema Regular Expression Parser
-
-   This parser supports the full W3C standard, the
-   complete grammar can be found under <http://www.w3.org/TR/xmlschema11-2/#regexs>
-
--}
-
--- ------------------------------------------------------------
-
-module Text.XML.HXT.RelaxNG.XmlSchema.RegexParser
-    ( parseRegex )
-where
-
-import Data.Maybe
-
-import Text.ParserCombinators.Parsec
-
-import Text.XML.HXT.DOM.Unicode
-
-import Text.XML.HXT.RelaxNG.Unicode.Blocks
-import Text.XML.HXT.RelaxNG.Unicode.CharProps
-import Text.XML.HXT.RelaxNG.XmlSchema.Regex
-
--- ------------------------------------------------------------
-
-parseRegex :: String -> Either String Regex
-parseRegex
-    = either (Left . show) Right
-      .
-      parse ( do
-              r <- regExp
-              eof
-              return r
-            ) ""
-
--- ------------------------------------------------------------
-
-regExp  :: Parser Regex
-regExp
-    = do
-      r1 <- branch
-      rs <- many branch1
-      return (foldr1 mkAlt $ r1:rs)
-    where
-    branch1
-        = do
-          _ <- char '|'
-          branch
-
-branch  :: Parser Regex
-branch
-    = do
-      rs <- many piece
-      return $ foldr mkSeq mkUnit rs
-
-piece   :: Parser Regex
-piece
-    = do
-      r <- atom
-      quantifier r
-
-quantifier      :: Regex -> Parser Regex
-quantifier r
-    = ( do
-        _ <- char '?'
-        return $ mkOpt r )
-      <|>
-      ( do
-        _ <- char '*'
-        return $ mkStar r )
-      <|>
-      ( do
-        _ <- char '+'
-        return $ mkRep 1 r )
-      <|>
-      ( do
-        _ <- char '{'
-        res <- quantity r
-        _ <- char '}'
-        return res
-      )
-      <|>
-      ( return r )
-
-quantity        :: Regex -> Parser Regex
-quantity r
-    = do
-      lb <- many1 digit
-      quantityRest r (read lb)
-
-quantityRest    :: Regex -> Int -> Parser Regex
-quantityRest r lb
-    = ( do
-        _ <- char ','
-        ub <- many digit
-        return ( if null ub
-                 then mkRep lb r
-                 else mkRng lb (read ub) r
-               )
-      )
-      <|>
-      ( return $ mkRng lb lb r)
-
-atom    :: Parser Regex
-atom
-    = char1
-      <|>
-      charClass
-      <|>
-      between (char '(') (char ')') regExp
-
-char1   :: Parser Regex
-char1
-    = do
-      c <- satisfy $ (`notElem` ".\\?*+{}()|[]")
-      return $ mkSym1 c
-
-charClass       :: Parser Regex
-charClass
-    = charClassEsc
-      <|>
-      charClassExpr
-      <|>
-      wildCardEsc
-
-charClassEsc    :: Parser Regex
-charClassEsc
-    = do
-      _ <- char '\\'
-      ( singleCharEsc
-        <|>
-        multiCharEsc
-        <|>
-        catEsc
-        <|>
-        complEsc )
-
-singleCharEsc   :: Parser Regex
-singleCharEsc
-    = do
-      c <- singleCharEsc'
-      return $ mkSym1 c
-
-singleCharEsc'  :: Parser Char
-singleCharEsc'
-    = do
-      c <- satisfy (`elem` "nrt\\|.?*+(){}-[]^")
-      return $ maybe c id . lookup c . zip "ntr" $ "\n\r\t"
-
-multiCharEsc    :: Parser Regex
-multiCharEsc
-    = do
-      c <- satisfy (`elem` es)
-      return $ mkSym . fromJust . lookup c $ pm
-    where
-    es = map fst pm
-    pm = [ ('s',       isXmlSpaceChar           )
-         , ('S', not . isXmlSpaceChar           )
-         , ('i',       isXmlNameStartChar       )
-         , ('I', not . isXmlNameStartChar       )
-         , ('c',       isXmlNameChar            )
-         , ('C', not . isXmlNameChar            )
-         , ('d',       isDigit                  )
-         , ('D', not . isDigit                  )
-         , ('w', not . isNotWord                )
-         , ('W',       isNotWord                )
-         ]
-    isDigit   = ('0' <=) <&&> (<= '9')
-    isNotWord = isUnicodeP <||>
-                isUnicodeZ <||>
-                isUnicodeC
-
-catEsc  :: Parser Regex
-catEsc
-    = do
-      _ <- char 'p'
-      s <- between (char '{') (char '}') charProp
-      return $ mkSym s
-
-charProp        :: Parser (Char -> Bool)
-charProp
-    = isCategory
-      <|>
-      isBlock
-
-isBlock         :: Parser (Char -> Bool)
-isBlock
-    = do
-      _ <- string "Is"
-      name <- many1 (satisfy legalChar)
-      let b = lookup name codeBlocks
-      if isJust b
-         then return $ let
-                       (lb, ub) = fromJust b
-                       in
-                       (lb <=) <&&> (<= ub)
-         else fail   $ "unknown Unicode code block " ++ show name
-    where
-    legalChar c  = 'A' <= c && c <= 'Z' ||
-                   'a' <= c && c <= 'z' ||
-                   '0' <= c && c <= '9' ||
-                   '-' == c
-
-isCategory      :: Parser (Char -> Bool)
-isCategory
-    = do
-      pr <- isCategory'
-      return $ fromJust (lookup pr categories)
-
-categories      :: [(String, Char -> Bool)]
-categories
-    = [ ("C",  isUnicodeC )
-      , ("Cc", isUnicodeCc)
-      , ("Cf", isUnicodeCf)
-      , ("Co", isUnicodeCo)
-      , ("Cs", isUnicodeCs)
-      , ("L",  isUnicodeL )
-      , ("Ll", isUnicodeLl)
-      , ("Lm", isUnicodeLm)
-      , ("Lo", isUnicodeLo)
-      , ("Lt", isUnicodeLt)
-      , ("Lu", isUnicodeLu)
-      , ("M",  isUnicodeM )
-      , ("Mc", isUnicodeMc)
-      , ("Me", isUnicodeMe)
-      , ("Mn", isUnicodeMn)
-      , ("N",  isUnicodeN )
-      , ("Nd", isUnicodeNd)
-      , ("Nl", isUnicodeNl)
-      , ("No", isUnicodeNo)
-      , ("P",  isUnicodeP )
-      , ("Pc", isUnicodePc)
-      , ("Pd", isUnicodePd)
-      , ("Pe", isUnicodePe)
-      , ("Pf", isUnicodePf)
-      , ("Pi", isUnicodePi)
-      , ("Po", isUnicodePo)
-      , ("Ps", isUnicodePs)
-      , ("S",  isUnicodeS )
-      , ("Sc", isUnicodeSc)
-      , ("Sk", isUnicodeSk)
-      , ("Sm", isUnicodeSm)
-      , ("So", isUnicodeSo)
-      , ("Z",  isUnicodeZ )
-      , ("Zl", isUnicodeZl)
-      , ("Zp", isUnicodeZp)
-      , ("Zs", isUnicodeZs)
-      ]
-
-isCategory'     :: Parser String
-isCategory'
-    = ( foldr1 (<|>) . map (uncurry prop) $
-        [ ('L', "ultmo")
-        , ('M', "nce")
-        , ('N', "dlo")
-        , ('P', "cdseifo")
-        , ('Z', "slp")
-        , ('S', "mcko")
-        , ('C', "cfon")
-        ]
-      ) <?> "illegal Unicode character property"
-    where
-    prop c1 cs2
-        = do
-          _ <- char c1
-          s2 <- option ""
-                ( do
-                  c2 <- satisfy (`elem` cs2)
-                  return [c2] )
-          return $ c1:s2
-
-complEsc        :: Parser Regex
-complEsc
-    = do
-      _ <- char 'P'
-      s <- between (char '{') (char '}') charProp
-      return $ mkSym (not . s)
-
-charClassExpr   :: Parser Regex
-charClassExpr
-    = between (char '[') (char ']') charGroup
-
-charGroup       :: Parser Regex
-charGroup
-    = do
-      r <- ( negCharGroup       -- a ^ at beginning denotes negation, not start of posCharGroup
-             <|>
-             posCharGroup
-           )
-      s <- option (mkZero "")   -- charClassSub
-           ( do
-             _ <- char '-'
-             charClassExpr
-           )
-      return $ mkDif r s
-
-posCharGroup    :: Parser Regex
-posCharGroup
-    = do
-      rs <- many1 (charRange <|> charClassEsc)
-      return $ foldr1 mkAlt rs
-
-charRange       :: Parser Regex
-charRange
-    = try seRange
-      <|>
-      xmlCharIncDash
-
-seRange :: Parser Regex
-seRange
-    = do
-      c1 <- charOrEsc'
-      _ <- char '-'
-      c2 <- charOrEsc'
-      return $ mkSymRng c1 c2
-
-charOrEsc'      :: Parser Char
-charOrEsc'
-    = satisfy (`notElem` "\\-[]")
-      <|>
-      singleCharEsc'
-
-xmlCharIncDash  :: Parser Regex
-xmlCharIncDash
-    = do
-      c <- satisfy (`notElem` "\\[]")
-      return $ mkSym1 c
-
-negCharGroup    :: Parser Regex
-negCharGroup
-    = do
-      _ <- char '^'
-      r <- posCharGroup
-      return $ mkCompl r
-
-wildCardEsc     :: Parser Regex
-wildCardEsc
-    = do
-      _ <- char '.'
-      return $ mkSym (`notElem` "\n\r")
-
-
--- ------------------------------------------------------------
diff --git a/src/Text/XML/HXT/XMLSchema/DataTypeLibW3CNames.hs b/src/Text/XML/HXT/XMLSchema/DataTypeLibW3CNames.hs
new file mode 100644
--- /dev/null
+++ b/src/Text/XML/HXT/XMLSchema/DataTypeLibW3CNames.hs
@@ -0,0 +1,124 @@
+-- ------------------------------------------------------------
+
+{- |
+   Module     : Text.XML.HXT.XMLSchema.DataTypeLibW3C
+   Copyright  : Copyright (C) 2005-2010 Uwe Schmidt
+   License    : MIT
+
+   Maintainer : Uwe Schmidt (uwe@fh-wedel.de)
+   Stability  : experimental
+   Portability: portable
+   Version    : $Id$
+
+   Datatype library for the W3C XML schema datatypes
+
+-}
+
+-- ------------------------------------------------------------
+
+module Text.XML.HXT.XMLSchema.DataTypeLibW3CNames
+where
+
+-- ------------------------------------------------------------
+
+-- | Namespace of the W3C XML schema datatype library
+
+w3cNS   :: String
+w3cNS   = "http://www.w3.org/2001/XMLSchema-datatypes"
+
+
+xsd_string
+ , xsd_normalizedString
+ , xsd_token
+ , xsd_language
+ , xsd_NMTOKEN
+ , xsd_NMTOKENS
+ , xsd_Name
+ , xsd_NCName
+ , xsd_ID
+ , xsd_IDREF
+ , xsd_IDREFS
+ , xsd_ENTITY
+ , xsd_ENTITIES
+ , xsd_anyURI
+ , xsd_QName
+ , xsd_NOTATION
+ , xsd_hexBinary
+ , xsd_base64Binary
+ , xsd_decimal
+ , xsd_integer
+ , xsd_nonPositiveInteger
+ , xsd_negativeInteger
+ , xsd_nonNegativeInteger
+ , xsd_positiveInteger
+ , xsd_long
+ , xsd_int
+ , xsd_short
+ , xsd_byte
+ , xsd_unsignedLong
+ , xsd_unsignedInt
+ , xsd_unsignedShort
+ , xsd_unsignedByte :: String
+
+xsd_string              = "string"
+xsd_normalizedString    = "normalizedString"
+xsd_token               = "token"
+xsd_language            = "language"
+xsd_NMTOKEN             = "NMTOKEN"
+xsd_NMTOKENS            = "NMTOKENS"
+xsd_Name                = "Name"
+xsd_NCName              = "NCName"
+xsd_ID                  = "ID"
+xsd_IDREF               = "IDREF"
+xsd_IDREFS              = "IDREFS"
+xsd_ENTITY              = "ENTITY"
+xsd_ENTITIES            = "ENTITIES"
+xsd_anyURI              = "anyURI"
+xsd_QName               = "QName"
+xsd_NOTATION            = "NOTATION"
+xsd_hexBinary           = "hexBinary"
+xsd_base64Binary        = "base64Binary"
+xsd_decimal             = "decimal"
+xsd_integer             = "integer"
+xsd_nonPositiveInteger  = "nonPositiveInteger"
+xsd_negativeInteger     = "negativeInteger"
+xsd_nonNegativeInteger  = "nonNegativeInteger"
+xsd_positiveInteger     = "positiveInteger"
+xsd_long                = "long"
+xsd_int                 = "int"
+xsd_short               = "short"
+xsd_byte                = "byte"
+xsd_unsignedLong        = "unsignedLong"
+xsd_unsignedInt         = "unsignedInt"
+xsd_unsignedShort       = "unsignedShort"
+xsd_unsignedByte        = "unsignedByte"
+
+
+xsd_length
+ , xsd_maxLength
+ , xsd_minLength
+ , xsd_maxExclusive
+ , xsd_minExclusive
+ , xsd_maxInclusive
+ , xsd_minInclusive
+ , xsd_totalDigits
+ , xsd_fractionDigits
+ , xsd_pattern
+ , xsd_enumeration :: String
+
+xsd_length              = "length"
+xsd_maxLength           = "maxLength"
+xsd_minLength           = "minLength"
+
+xsd_maxExclusive        = "maxExclusive"
+xsd_minExclusive        = "minExclusive"
+xsd_maxInclusive        = "maxInclusive"
+xsd_minInclusive        = "minInclusive"
+
+xsd_totalDigits         = "totalDigits"
+xsd_fractionDigits      = "fractionDigits"
+
+xsd_pattern             = "pattern"
+xsd_enumeration         = "enumeration"
+
+-- ----------------------------------------
