HaXml-1.25.4: Utilities for manipulating XML documents

Safe Haskell | Safe
Language | Haskell98

Text.XML.HaXml.XmlContent.Parser

Contents

- Re-export the relevant set of generic XML document type definitions
- The enabling classes, that define parsing/unparsing between Haskell
  - Auxiliaries for writing parsers in the XmlContent class
  - Auxiliaries for generating in the XmlContent class
  - Auxiliaries for the attribute-related classes
- Explicit representation of Haskell datatype information
- Types useful for some content models

Description

The class `XmlContent` is a kind of replacement for Read and Show: it provides conversions between a generic XML tree representation and your own more specialised typeful Haskell data trees.

If you are starting with a set of Haskell datatypes, use DrIFT to derive instances of this class for you: http://repetae.net/john/computer/haskell/DrIFT If you are starting with an XML DTD, use HaXml's tool DtdToHaskell to generate both the Haskell types and the corresponding instances.

This unified class interface replaces two previous (somewhat similar) classes: Haskell2Xml and Xml2Haskell. There was no real reason to have separate classes depending on how you originally defined your datatypes. However, some instances for basic types like lists will depend on which direction you are using. See Text.XML.HaXml.XmlContent and Text.XML.HaXml.XmlContent.Haskell.

Synopsis

- data Document i = Document Prolog (SymTab EntityDef) (Element i) [Misc]
- data Element i = Elem QName [Attribute] [Content i]
- data ElemTag = ElemTag QName [Attribute]
- data Content i
  - = CElem (Element i) i
  - | CString Bool CharData i
  - | CRef Reference i
  - | CMisc Misc i
- type Attribute = (QName, AttValue)
- data AttValue = AttValue [Either String Reference]
- data Prolog = Prolog (Maybe XMLDecl) [Misc] (Maybe DocTypeDecl) [Misc]
- data Reference
  - = RefEntity EntityRef
  - | RefChar CharRef
- class HTypeable a => XmlContent a where
- class XmlAttributes a where
- class XmlAttrType a where
- module Text.ParserCombinators.Poly
- type XMLParser a = Parser (Content Posn) a
- content :: String -> XMLParser (Content Posn)
- posnElement :: [String] -> XMLParser (Posn, Element Posn)
- element :: [String] -> XMLParser (Element Posn)
- interior :: Element Posn -> XMLParser a -> XMLParser a
- inElement :: String -> XMLParser a -> XMLParser a
- text :: XMLParser String
- attributes :: XmlAttributes a => Element Posn -> XMLParser a
- posnElementWith :: (String -> String -> Bool) -> [String] -> XMLParser (Posn, Element Posn)
- elementWith :: (String -> String -> Bool) -> [String] -> XMLParser (Element Posn)
- inElementWith :: (String -> String -> Bool) -> String -> XMLParser a -> XMLParser a
- choice :: XmlContent a => (a -> b) -> XMLParser b -> XMLParser b
- definite :: XmlContent a => XMLParser a -> String -> String -> XMLParser a
- mkElem :: XmlContent a => a -> [Content ()] -> Content ()
- mkElemC :: String -> [Content ()] -> Content ()
- mkAttr :: String -> String -> Attribute
- toText :: String -> [Content ()]
- toCData :: String -> [Content ()]
- 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
- attval :: Read a => Element i -> a
- catMaybes :: [Maybe a] -> [a]
- module Text.XML.HaXml.TypeMapping
- data List1 a = NonEmpty [a]
- data ANYContent
  - = (XmlContent a, Show a) => ANYContent a
  - | UnConverted [Content Posn]

# Re-export the relevant set of generic XML document type definitions

data Document i #

The symbol table stored in a document holds all its general entity reference definitions.

Constructors

Document Prolog (SymTab EntityDef) (Element i) [Misc] |

Instances

Functor Document # |
Methods fmap :: (a -> b) -> Document a -> Document b # (<$) :: a -> Document b -> Document a #
Eq (Document i) # |
Methods (==) :: Document i -> Document i -> Bool # (/=) :: Document i -> Document i -> Bool #
Show i => Show (Document i) # |
Methods showsPrec :: Int -> Document i -> ShowS # show :: Document i -> String # showList :: [Document i] -> ShowS #

data Element i #

Constructors

Elem QName [Attribute] [Content i] |

Instances

