HaXml-1.24: Utilities for manipulating XML documents

Safe Haskell | None

Text.XML.HaXml.Schema.Schema

Synopsis

- class SchemaType a where
  - parseSchemaType :: String -> XMLParser a
  - schemaTypeToXML :: String -> a -> [Content ()]
- class SimpleType a where
  - acceptingParser :: TextParser a
  - simpleTypeText :: a -> String
- class Extension t s where
  - supertype :: t -> s
- class Restricts t s | t -> s where
  - restricts :: t -> s
- class FwdDecl fd a | fd -> a
- getAttribute :: (SimpleType a, Show a) => String -> Element Posn -> Posn -> XMLParser a
- between :: PolyParse p => Occurs -> p a -> p [a]
- data Occurs = Occurs (Maybe Int) (Maybe Int)
- parseSimpleType :: SimpleType t => XMLParser t
- parseText :: XMLParser String
- data AnyElement
  - = forall a . (SchemaType a, Show a) => ANYSchemaType a
  - | UnconvertedANY (Content Posn)
- parseAnyElement :: XMLParser AnyElement
- data Content i
  - = CElem (Element i) i
  - | CString Bool CharData i
  - | CRef Reference i
  - | CMisc Misc i
- type XMLParser a = Parser (Content Posn) a
- posnElement :: [String] -> XMLParser (Posn, Element Posn)
- posnElementWith :: (String -> String -> Bool) -> [String] -> XMLParser (Posn, Element Posn)
- element :: [String] -> XMLParser (Element Posn)
- interior :: Element Posn -> XMLParser a -> XMLParser a
- text :: XMLParser String
- module Text.ParserCombinators.Poly
- module Text.Parse
- module Text.XML.HaXml.OneOfN
- toXMLElement :: String -> [[Attribute]] -> [[Content ()]] -> [Content ()]
- toXMLText :: String -> [Content ()]
- toXMLAnyElement :: AnyElement -> [Content ()]
- toXMLAttribute :: SimpleType a => String -> a -> [Attribute]
- addXMLAttributes :: [[Attribute]] -> [Content ()] -> [Content ()]

# Documentation

class SchemaType a where

A SchemaType promises to interconvert between a generic XML content tree and a Haskell value, according to the rules of XSD.

Methods

parseSchemaType :: String -> XMLParser a

schemaTypeToXML :: String -> a -> [Content ()]

Instances

SchemaType Double |
SchemaType Float |
SchemaType Int |
SchemaType Integer |
SchemaType PositiveInteger |
SchemaType UnsignedByte |
SchemaType UnsignedShort |
SchemaType UnsignedInt |
SchemaType UnsignedLong |
SchemaType NonNegativeInteger |
SchemaType Byte |
SchemaType Short |
SchemaType Long |
SchemaType NegativeInteger |
SchemaType NonPositiveInteger |
SchemaType NMTOKENS |
SchemaType NMTOKEN |
SchemaType ENTITIES |
SchemaType ENTITY |
SchemaType IDREFS |
SchemaType IDREF |
SchemaType ID |
SchemaType NCName |
SchemaType Name |
SchemaType Language |
SchemaType Token |
SchemaType NormalizedString |
SchemaType GMonth |
SchemaType GDay |
SchemaType GMonthDay |
SchemaType GYear |
SchemaType GYearMonth |
SchemaType Date |
SchemaType Time |
SchemaType DateTime |
SchemaType Duration |
SchemaType Decimal |
SchemaType NOTATION |
SchemaType AnyURI |
SchemaType HexBinary |
SchemaType Base64Binary |
SchemaType XsdString |
SchemaType Boolean |
SchemaType AnyElement |

class SimpleType a where

Ultimately, an XML parser will find some plain text as the content of a simpleType, which will need to be parsed. We use a TextParser, because values of simpleTypes can also be given elsewhere, e.g. as attribute values in an XSD definition, e.g. to restrict the permissible values of the simpleType. Such restrictions are therefore implemented as layered parsers.

