xml-types-0.3.6: Basic types for representing XML

Copyright | 2010-2011 John Millikin
License | MIT
Maintainer | jmillikin@gmail.com
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Data.XML.Types

Contents

- Types
  - Document prologue
  - Document body
  - Doctypes
  - Incremental processing
- Combinators
  - Filters
  - Element traversal
  - Node traversal
  - Attributes

Description

Basic types for representing XML.

The idea is to have a full set of appropriate types, which various XML libraries can share. Instead of having equivalent-but-incompatible types for every binding, parser, or client, they all share the same types can can thus interoperate easily.

This library contains complete types for most parts of an XML document, including the prologue, node tree, and doctype. Some basic combinators are included for common tasks, including traversing the node tree and filtering children.

Synopsis

- data Document = Document {
  - documentPrologue :: Prologue
  - documentRoot :: Element
  - documentEpilogue :: [Miscellaneous]
  }
- data Prologue = Prologue {
  - prologueBefore :: [Miscellaneous]
  - prologueDoctype :: Maybe Doctype
  - prologueAfter :: [Miscellaneous]
  }
- data Instruction = Instruction {
  - instructionTarget :: Text
  - instructionData :: Text
  }
- data Miscellaneous
  - = MiscInstruction Instruction
  - | MiscComment Text
- data Node
  - = NodeElement Element
  - | NodeInstruction Instruction
  - | NodeContent Content
  - | NodeComment Text
- data Element = Element {
  - elementName :: Name
  - elementAttributes :: [(Name, [Content])]
  - elementNodes :: [Node]
  }
- data Content
  - = ContentText Text
  - | ContentEntity Text
- data Name = Name {
  - nameLocalName :: Text
  - nameNamespace :: Maybe Text
  - namePrefix :: Maybe Text
  }
- data Doctype = Doctype {
  - doctypeName :: Text
  - doctypeID :: Maybe ExternalID
  }
- data ExternalID
  - = SystemID Text
  - | PublicID Text Text
- data Event
  - = EventBeginDocument
  - | EventEndDocument
  - | EventBeginDoctype Text (Maybe ExternalID)
  - | EventEndDoctype
  - | EventInstruction Instruction
  - | EventBeginElement Name [(Name, [Content])]
  - | EventEndElement Name
  - | EventContent Content
  - | EventComment Text
  - | EventCDATA Text
- isElement :: Node -> [Element]
- isInstruction :: Node -> [Instruction]
- isContent :: Node -> [Content]
- isComment :: Node -> [Text]
- isNamed :: Name -> Element -> [Element]
- elementChildren :: Element -> [Element]
- elementContent :: Element -> [Content]
- elementText :: Element -> [Text]
- nodeChildren :: Node -> [Node]
- nodeContent :: Node -> [Content]
- nodeText :: Node -> [Text]
- hasAttribute :: Name -> Element -> [Element]
- hasAttributeText :: Name -> (Text -> Bool) -> Element -> [Element]
- attributeContent :: Name -> Element -> Maybe [Content]
- attributeText :: Name -> Element -> Maybe Text

# Types

## Document prologue

data Document

Constructors

Document |
Fields documentPrologue :: Prologue documentRoot :: Element documentEpilogue :: [Miscellaneous]

Instances

Eq Document |
Data Document |
Ord Document |
Show Document |
Generic Document |
NFData Document |
type Rep Document |

data Prologue

Constructors

Prologue |
Fields prologueBefore :: [Miscellaneous] prologueDoctype :: Maybe Doctype prologueAfter :: [Miscellaneous]

Instances

Eq Prologue |
Data Prologue |
Ord Prologue |
Show Prologue |
Generic Prologue |
NFData Prologue |
type Rep Prologue |

data Instruction

Constructors

Instruction |
Fields instructionTarget :: Text instructionData :: Text

Instances

Eq Instruction |
Data Instruction |
Ord Instruction |
Show Instruction |
Generic Instruction |
NFData Instruction |
type Rep Instruction |

data Miscellaneous

Constructors

MiscInstruction Instruction |
MiscComment Text |

Instances