Functor Element # |
Methods fmap :: (a -> b) -> Element a -> Element b # (<$) :: a -> Element b -> Element a #
Eq (Element i) # |
Methods (==) :: Element i -> Element i -> Bool # (/=) :: Element i -> Element i -> Bool #
Show i => Show (Element i) # |
Methods showsPrec :: Int -> Element i -> ShowS # show :: Element i -> String # showList :: [Element i] -> ShowS #
Verbatim (Element i) # |
Methods verbatim :: Element i -> String #

data ElemTag #

Constructors

ElemTag QName [Attribute] |

Instances

Eq ElemTag # |
Methods (==) :: ElemTag -> ElemTag -> Bool # (/=) :: ElemTag -> ElemTag -> Bool #

data Content i #

Constructors

CElem (Element i) i |
CString Bool CharData i | bool is whether whitespace is significant
CRef Reference i |
CMisc Misc i |

Instances

Functor Content # |
Methods fmap :: (a -> b) -> Content a -> Content b # (<$) :: a -> Content b -> Content a #
Eq (Content i) # |
Methods (==) :: Content i -> Content i -> Bool # (/=) :: Content i -> Content i -> Bool #
Show i => Show (Content i) # |
Methods showsPrec :: Int -> Content i -> ShowS # show :: Content i -> String # showList :: [Content i] -> ShowS #
Verbatim (Content i) # |
Methods verbatim :: Content i -> String #

type Attribute = (QName, AttValue) #

data AttValue #

Constructors

AttValue [Either String Reference] |

Instances

Eq AttValue # |
Methods (==) :: AttValue -> AttValue -> Bool # (/=) :: AttValue -> AttValue -> Bool #
Show AttValue # |
Methods showsPrec :: Int -> AttValue -> ShowS # show :: AttValue -> String # showList :: [AttValue] -> ShowS #
Verbatim AttValue # |
Methods verbatim :: AttValue -> String #

data Prolog #

Constructors

Prolog (Maybe XMLDecl) [Misc] (Maybe DocTypeDecl) [Misc] |

Instances

Eq Prolog # |
Methods (==) :: Prolog -> Prolog -> Bool # (/=) :: Prolog -> Prolog -> Bool #
Show Prolog # |
Methods showsPrec :: Int -> Prolog -> ShowS # show :: Prolog -> String # showList :: [Prolog] -> ShowS #

data Reference #

Constructors

RefEntity EntityRef |
RefChar CharRef |

Instances

Eq Reference # |
Methods (==) :: Reference -> Reference -> Bool # (/=) :: Reference -> Reference -> Bool #
Show Reference # |
Methods showsPrec :: Int -> Reference -> ShowS # show :: Reference -> String # showList :: [Reference] -> ShowS #
Verbatim Reference # |
Methods verbatim :: Reference -> String #

# The enabling classes, that define parsing/unparsing between Haskell

class HTypeable a => XmlContent a where #

The `XmlContent` class promises that an XML Content element can be converted to and from a Haskell value.

Minimal complete definition

parseContents, toContents

Methods

parseContents :: XMLParser a #

Convert from XML to Haskell

toContents :: a -> [Content ()] #

Convert from Haskell to XML

xToChar :: a -> Char #

Dummy functions (for most types): used only in the Char instance for coercing lists of Char into String.

xFromChar :: Char -> a #

Instances

