Copyright | 2010-2011 John Millikin |
---|---|
License | MIT |
Maintainer | jmillikin@gmail.com |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell98 |
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.
- data Document = Document {}
- data Prologue = Prologue {}
- data Instruction = Instruction {}
- data Miscellaneous
- data Node
- data Element = Element {
- elementName :: Name
- elementAttributes :: [(Name, [Content])]
- elementNodes :: [Node]
- data Content
- data Name = Name {}
- data Doctype = Doctype {}
- data ExternalID
- data Event
- 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 Instruction Source
data Miscellaneous Source
Document body
Element | |
|
ContentText Text | |
ContentEntity Text | For pass-through parsing |
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"
Name | |
|
Doctypes
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.
data ExternalID Source
Incremental processing
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:
Combinators
Filters
isInstruction :: Node -> [Instruction] Source
Element traversal
elementChildren :: Element -> [Element] Source
elementContent :: Element -> [Content] Source
elementText :: Element -> [Text] Source
Node traversal
nodeChildren :: Node -> [Node] Source
nodeContent :: Node -> [Content] Source
Attributes
hasAttribute :: Name -> Element -> [Element] Source