This module provides the XmlContent
class and readXml
and writeXml
functions that you will need if you generate a module of Haskell
datatype definitions from an XML DTD. Use the DtdToHaskell
program to generate both datatypes and instances of this class,
then import this module to read and write values to and from XML files.
- readXml :: XmlContent a => String -> Maybe a
- showXml :: XmlContent a => a -> String
- hGetXml :: XmlContent a => Handle -> IO a
- hPutXml :: XmlContent a => Handle -> a -> IO ()
- fReadXml :: XmlContent a => FilePath -> IO a
- fWriteXml :: XmlContent a => FilePath -> a -> IO ()
- class XmlContent a where
- class XmlAttributes a where
- class XmlAttrType a where
- fromAttrToTyp :: String -> Attribute -> Maybe a
- toAttrFrTyp :: String -> a -> Maybe Attribute
- choice :: XmlContent a => (a -> b) -> ([Content] -> (Maybe b, [Content])) -> [Content] -> (Maybe b, [Content])
- definite :: ([Content] -> (Maybe a, [Content])) -> String -> String -> [Content] -> (a, [Content])
- many :: ([Content] -> (Maybe a, [Content])) -> [Content] -> ([a], [Content])
- fromText :: [Content] -> (Maybe String, [Content])
- toText :: String -> [Content]
- data List1 a = NonEmpty [a]
- data ANYContent = ANYContent
- maybeToAttr :: (String -> a -> Maybe Attribute) -> String -> Maybe a -> Maybe Attribute
- defaultToAttr :: (String -> a -> Maybe Attribute) -> String -> Defaultable a -> Maybe Attribute
- definiteA :: (String -> Attribute -> Maybe a) -> String -> String -> [Attribute] -> a
- defaultA :: (String -> Attribute -> Maybe a) -> a -> String -> [Attribute] -> Defaultable a
- possibleA :: (String -> Attribute -> Maybe a) -> String -> [Attribute] -> Maybe a
- fromAttrToStr :: String -> Attribute -> Maybe String
- toAttrFrStr :: String -> String -> Maybe Attribute
- data Defaultable a
- = Default a
- | NonDefault a
- str2attr :: String -> AttValue
- attr2str :: AttValue -> String
- data Element = Elem Name [Attribute] [Content]
- data Content
- catMaybes :: [Maybe a] -> [a]
Reading and writing XML data into a typed Haskell representation.
readXml :: XmlContent a => String -> Maybe aSource
Read a fully-typed XML document from a string.
showXml :: XmlContent a => a -> StringSource
Convert a fully-typed XML document to a string.
hGetXml :: XmlContent a => Handle -> IO aSource
Read a fully-typed XML document from a file handle.
hPutXml :: XmlContent a => Handle -> a -> IO ()Source
Write a fully-typed XML document to a file handle.
fReadXml :: XmlContent a => FilePath -> IO aSource
Read an XML document from a file and convert it to a fully-typed Haskell value.
fWriteXml :: XmlContent a => FilePath -> a -> IO ()Source
Write a fully-typed Haskell value to the given file as an XML document.
The enabling classes.
class XmlContent a whereSource
The XmlContent class promises that an XML content element can be converted to and from a Haskell value.
class XmlAttributes a whereSource
The XmlAttributes class promises that a list of XML tag attributes can be converted to and from a Haskell value.
class XmlAttrType a whereSource
The XmlAttrType class promises that an attribute taking an XML enumerated type can be converted to and from a Haskell value.
fromAttrToTyp :: String -> Attribute -> Maybe aSource
toAttrFrTyp :: String -> a -> Maybe AttributeSource
Parsing and printing helper functions
choice :: XmlContent a => (a -> b) -> ([Content] -> (Maybe b, [Content])) -> [Content] -> (Maybe b, [Content])Source
definite :: ([Content] -> (Maybe a, [Content])) -> String -> String -> [Content] -> (a, [Content])Source
The List1 type represents lists with at least one element. It is required for DTD content models that use + as a modifier.
NonEmpty [a] |
Eq a => Eq (List1 a) | |
Show a => Show (List1 a) | |
XmlContent a => XmlContent (List1 a) |
data ANYContent Source
A type corresponding to XML's ANY contentspec data ANYContent = forall a . XmlContent a => ANYContent a
defaultToAttr :: (String -> a -> Maybe Attribute) -> String -> Defaultable a -> Maybe AttributeSource
data Defaultable a Source
If an attribute is defaultable, then it either takes the default value (which is omitted from the output), or a non-default value (which obviously must be printed).
Default a | |
NonDefault a |
Eq a => Eq (Defaultable a) | |
Show a => Show (Defaultable a) |