XmlContent ANYContent # |
Methods parseContents :: XMLParser ANYContent # toContents :: ANYContent -> [Content ()] # xToChar :: ANYContent -> Char # xFromChar :: Char -> ANYContent #
XmlContent a => XmlContent (List1 a) # |
Methods parseContents :: XMLParser (List1 a) # toContents :: List1 a -> [Content ()] # xToChar :: List1 a -> Char # xFromChar :: Char -> List1 a #
XmlContent a => XmlContent (OneOf1 a) # |
Methods parseContents :: XMLParser (OneOf1 a) # toContents :: OneOf1 a -> [Content ()] # xToChar :: OneOf1 a -> Char # xFromChar :: Char -> OneOf1 a #
(XmlContent a, XmlContent b) => XmlContent (a, b) # |
Methods parseContents :: XMLParser (a, b) # toContents :: (a, b) -> [Content ()] # xToChar :: (a, b) -> Char # xFromChar :: Char -> (a, b) #
(XmlContent a, XmlContent b) => XmlContent (OneOf2 a b) # |
Methods parseContents :: XMLParser (OneOf2 a b) # toContents :: OneOf2 a b -> [Content ()] # xToChar :: OneOf2 a b -> Char # xFromChar :: Char -> OneOf2 a b #
(XmlContent a, XmlContent b, XmlContent c) => XmlContent (a, b, c) # |
Methods parseContents :: XMLParser (a, b, c) # toContents :: (a, b, c) -> [Content ()] # xToChar :: (a, b, c) -> Char # xFromChar :: Char -> (a, b, c) #
(XmlContent a, XmlContent b, XmlContent c) => XmlContent (OneOf3 a b c) # |
Methods parseContents :: XMLParser (OneOf3 a b c) # toContents :: OneOf3 a b c -> [Content ()] # xToChar :: OneOf3 a b c -> Char # xFromChar :: Char -> OneOf3 a b c #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d) => XmlContent (a, b, c, d) # |
Methods parseContents :: XMLParser (a, b, c, d) # toContents :: (a, b, c, d) -> [Content ()] # xToChar :: (a, b, c, d) -> Char # xFromChar :: Char -> (a, b, c, d) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d) => XmlContent (OneOf4 a b c d) # |
Methods parseContents :: XMLParser (OneOf4 a b c d) # toContents :: OneOf4 a b c d -> [Content ()] # xToChar :: OneOf4 a b c d -> Char # xFromChar :: Char -> OneOf4 a b c d #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e) => XmlContent (a, b, c, d, e) # |
Methods parseContents :: XMLParser (a, b, c, d, e) # toContents :: (a, b, c, d, e) -> [Content ()] # xToChar :: (a, b, c, d, e) -> Char # xFromChar :: Char -> (a, b, c, d, e) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e) => XmlContent (OneOf5 a b c d e) # |
Methods parseContents :: XMLParser (OneOf5 a b c d e) # toContents :: OneOf5 a b c d e -> [Content ()] # xToChar :: OneOf5 a b c d e -> Char # xFromChar :: Char -> OneOf5 a b c d e #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f) => XmlContent (a, b, c, d, e, f) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f) # toContents :: (a, b, c, d, e, f) -> [Content ()] # xToChar :: (a, b, c, d, e, f) -> Char # xFromChar :: Char -> (a, b, c, d, e, f) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f) => XmlContent (OneOf6 a b c d e f) # |
Methods parseContents :: XMLParser (OneOf6 a b c d e f) # toContents :: OneOf6 a b c d e f -> [Content ()] # xToChar :: OneOf6 a b c d e f -> Char # xFromChar :: Char -> OneOf6 a b c d e f #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g) => XmlContent (a, b, c, d, e, f, g) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f, g) # toContents :: (a, b, c, d, e, f, g) -> [Content ()] # xToChar :: (a, b, c, d, e, f, g) -> Char # xFromChar :: Char -> (a, b, c, d, e, f, g) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g) => XmlContent (OneOf7 a b c d e f g) # |
Methods parseContents :: XMLParser (OneOf7 a b c d e f g) # toContents :: OneOf7 a b c d e f g -> [Content ()] # xToChar :: OneOf7 a b c d e f g -> Char # xFromChar :: Char -> OneOf7 a b c d e f g #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h) => XmlContent (a, b, c, d, e, f, g, h) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f, g, h) # toContents :: (a, b, c, d, e, f, g, h) -> [Content ()] # xToChar :: (a, b, c, d, e, f, g, h) -> Char # xFromChar :: Char -> (a, b, c, d, e, f, g, h) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h) => XmlContent (OneOf8 a b c d e f g h) # |
Methods parseContents :: XMLParser (OneOf8 a b c d e f g h) # toContents :: OneOf8 a b c d e f g h -> [Content ()] # xToChar :: OneOf8 a b c d e f g h -> Char # xFromChar :: Char -> OneOf8 a b c d e f g h #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i) => XmlContent (a, b, c, d, e, f, g, h, i) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f, g, h, i) # toContents :: (a, b, c, d, e, f, g, h, i) -> [Content ()] # xToChar :: (a, b, c, d, e, f, g, h, i) -> Char # xFromChar :: Char -> (a, b, c, d, e, f, g, h, i) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i) => XmlContent (OneOf9 a b c d e f g h i) # |
Methods parseContents :: XMLParser (OneOf9 a b c d e f g h i) # toContents :: OneOf9 a b c d e f g h i -> [Content ()] # xToChar :: OneOf9 a b c d e f g h i -> Char # xFromChar :: Char -> OneOf9 a b c d e f g h i #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j) => XmlContent (a, b, c, d, e, f, g, h, i, j) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j) # toContents :: (a, b, c, d, e, f, g, h, i, j) -> [Content ()] # xToChar :: (a, b, c, d, e, f, g, h, i, j) -> Char # xFromChar :: Char -> (a, b, c, d, e, f, g, h, i, j) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j) => XmlContent (OneOf10 a b c d e f g h i j) # |
Methods parseContents :: XMLParser (OneOf10 a b c d e f g h i j) # toContents :: OneOf10 a b c d e f g h i j -> [Content ()] # xToChar :: OneOf10 a b c d e f g h i j -> Char # xFromChar :: Char -> OneOf10 a b c d e f g h i j #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k) => XmlContent (a, b, c, d, e, f, g, h, i, j, k) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k) # toContents :: (a, b, c, d, e, f, g, h, i, j, k) -> [Content ()] # xToChar :: (a, b, c, d, e, f, g, h, i, j, k) -> Char # xFromChar :: Char -> (a, b, c, d, e, f, g, h, i, j, k) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k) => XmlContent (OneOf11 a b c d e f g h i j k) # |
Methods parseContents :: XMLParser (OneOf11 a b c d e f g h i j k) # toContents :: OneOf11 a b c d e f g h i j k -> [Content ()] # xToChar :: OneOf11 a b c d e f g h i j k -> Char # xFromChar :: Char -> OneOf11 a b c d e f g h i j k #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l) => XmlContent (a, b, c, d, e, f, g, h, i, j, k, l) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k, l) # toContents :: (a, b, c, d, e, f, g, h, i, j, k, l) -> [Content ()] # xToChar :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Char # xFromChar :: Char -> (a, b, c, d, e, f, g, h, i, j, k, l) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l) => XmlContent (OneOf12 a b c d e f g h i j k l) # |
Methods parseContents :: XMLParser (OneOf12 a b c d e f g h i j k l) # toContents :: OneOf12 a b c d e f g h i j k l -> [Content ()] # xToChar :: OneOf12 a b c d e f g h i j k l -> Char # xFromChar :: Char -> OneOf12 a b c d e f g h i j k l #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m) => XmlContent (a, b, c, d, e, f, g, h, i, j, k, l, m) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k, l, m) # toContents :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> [Content ()] # xToChar :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Char # xFromChar :: Char -> (a, b, c, d, e, f, g, h, i, j, k, l, m) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m) => XmlContent (OneOf13 a b c d e f g h i j k l m) # |
Methods parseContents :: XMLParser (OneOf13 a b c d e f g h i j k l m) # toContents :: OneOf13 a b c d e f g h i j k l m -> [Content ()] # xToChar :: OneOf13 a b c d e f g h i j k l m -> Char # xFromChar :: Char -> OneOf13 a b c d e f g h i j k l m #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m, XmlContent n) => XmlContent (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k, l, m, n) # toContents :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> [Content ()] # xToChar :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Char # xFromChar :: Char -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m, XmlContent n) => XmlContent (OneOf14 a b c d e f g h i j k l m n) # |
Methods parseContents :: XMLParser (OneOf14 a b c d e f g h i j k l m n) # toContents :: OneOf14 a b c d e f g h i j k l m n -> [Content ()] # xToChar :: OneOf14 a b c d e f g h i j k l m n -> Char # xFromChar :: Char -> OneOf14 a b c d e f g h i j k l m n #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m, XmlContent n, XmlContent o) => XmlContent (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # |
Methods parseContents :: XMLParser (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) # toContents :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> [Content ()] # xToChar :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Char # xFromChar :: Char -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m, XmlContent n, XmlContent o) => XmlContent (OneOf15 a b c d e f g h i j k l m n o) # |
Methods parseContents :: XMLParser (OneOf15 a b c d e f g h i j k l m n o) # toContents :: OneOf15 a b c d e f g h i j k l m n o -> [Content ()] # xToChar :: OneOf15 a b c d e f g h i j k l m n o -> Char # xFromChar :: Char -> OneOf15 a b c d e f g h i j k l m n o #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m, XmlContent n, XmlContent o, XmlContent p) => XmlContent (OneOf16 a b c d e f g h i j k l m n o p) # |
Methods parseContents :: XMLParser (OneOf16 a b c d e f g h i j k l m n o p) # toContents :: OneOf16 a b c d e f g h i j k l m n o p -> [Content ()] # xToChar :: OneOf16 a b c d e f g h i j k l m n o p -> Char # xFromChar :: Char -> OneOf16 a b c d e f g h i j k l m n o p #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m, XmlContent n, XmlContent o, XmlContent p, XmlContent q) => XmlContent (OneOf17 a b c d e f g h i j k l m n o p q) # |
Methods parseContents :: XMLParser (OneOf17 a b c d e f g h i j k l m n o p q) # toContents :: OneOf17 a b c d e f g h i j k l m n o p q -> [Content ()] # xToChar :: OneOf17 a b c d e f g h i j k l m n o p q -> Char # xFromChar :: Char -> OneOf17 a b c d e f g h i j k l m n o p q #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m, XmlContent n, XmlContent o, XmlContent p, XmlContent q, XmlContent r) => XmlContent (OneOf18 a b c d e f g h i j k l m n o p q r) # |
Methods parseContents :: XMLParser (OneOf18 a b c d e f g h i j k l m n o p q r) # toContents :: OneOf18 a b c d e f g h i j k l m n o p q r -> [Content ()] # xToChar :: OneOf18 a b c d e f g h i j k l m n o p q r -> Char # xFromChar :: Char -> OneOf18 a b c d e f g h i j k l m n o p q r #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m, XmlContent n, XmlContent o, XmlContent p, XmlContent q, XmlContent r, XmlContent s) => XmlContent (OneOf19 a b c d e f g h i j k l m n o p q r s) # |
Methods parseContents :: XMLParser (OneOf19 a b c d e f g h i j k l m n o p q r s) # toContents :: OneOf19 a b c d e f g h i j k l m n o p q r s -> [Content ()] # xToChar :: OneOf19 a b c d e f g h i j k l m n o p q r s -> Char # xFromChar :: Char -> OneOf19 a b c d e f g h i j k l m n o p q r s #
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g, XmlContent h, XmlContent i, XmlContent j, XmlContent k, XmlContent l, XmlContent m, XmlContent n, XmlContent o, XmlContent p, XmlContent q, XmlContent r, XmlContent s, XmlContent t) => XmlContent (OneOf20 a b c d e f g h i j k l m n o p q r s t) # |
Methods parseContents :: XMLParser (OneOf20 a b c d e f g h i j k l m n o p q r s t) # toContents :: OneOf20 a b c d e f g h i j k l m n o p q r s t -> [Content ()] # xToChar :: OneOf20 a b c d e f g h i j k l m n o p q r s t -> Char # xFromChar :: Char -> OneOf20 a b c d e f g h i j k l m n o p q r s t #