Eq Miscellaneous |
Data Miscellaneous |
Ord Miscellaneous |
Show Miscellaneous |
Generic Miscellaneous |
NFData Miscellaneous |
type Rep Miscellaneous |

## Document body

data Node

Constructors

NodeElement Element |
NodeInstruction Instruction |
NodeContent Content |
NodeComment Text |

Instances

Eq Node |
Data Node |
Ord Node |
Show Node |
Generic Node |
NFData Node |
type Rep Node |

data Element

Constructors

Element |
Fields elementName :: Name elementAttributes :: [(Name, [Content])] elementNodes :: [Node]

Instances

Eq Element |
Data Element |
Ord Element |
Show Element |
Generic Element |
NFData Element |
type Rep Element |

data Content

Constructors

ContentText Text |
ContentEntity Text | For pass-through parsing

Instances

Eq Content |
Data Content |
Ord Content |
Show Content |
Generic Content |
NFData Content |
type Rep Content |

data Name

A fully qualified name.

Prefixes are not semantically important; they are included only to simplify pass-through parsing. When comparing names with `Eq` or `Ord` methods, prefixes are ignored.

The `IsString` instance supports Clark notation; see http://www.jclark.com/xml/xmlns.htm and http://infohost.nmt.edu/tcc/help/pubs/pylxml/etree-QName.html. Use the `OverloadedStrings` language extension for very simple `Name` construction:

    myname :: Name
    myname = "{http://example.com/ns/my-namespace}my-name"

Constructors

Name |
Fields nameLocalName :: Text nameNamespace :: Maybe Text namePrefix :: Maybe Text

Instances

Eq Name |
Data Name |
Ord Name |
Show Name |
IsString Name |
Generic Name |
NFData Name |
type Rep Name |

## Doctypes

data Doctype

Note: due to the incredible complexity of DTDs, this type only supports external subsets. I've tried adding internal subset types, but they quickly gain more code than the rest of this module put together.

It is possible that some future version of this library might support internal subsets, but I am no longer actively working on adding them.

Constructors

Doctype |
Fields doctypeName :: Text doctypeID :: Maybe ExternalID

Instances

Eq Doctype |
Data Doctype |
Ord Doctype |
Show Doctype |
Generic Doctype |
NFData Doctype |
type Rep Doctype |

data ExternalID

Constructors

SystemID Text |
PublicID Text Text |

Instances

Eq ExternalID |
Data ExternalID |
Ord ExternalID |
Show ExternalID |
Generic ExternalID |
NFData ExternalID |
type Rep ExternalID |

## Incremental processing

data Event

Some XML processing tools are incremental, and work in terms of events rather than node trees. The `Event` type allows a document to be fully specified as a sequence of events.

Event-based XML libraries include:

- http://hackage.haskell.org/package/xml-enumerator
- http://hackage.haskell.org/package/libxml-enumerator
- http://hackage.haskell.org/package/expat-enumerator

Constructors

EventBeginDocument |
EventEndDocument |
EventBeginDoctype Text (Maybe ExternalID) |
EventEndDoctype |
EventInstruction Instruction |
EventBeginElement Name [(Name, [Content])] |
EventEndElement Name |
EventContent Content |
EventComment Text |
EventCDATA Text |

Instances

Eq Event |
Data Event |
Ord Event |
Show Event |
Generic Event |
NFData Event |
type Rep Event |

# Combinators

## Filters

isElement :: Node -> [Element]

isInstruction :: Node -> [Instruction]

isContent :: Node -> [Content]

isComment :: Node -> [Text]

isNamed :: Name -> Element -> [Element]

## Element traversal

elementChildren :: Element -> [Element]

elementContent :: Element -> [Content]

elementText :: Element -> [Text]

## Node traversal

nodeChildren :: Node -> [Node]

nodeContent :: Node -> [Content]

nodeText :: Node -> [Text]

## Attributes

hasAttribute :: Name -> Element -> [Element]

hasAttributeText :: Name -> (Text -> Bool) -> Element -> [Element]

attributeContent :: Name -> Element -> Maybe [Content]

attributeText :: Name -> Element -> Maybe Text