HaXml-1.19.7: Utilities for manipulating XML documents

Text.XML.HaXml.XmlContent.Parser

Contents

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

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

data Document i Source

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

Constructors

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

Instances

data Element i Source

Constructors

Elem Name [Attribute] [Content i] 

Instances

data ElemTag Source

Constructors

ElemTag Name [Attribute] 

Instances

data Content i Source

Constructors

CElem (Element i) i 
CString Bool CharData i

bool is whether whitespace is significant

CRef Reference i 
CMisc Misc i 

Instances

data Prolog Source

Constructors

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

Instances

The enabling classes, that define parsing/unparsing between Haskell

class HTypeable a => XmlContent a whereSource

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

Methods

parseContents :: XMLParser aSource

Convert from XML to Haskell

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

Convert from Haskell to XML

xToChar :: a -> CharSource

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

xFromChar :: Char -> aSource

Instances

XmlContent Bool 
XmlContent Char 
XmlContent Char 
XmlContent Double 
XmlContent Float 
XmlContent Int 
XmlContent Integer 
XmlContent () 
XmlContent ANYContent 
XmlContent a => XmlContent [a] 
XmlContent a => XmlContent [a] 
XmlContent a => XmlContent (Maybe a) 
XmlContent a => XmlContent (Maybe a) 
XmlContent a => XmlContent (List1 a) 
(XmlContent a, XmlContent b) => XmlContent (Either a b) 
(XmlContent a, XmlContent b) => XmlContent (a, b) 
(XmlContent a, XmlContent b) => XmlContent (OneOf2 a b) 
(XmlContent a, XmlContent b, XmlContent c) => XmlContent (a, b, c) 
(XmlContent a, XmlContent b, XmlContent c) => XmlContent (OneOf3 a b c) 
(XmlContent a, XmlContent b, XmlContent c, XmlContent d) => XmlContent (a, b, c, d) 
(XmlContent a, XmlContent b, XmlContent c, XmlContent d) => XmlContent (OneOf4 a b c d) 
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e) => XmlContent (a, b, c, d, e) 
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e) => XmlContent (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) 
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f) => XmlContent (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) 
(XmlContent a, XmlContent b, XmlContent c, XmlContent d, XmlContent e, XmlContent f, XmlContent g) => XmlContent (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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 
(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) 

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.

Auxiliaries for writing parsers in the XmlContent class

type XMLParser a = Parser (Content Posn) aSource

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

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

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

A specialisation of posnElementWith (==).

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

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 aSource

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 aSource

A combination of element + interior.

text :: XMLParser StringSource

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

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

Do some parsing of the attributes of the given element

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

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

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

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

A combination of elementWith + interior.

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

'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 aSource

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 ()Source

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

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

Generate an element with no attributes, named directly.

mkAttr :: String -> String -> AttributeSource

Generate a single attribute.

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

Turn a simple string into XML text.

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

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

Auxiliaries for the attribute-related classes

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

Constructors

Default a 
NonDefault a 

Instances

Eq a => Eq (Defaultable a) 
Show a => Show (Defaultable a) 

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

Read a single attribute called value.

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

The catMaybes function takes a list of Maybes and returns a list of all the Just values.

Explicit representation of Haskell datatype information

Types useful for some content models

data List1 a Source

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) 
Show a => Show (List1 a) 
HTypeable a => HTypeable (List1 a) 
XmlContent a => XmlContent (List1 a) 

data ANYContent Source

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

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