class XmlAttributes a where #

The `XmlAttributes` class promises that a list of XML tag attributes can be converted to and from a Haskell value.

Minimal complete definition

fromAttrs, toAttrs

Methods

fromAttrs :: [Attribute] -> a #

toAttrs :: a -> [Attribute] #

class XmlAttrType a where #

The `XmlAttrType` class promises that an attribute taking an XML enumerated type can be converted to and from a Haskell value.

Minimal complete definition

fromAttrToTyp, toAttrFrTyp

Methods

fromAttrToTyp :: String -> Attribute -> Maybe a #

toAttrFrTyp :: String -> a -> Maybe Attribute #

## Auxiliaries for writing parsers in the XmlContent class

module Text.ParserCombinators.Poly

type XMLParser a = Parser (Content Posn) a #

We need a parsing monad for reading generic XML Content into specific datatypes. This is a specialisation of the Text.ParserCombinators.Poly ones, where the input token type is fixed as XML Content.

content :: String -> XMLParser (Content Posn) #

The most primitive combinator for XMLParser - get one content item.

posnElement :: [String] -> XMLParser (Posn, Element Posn) #

A specialisation of `posnElementWith (==)`.

element :: [String] -> XMLParser (Element Posn) #

Get the next content element, checking that it has one of the required tags. (Skips over comments and whitespace, rejects text and refs.)

