Copyright | 2010-2011 John Millikin |
---|---|
License | MIT |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Data.XML.Types
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 {}
- 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
Constructors
Document | |
Fields |
Instances
Eq Document # | |
Data Document # | |
Defined in Data.XML.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Document -> c Document # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Document # toConstr :: Document -> Constr # dataTypeOf :: Document -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Document) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Document) # gmapT :: (forall b. Data b => b -> b) -> Document -> Document # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Document -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Document -> r # gmapQ :: (forall d. Data d => d -> u) -> Document -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Document -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Document -> m Document # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Document -> m Document # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Document -> m Document # | |
Ord Document # | |
Defined in Data.XML.Types | |
Show Document # | |
Generic Document # | |
NFData Document # | |
Defined in Data.XML.Types | |
type Rep Document # | |
Defined in Data.XML.Types type Rep Document = D1 ('MetaData "Document" "Data.XML.Types" "xml-types-0.3.8" 'False) (C1 ('MetaCons "Document" 'PrefixI 'True) (S1 ('MetaSel ('Just "documentPrologue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Prologue) :*: (S1 ('MetaSel ('Just "documentRoot") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Element) :*: S1 ('MetaSel ('Just "documentEpilogue") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Miscellaneous])))) |
Constructors
Prologue | |
Fields |
Instances
Eq Prologue # | |
Data Prologue # | |
Defined in Data.XML.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Prologue -> c Prologue # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Prologue # toConstr :: Prologue -> Constr # dataTypeOf :: Prologue -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Prologue) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Prologue) # gmapT :: (forall b. Data b => b -> b) -> Prologue -> Prologue # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Prologue -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Prologue -> r # gmapQ :: (forall d. Data d => d -> u) -> Prologue -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Prologue -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Prologue -> m Prologue # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Prologue -> m Prologue # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Prologue -> m Prologue # | |
Ord Prologue # | |
Defined in Data.XML.Types | |
Show Prologue # | |
Generic Prologue # | |
NFData Prologue # | |
Defined in Data.XML.Types | |
type Rep Prologue # | |
Defined in Data.XML.Types type Rep Prologue = D1 ('MetaData "Prologue" "Data.XML.Types" "xml-types-0.3.8" 'False) (C1 ('MetaCons "Prologue" 'PrefixI 'True) (S1 ('MetaSel ('Just "prologueBefore") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Miscellaneous]) :*: (S1 ('MetaSel ('Just "prologueDoctype") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Doctype)) :*: S1 ('MetaSel ('Just "prologueAfter") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Miscellaneous])))) |
data Instruction #
Constructors
Instruction | |
Fields |
Instances
data Miscellaneous #
Constructors
MiscInstruction Instruction | |
MiscComment Text |
Instances
Document body
Instances
Eq Node # | |
Data Node # | |
Defined in Data.XML.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Node -> c Node # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Node # dataTypeOf :: Node -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Node) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Node) # gmapT :: (forall b. Data b => b -> b) -> Node -> Node # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Node -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Node -> r # gmapQ :: (forall d. Data d => d -> u) -> Node -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Node -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Node -> m Node # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Node -> m Node # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Node -> m Node # | |
Ord Node # | |
Show Node # | |
IsString Node # | |
Defined in Data.XML.Types Methods fromString :: String -> Node # | |
Generic Node # | |
NFData Node # | |
Defined in Data.XML.Types | |
type Rep Node # | |
Defined in Data.XML.Types type Rep Node = D1 ('MetaData "Node" "Data.XML.Types" "xml-types-0.3.8" 'False) ((C1 ('MetaCons "NodeElement" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Element)) :+: C1 ('MetaCons "NodeInstruction" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Instruction))) :+: (C1 ('MetaCons "NodeContent" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Content)) :+: C1 ('MetaCons "NodeComment" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)))) |
Constructors
Element | |
Fields
|
Instances
Eq Element # | |
Data Element # | |
Defined in Data.XML.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Element -> c Element # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Element # toConstr :: Element -> Constr # dataTypeOf :: Element -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Element) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Element) # gmapT :: (forall b. Data b => b -> b) -> Element -> Element # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Element -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Element -> r # gmapQ :: (forall d. Data d => d -> u) -> Element -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Element -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Element -> m Element # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Element -> m Element # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Element -> m Element # | |
Ord Element # | |
Show Element # | |
Generic Element # | |
NFData Element # | |
Defined in Data.XML.Types | |
type Rep Element # | |
Defined in Data.XML.Types type Rep Element = D1 ('MetaData "Element" "Data.XML.Types" "xml-types-0.3.8" 'False) (C1 ('MetaCons "Element" 'PrefixI 'True) (S1 ('MetaSel ('Just "elementName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Name) :*: (S1 ('MetaSel ('Just "elementAttributes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [(Name, [Content])]) :*: S1 ('MetaSel ('Just "elementNodes") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Node])))) |
Constructors
ContentText Text | |
ContentEntity Text | For pass-through parsing |
Instances
Eq Content # | |
Data Content # | |
Defined in Data.XML.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Content -> c Content # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Content # toConstr :: Content -> Constr # dataTypeOf :: Content -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Content) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Content) # gmapT :: (forall b. Data b => b -> b) -> Content -> Content # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Content -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Content -> r # gmapQ :: (forall d. Data d => d -> u) -> Content -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Content -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Content -> m Content # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Content -> m Content # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Content -> m Content # | |
Ord Content # | |
Show Content # | |
IsString Content # | |
Defined in Data.XML.Types Methods fromString :: String -> Content # | |
Generic Content # | |
NFData Content # | |
Defined in Data.XML.Types | |
type Rep Content # | |
Defined in Data.XML.Types type Rep Content = D1 ('MetaData "Content" "Data.XML.Types" "xml-types-0.3.8" 'False) (C1 ('MetaCons "ContentText" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text)) :+: C1 ('MetaCons "ContentEntity" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text))) |
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
|
Instances
Eq Name # | |
Data Name # | |
Defined in Data.XML.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Name -> c Name # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Name # dataTypeOf :: Name -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Name) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name) # gmapT :: (forall b. Data b => b -> b) -> Name -> Name # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r # gmapQ :: (forall d. Data d => d -> u) -> Name -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Name -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Name -> m Name # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Name -> m Name # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Name -> m Name # | |
Ord Name # | |
Show Name # | |
IsString Name # | |
Defined in Data.XML.Types Methods fromString :: String -> Name # | |
Generic Name # | |
NFData Name # | |
Defined in Data.XML.Types | |
type Rep Name # | |
Defined in Data.XML.Types type Rep Name = D1 ('MetaData "Name" "Data.XML.Types" "xml-types-0.3.8" 'False) (C1 ('MetaCons "Name" 'PrefixI 'True) (S1 ('MetaSel ('Just "nameLocalName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: (S1 ('MetaSel ('Just "nameNamespace") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text)) :*: S1 ('MetaSel ('Just "namePrefix") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe Text))))) |
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.
Constructors
Doctype | |
Fields
|
Instances
Eq Doctype # | |
Data Doctype # | |
Defined in Data.XML.Types Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Doctype -> c Doctype # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Doctype # toConstr :: Doctype -> Constr # dataTypeOf :: Doctype -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Doctype) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Doctype) # gmapT :: (forall b. Data b => b -> b) -> Doctype -> Doctype # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Doctype -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Doctype -> r # gmapQ :: (forall d. Data d => d -> u) -> Doctype -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Doctype -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Doctype -> m Doctype # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Doctype -> m Doctype # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Doctype -> m Doctype # | |
Ord Doctype # | |
Show Doctype # | |
Generic Doctype # | |
NFData Doctype # | |
Defined in Data.XML.Types | |
type Rep Doctype # | |
Defined in Data.XML.Types type Rep Doctype = D1 ('MetaData "Doctype" "Data.XML.Types" "xml-types-0.3.8" 'False) (C1 ('MetaCons "Doctype" 'PrefixI 'True) (S1 ('MetaSel ('Just "doctypeName") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 Text) :*: S1 ('MetaSel ('Just "doctypeID") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe ExternalID)))) |
data ExternalID #
Instances
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:
Constructors
Instances
Combinators
Filters
isInstruction :: Node -> [Instruction] #
Element traversal
elementChildren :: Element -> [Element] #
elementContent :: Element -> [Content] #
elementText :: Element -> [Text] #
Node traversal
nodeChildren :: Node -> [Node] #
nodeContent :: Node -> [Content] #
Attributes
hasAttribute :: Name -> Element -> [Element] #