Methods

acceptingParser :: TextParser a

simpleTypeText :: a -> String

Instances

SimpleType Bool |
SimpleType Double |
SimpleType Float |
SimpleType Int |
SimpleType Integer |
SimpleType PositiveInteger |
SimpleType UnsignedByte |
SimpleType UnsignedShort |
SimpleType UnsignedInt |
SimpleType UnsignedLong |
SimpleType NonNegativeInteger |
SimpleType Byte |
SimpleType Short |
SimpleType Long |
SimpleType NegativeInteger |
SimpleType NonPositiveInteger |
SimpleType NMTOKENS |
SimpleType NMTOKEN |
SimpleType ENTITIES |
SimpleType ENTITY |
SimpleType IDREFS |
SimpleType IDREF |
SimpleType ID |
SimpleType NCName |
SimpleType Name |
SimpleType Language |
SimpleType Token |
SimpleType NormalizedString |
SimpleType GMonth |
SimpleType GDay |
SimpleType GMonthDay |
SimpleType GYear |
SimpleType GYearMonth |
SimpleType Date |
SimpleType Time |
SimpleType DateTime |
SimpleType Duration |
SimpleType Decimal |
SimpleType NOTATION |
SimpleType AnyURI |
SimpleType HexBinary |
SimpleType Base64Binary |
SimpleType XsdString |

class Extension t s where

A type t can extend another type s by the addition of extra elements and/or attributes. s is therefore the supertype of t.

Methods

supertype :: t -> s

class Restricts t s | t -> s where

A type t can restrict another type s, that is, t admits fewer values than s, but all the values t does admit also belong to the type s.

Methods

restricts :: t -> s

class FwdDecl fd a | fd -> a

A trick to enable forward-declaration of a type that will be defined properly in another module, higher in the dependency graph. `fd` is a dummy type e.g. the empty `data FwdA`, where `a` is the proper `data A`, not yet available.

getAttribute :: (SimpleType a, Show a) => String -> Element Posn -> Posn -> XMLParser a

Generated parsers will use `getAttribute` as a convenient wrapper to lift a SchemaAttribute parser into an XMLParser.

between :: PolyParse p => Occurs -> p a -> p [a]

Between is a list parser that tries to ensure that any range specification (min and max elements) is obeyed when parsing.

data Occurs

Constructors

Occurs (Maybe Int) (Maybe Int) |

Instances

Eq Occurs |
Show Occurs |

parseSimpleType :: SimpleType t => XMLParser t

Given a TextParser for a SimpleType, make it into an XMLParser, i.e. consuming textual XML content as input rather than a String.

parseText :: XMLParser String

Parse the textual part of mixed content

data AnyElement

The xsd:any type. Parsing will always produce an UnconvertedANY.

Constructors

forall a . (SchemaType a, Show a) => ANYSchemaType a |
UnconvertedANY (Content Posn) |

Instances

Eq AnyElement |
Show AnyElement |
SchemaType AnyElement |

parseAnyElement :: XMLParser AnyElement

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 |
Eq (Content i) |
Show i => Show (Content i) |
Verbatim (Content i) |

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.

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

A specialisation of `posnElementWith (==)`.

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

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.

text :: XMLParser String

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

module Text.ParserCombinators.Poly

module Text.Parse

module Text.XML.HaXml.OneOfN

toXMLElement :: String -> [[Attribute]] -> [[Content ()]] -> [Content ()]

toXMLText :: String -> [Content ()]

toXMLAnyElement :: AnyElement -> [Content ()]

toXMLAttribute :: SimpleType a => String -> a -> [Attribute]

addXMLAttributes :: [[Attribute]] -> [Content ()] -> [Content ()]

For a ComplexType that is an extension of a SimpleType, it is necessary to convert the value to XML first, then add in the extra attributes that constitute the extension.