interior :: Element Posn -> XMLParser a -> XMLParser a #

Run an XMLParser on the contents of the given element (i.e. not on the current monadic content sequence), checking that the contents are exhausted, before returning the calculated value within the current parser context.

inElement :: String -> XMLParser a -> XMLParser a #

A combination of element + interior.

text :: XMLParser String #

`text` is a counterpart to `element`, parsing text content if it exists. Adjacent text and references are coalesced.

attributes :: XmlAttributes a => Element Posn -> XMLParser a #

Do some parsing of the attributes of the given element

posnElementWith :: (String -> String -> Bool) -> [String] -> XMLParser (Posn, Element Posn) #

Get the next content element, checking that it has one of the required tags, using the given matching function. (Skips over comments and whitespace, rejects text and refs. Also returns position of element.)

elementWith :: (String -> String -> Bool) -> [String] -> XMLParser (Element Posn) #

Like element, only permits a more flexible match against the tagname.

inElementWith :: (String -> String -> Bool) -> String -> XMLParser a -> XMLParser a #

A combination of elementWith + interior.

choice :: XmlContent a => (a -> b) -> XMLParser b -> XMLParser b #

'choice f p' means if parseContents succeeds, apply f to the result, otherwise use the continuation parser.

definite :: XmlContent a => XMLParser a -> String -> String -> XMLParser a #

