xml-tydom-core-0.1.0.0: Typed XML encoding (core library).

Copyright(c) Jonathan Merritt 2017
LicenseBSD3
Maintainerj.s.merritt@gmail.com
StabilityExperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

Text.XML.TyDom.Core.XMLInterface

Contents

Description

This module contains the underlying machinery for the generic implementations of the classes that read and write XML. Examples of this functionality include the ability to get or set names of elements, get or set attributes, get or set child elements, and so on. The Compose and Decompose data types abstract over any underlying XML DOM representation to provide the required functionality. Thus, provided Compose and Decompose can be written for a given XML DOM backend, that backend can be used with xml-tydom.

Importantly, the requirements of xml-tydom may differ from those of any given XML DOM backend. Because of this, Compose and Decompose both have the concepts of freeze and thaw, which convert types in an actual XML DOM backend to types that can be chosen to be well-suited to xml-tydom itself. These special element representations are referred to as compose-elements and decompose-elements.

Compose and Decompose are parameterised by a variety of type variables that describe the underlying API. We have attempted to name these in a uniform fashion:

  • e: type of an element
  • n: type of the name of an element
  • a: type of the name of an attribute
  • t: type of text content in the XML document
  • c: type of the temporary representation of a compose-element used by the Compose data type
  • d: type of the temporary representation of a decompose-element used by the Decompose data type

Synopsis

Summary

Types

data Compose e n a t c Source #

Composes an element.

Constructors

Compose 

Fields

  • cEmpty :: c

    Empty instance of a compose-element of type c.

  • cName :: n -> c -> c

    Sets the name of a compose-element.

  • cAttr :: a -> t -> c -> c

    Adds an attribute to a compose-element.

  • cChild :: e -> c -> c

    Adds a child element to a compose-element.

  • cContent :: t -> c -> c

    Adds a text content node to a compose-element.

  • cCData :: t -> c -> c

    Adds a CDATA node to a compose-element.

  • cFreeze :: c -> e

    Freezes a compose-element into an ordinary element.

  • cThaw :: e -> c

    Thaws an ordinary element into a compose-element.

  • cNull :: t -> Bool

    Checks if given text is an empty string.

data Decompose e n a t d Source #

Decomposes an element.

An important principle when decomposing an element is that when attributes or child nodes are returned, a new version of the element is also returned without those attributes or elements. This is important for the case where we want to check that an element has been read completely.

Constructors

Decompose 

Fields

  • dThaw :: e -> d

    Thaws an ordinary element into a decompose-element.

  • dFreeze :: d -> e

    Freezes a decompose-element into an ordinary element.

  • dEmpty :: d

    An empty decompose-element.

  • dNull :: d -> Bool

    Checks if a decompose-element is empty.

  • dName :: d -> n

    Returns the name of a decompose element.

  • dRename :: n -> d -> d

    Renames a decompose element element.

  • dAttr :: a -> d -> Result d t

    Extracts an attribute.

  • dNextSeqChild :: d -> Result d d

    Next child element, iff the next node is an element.

  • dNextSeqContent :: d -> Result d t

    Next text content, iff the next node is text.

  • dNextSeqCData :: d -> Result d t

    Next CDATA content, iff the next node is CDATA.

  • dNextChildNamed :: n -> d -> Result d d

    Next child element with the given name, even if it is not the next node.

  • dNextContent :: d -> Result d t

    Next text content, even if the next node is not text.

  • dNextCData :: d -> Result d t

    Next CDATA content, even if the next node is not CDATA.

  • dSuccessChild :: forall z. d -> (e -> Maybe z) -> Result d z

    First child node that succeeds with the supplied function.

  • dSuccessNextChildren :: forall z. d -> (e -> Maybe z) -> (d, [z])

    Consumes sequential children with the supplied function until the element is exhausted, or until one child fails. (Should never fail.)

  • dSuccessChildren :: forall z. d -> (e -> Maybe z) -> (d, [z])

    Consumes all children (even non-contiguous ones) that satisfy the supplied function. (Should never fail.)

  • dAllContent :: d -> Result d t

    All content from the element (even non-contiguous).

  • dAllNextCData :: d -> (d, [t])

    Consume all contiguous CData nodes. (Should never fail.)

  • dAllCData :: d -> (d, [t])

    Consume add CData (even non-contiguous). (Should never fail.)

  • dEmptyTxt :: t

    Empty text value.

data Result d z Source #

Result type for operations from Decompose.

Constructors

Success d z

Successful result. Contains both the result type (z) and a new version of the decompose-element d without the particular thing that was returned (ie. without that particular attribute or child node).

Failure

Failure case; no additional information is required.

Instances

(Show d, Show z) => Show (Result d z) Source # 

Methods

showsPrec :: Int -> Result d z -> ShowS #

show :: Result d z -> String #

showList :: [Result d z] -> ShowS #