1 module Rakka.Validation
7 import Control.Arrow.ArrowList
8 import Control.Arrow.ArrowTree
9 import Control.Monad.Reader
10 import Paths_Rakka -- Cabal が用意する。
11 import Rakka.Environment
12 import System.Directory
13 import System.FilePath
14 import Text.XML.HXT.Arrow.XmlArrow
15 import Text.XML.HXT.Arrow.XmlIOStateArrow
16 import Text.XML.HXT.DOM.TypeDefs
17 import qualified Text.XML.HXT.RelaxNG.Schema as S
18 import Text.XML.HXT.RelaxNG.Validator
21 loadSchema :: FilePath -> IO (IOSArrow XmlTree XmlTree)
23 = do [schema] <- runX ( setErrorMsgHandler False fail
27 perform (validateWithRelaxAndHandleErrors S.relaxSchemaArrow)
29 createSimpleForm [] True True True
33 getChildren >>> getAttrValue "desc"
35 arr ("Relax NG validation: " ++ )
42 return $ validateDocumentWithRelax schema
45 doesLocalDirExist :: IO Bool
46 doesLocalDirExist = doesDirectoryExist "schemas"
49 getValidator :: MonadIO m => Environment -> FilePath -> m (IOSArrow XmlTree XmlTree)
52 do let schemaPath = "schemas" </> fname
54 localDirExists <- doesLocalDirExist
55 if localDirExists then
58 getDataFileName ("schemas" </> fname) >>= loadSchema