not sure this is needed now. 'definite p' previously ensured that an element was definitely present. Now I think the monad might take care of that for us.

## Auxiliaries for generating in the XmlContent class

mkElem :: XmlContent a => a -> [Content ()] -> Content () #

Generate an element with no attributes, named for its HType.

mkElemC :: String -> [Content ()] -> Content () #

Generate an element with no attributes, named directly.

mkAttr :: String -> String -> Attribute #

Generate a single attribute.

toText :: String -> [Content ()] #

Turn a simple string into XML text.

toCData :: String -> [Content ()] #

Turn a string into an XML CDATA section. (i.e. special characters like `&` are preserved without interpretation.)

## Auxiliaries for the attribute-related classes

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 #

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).

Constructors

Default a |
NonDefault a |

Instances

Eq a => Eq (Defaultable a) # |
Methods (==) :: Defaultable a -> Defaultable a -> Bool # (/=) :: Defaultable a -> Defaultable a -> Bool #
Show a => Show (Defaultable a) # |
Methods showsPrec :: Int -> Defaultable a -> ShowS # show :: Defaultable a -> String # showList :: [Defaultable a] -> ShowS #

str2attr :: String -> AttValue #

attr2str :: AttValue -> String #

attval :: Read a => Element i -> a #

Read a single attribute called "value".

catMaybes :: [Maybe a] -> [a] #

The `catMaybes` function takes a list of `Maybe`s and returns a list of all the `Just` values.

#### Examples

Basic usage:

    >>> catMaybes [Just 1, Nothing, Just 3]
    [1,3]

When constructing a list of `Maybe` values, `catMaybes` can be used to return all of the "success" results (if the list is the result of a `map`, then `mapMaybe` would be more appropriate):

    >>> import Text.Read ( readMaybe )
    >>> [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
    [Just 1,Nothing,Just 3]
    >>> catMaybes $ [readMaybe x :: Maybe Int | x <- ["1", "Foo", "3"] ]
    [1,3]

# Explicit representation of Haskell datatype information

module Text.XML.HaXml.TypeMapping

# Types useful for some content models

data List1 a #

The List1 type represents lists with at least one element. It is required for DTD content models that use + as a modifier.

Constructors

NonEmpty [a] |

Instances

Eq a => Eq (List1 a) # |
Methods (==) :: List1 a -> List1 a -> Bool # (/=) :: List1 a -> List1 a -> Bool #
Show a => Show (List1 a) # |
Methods showsPrec :: Int -> List1 a -> ShowS # show :: List1 a -> String # showList :: [List1 a] -> ShowS #
HTypeable a => HTypeable (List1 a) # |
Methods toHType :: List1 a -> HType #
XmlContent a => XmlContent (List1 a) # |
Methods parseContents :: XMLParser (List1 a) # toContents :: List1 a -> [Content ()] # xToChar :: List1 a -> Char # xFromChar :: Char -> List1 a #

data ANYContent #

A type corresponding to XML's ANY contentspec. It is either a list of unconverted xml `Content` or some `XmlContent`-able value.

Parsing functions (e.g. `parseContents`) will always produce `UnConverted`. Note: The Show instance for `UnConverted` uses `verbatim`.

Constructors

(XmlContent a, Show a) => ANYContent a |
UnConverted [Content Posn] |

Instances

Eq ANYContent # |
Methods (==) :: ANYContent -> ANYContent -> Bool # (/=) :: ANYContent -> ANYContent -> Bool #
Show ANYContent # |
Methods showsPrec :: Int -> ANYContent -> ShowS # show :: ANYContent -> String # showList :: [ANYContent] -> ShowS #
HTypeable ANYContent # |
Methods toHType :: ANYContent -> HType #
XmlContent ANYContent # |
Methods parseContents :: XMLParser ANYContent # toContents :: ANYContent -> [Content ()] # xToChar :: ANYContent -> Char # xFromChar :: Char -> ANYContent #