The class Haskell2Xml
is a replacement for Read and Show: it provides
textual conversions (to and from an XML representation) for your
Haskell data values. Use the tool
DrIFT to derive this class for your own datatypes, then
include this module where you want to use the facilities.
The methods toContents
and fromContents
convert a value to and from
a generic internal representation of an XML document without a DTD.
The functions toXml
and fromXml
convert a value to and from a generic
internal representation of an XML document including a DTD.
The functions readXml
and showXml
convert to and from Strings.
The functions fReadXml
and fWriteXml
do the conversion to and from
the given filenames.
The functions hGetXml
and hPutXml
do the conversion to and from
the given file handles.
(See the type signatures.)
- module Text.XML.HaXml.Types
- class Haskell2Xml a where
- toXml :: Haskell2Xml a => a -> Document
- toDTD :: HType -> DocTypeDecl
- fromXml :: Haskell2Xml a => Document -> a
- readXml :: Haskell2Xml a => String -> Maybe a
- showXml :: Haskell2Xml a => a -> String
- fReadXml :: Haskell2Xml a => FilePath -> IO a
- fWriteXml :: Haskell2Xml a => FilePath -> a -> IO ()
- hGetXml :: Haskell2Xml a => Handle -> IO a
- hPutXml :: Haskell2Xml a => Handle -> a -> IO ()
- data HType
- data Constr = Constr String [HType] [HType]
- mkElem :: Haskell2Xml a => a -> [Content] -> Content
- mkElemC :: Name -> [Content] -> Content
- showConstr :: Int -> HType -> String
- isPrefixOf :: Eq a => [a] -> [a] -> Bool
Re-export the entire set of XML type definitions
module Text.XML.HaXml.Types
The class Haskell2Xml
class Haskell2Xml a whereSource
A class to convert any Haskell value to and from an XML representation.
Determine the type of the Haskell value (to create a DTD).
toContents :: a -> [Content]Source
Convert the Haskell value to a generic XML value.
fromContents :: [Content] -> (a, [Content])Source
Parse a Haskell value from a generic XML representation, returning the value and the remainder of the XML.
This function is a dummy for most types: it is used only in the Char instance for coercing lists of Char into String.
This function is a dummy for most types: it is used only in the Char instance for coercing lists of Char into String.
Haskell2Xml Bool | |
Haskell2Xml Char | |
Haskell2Xml Double | |
Haskell2Xml Float | |
Haskell2Xml Int | |
Haskell2Xml Integer | |
Haskell2Xml () | |
Haskell2Xml a => Haskell2Xml [a] | |
Haskell2Xml a => Haskell2Xml (Maybe a) | |
(Haskell2Xml a, Haskell2Xml b) => Haskell2Xml (Either a b) | |
(Haskell2Xml a, Haskell2Xml b) => Haskell2Xml (a, b) |
Conversion functions
toXml :: Haskell2Xml a => a -> DocumentSource
Convert any Haskell value to an XML document, including both DTD and content.
toDTD :: HType -> DocTypeDeclSource
fromXml :: Haskell2Xml a => Document -> aSource
Read a Haskell value from an XML document, ignoring the DTD and using the Haskell result type to determine how to parse it.
readXml :: Haskell2Xml a => String -> Maybe aSource
Convert an XML document encoded as a String, into a Haskell value.
showXml :: Haskell2Xml a => a -> StringSource
Convert a Haskell value to an XML document, encoded as a String.
IO conversion functions
fReadXml :: Haskell2Xml a => FilePath -> IO aSource
Read a Haskell value from an XML document stored in a file.
fWriteXml :: Haskell2Xml a => FilePath -> a -> IO ()Source
Write a Haskell value to the given file as an XML document.
hGetXml :: Haskell2Xml a => Handle -> IO aSource
Read a Haskell value from an XML document transmitted through the
given Handle
.
hPutXml :: Haskell2Xml a => Handle -> a -> IO ()Source
Write a Haskell value to the given Handle
as an XML document.
Auxiliary types
A concrete representation of any Haskell type.
A concrete representation of any user-defined Haskell constructor. The constructor has a name, and a sequence of component types. The first sequence of types represents the minimum set of free type variables occurring in the (second) list of real component types.
mkElem :: Haskell2Xml a => a -> [Content] -> ContentSource
showConstr :: Int -> HType -> StringSource
isPrefixOf :: Eq a => [a] -> [a] -> Bool
The isPrefixOf
function takes two lists and returns True
iff the first list is a prefix of the second.