Safe Haskell | None |
---|---|
Language | Haskell2010 |
Mid-level XML parsers, built on top of Data.XML.Parser.Low:
- some formatting details are abstracted away (e.g. quoting, whitespacing), therefore parsers are not reversible
- entities delimited by an opening and closing sequence are recognized, except for tags which need a more complex, recursive logic
- token parsers do not overlap, therefore XML document can be tokenized in a stateless way
All documentation examples assume the following setup:
:set -XOverloadedStrings import Data.Attoparsec.ByteString
Synopsis
- module Data.XML.Parser.Mid.Attribute
- module Data.XML.Parser.Mid.Comment
- module Data.XML.Parser.Mid.Doctype
- module Data.XML.Parser.Mid.Instruction
- data XMLDeclaration = XMLDeclaration Text (Maybe Text) (Maybe Bool)
- data StartTag = StartTag QName [Attribute]
- data EmptyElementTag = EmptyElementTag QName [Attribute]
- data Token
- data TokenParser m a
- runTokenParser :: TokenParser m a -> m a
- tokenInstruction :: CharParsing m => Monad m => TokenParser m Instruction
- tokenComment :: CharParsing m => Monad m => TokenParser m Text
- tokenCdata :: CharParsing m => Monad m => TokenParser m Text
- tokenDoctype :: CharParsing m => Monad m => TokenParser m Doctype
- tokenXmlDeclaration :: CharParsing m => Monad m => TokenParser m XMLDeclaration
- tokenStartTag :: CharParsing m => Monad m => TokenParser m StartTag
- tokenEndTag :: CharParsing m => Monad m => TokenParser m QName
- tokenEmptyElementTag :: CharParsing m => Monad m => TokenParser m EmptyElementTag
- tokenData :: CharParsing m => Monad m => TokenParser m [Content]
- anyToken :: CharParsing m => Monad m => TokenParser m Token
Documentation
module Data.XML.Parser.Mid.Comment
module Data.XML.Parser.Mid.Doctype
data XMLDeclaration Source #
Instances
Eq XMLDeclaration Source # | |
Defined in Data.XML.Parser.Mid (==) :: XMLDeclaration -> XMLDeclaration -> Bool # (/=) :: XMLDeclaration -> XMLDeclaration -> Bool # | |
Ord XMLDeclaration Source # | |
Defined in Data.XML.Parser.Mid compare :: XMLDeclaration -> XMLDeclaration -> Ordering # (<) :: XMLDeclaration -> XMLDeclaration -> Bool # (<=) :: XMLDeclaration -> XMLDeclaration -> Bool # (>) :: XMLDeclaration -> XMLDeclaration -> Bool # (>=) :: XMLDeclaration -> XMLDeclaration -> Bool # max :: XMLDeclaration -> XMLDeclaration -> XMLDeclaration # min :: XMLDeclaration -> XMLDeclaration -> XMLDeclaration # | |
Read XMLDeclaration Source # | |
Defined in Data.XML.Parser.Mid readsPrec :: Int -> ReadS XMLDeclaration # readList :: ReadS [XMLDeclaration] # | |
Show XMLDeclaration Source # | |
Defined in Data.XML.Parser.Mid showsPrec :: Int -> XMLDeclaration -> ShowS # show :: XMLDeclaration -> String # showList :: [XMLDeclaration] -> ShowS # |
data EmptyElementTag Source #
Instances
Eq EmptyElementTag Source # | |
Defined in Data.XML.Parser.Mid (==) :: EmptyElementTag -> EmptyElementTag -> Bool # (/=) :: EmptyElementTag -> EmptyElementTag -> Bool # | |
Ord EmptyElementTag Source # | |
Defined in Data.XML.Parser.Mid compare :: EmptyElementTag -> EmptyElementTag -> Ordering # (<) :: EmptyElementTag -> EmptyElementTag -> Bool # (<=) :: EmptyElementTag -> EmptyElementTag -> Bool # (>) :: EmptyElementTag -> EmptyElementTag -> Bool # (>=) :: EmptyElementTag -> EmptyElementTag -> Bool # max :: EmptyElementTag -> EmptyElementTag -> EmptyElementTag # min :: EmptyElementTag -> EmptyElementTag -> EmptyElementTag # | |
Read EmptyElementTag Source # | |
Defined in Data.XML.Parser.Mid | |
Show EmptyElementTag Source # | |
Defined in Data.XML.Parser.Mid showsPrec :: Int -> EmptyElementTag -> ShowS # show :: EmptyElementTag -> String # showList :: [EmptyElementTag] -> ShowS # |
data TokenParser m a Source #
A parser that consumes whole Token
s.
Instances
runTokenParser :: TokenParser m a -> m a Source #
tokenInstruction :: CharParsing m => Monad m => TokenParser m Instruction Source #
tokenComment :: CharParsing m => Monad m => TokenParser m Text Source #
tokenCdata :: CharParsing m => Monad m => TokenParser m Text Source #
https://www.w3.org/TR/REC-xml/#dt-cdsection
>>>
parseOnly (runTokenParser tokenCdata) "<![CDATA[<greeting>Hello, world!</greeting>]]>"
Right "<greeting>Hello, world!</greeting>"
tokenDoctype :: CharParsing m => Monad m => TokenParser m Doctype Source #
tokenXmlDeclaration :: CharParsing m => Monad m => TokenParser m XMLDeclaration Source #
https://www.w3.org/TR/REC-xml/#NT-XMLDecl
>>>
parseOnly (runTokenParser tokenXmlDeclaration) "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>"
Right (XMLDeclaration "1.0" (Just "UTF-8") (Just True))
tokenStartTag :: CharParsing m => Monad m => TokenParser m StartTag Source #
https://www.w3.org/TR/REC-xml/#NT-STag
>>>
parseOnly (runTokenParser tokenStartTag) "<termdef id='dt-dog' term='dog'>"
Right (StartTag (QName {namePrefix = "", nameLocal = "termdef"}) [Attribute (QName {namePrefix = "", nameLocal = "id"}) [ContentText "dt-dog"],Attribute (QName {namePrefix = "", nameLocal = "term"}) [ContentText "dog"]])>>>
parse (runTokenParser tokenStartTag) "<updated>2003-12-13T18:30:02Z</updated>"
Done "2003-12-13T18:30:02Z</updated>" (StartTag (QName {namePrefix = "", nameLocal = "updated"}) [])
tokenEndTag :: CharParsing m => Monad m => TokenParser m QName Source #
https://www.w3.org/TR/REC-xml/#NT-ETag
>>>
parseOnly (runTokenParser tokenEndTag) "</termdef>"
Right (QName {namePrefix = "", nameLocal = "termdef"})
tokenEmptyElementTag :: CharParsing m => Monad m => TokenParser m EmptyElementTag Source #
https://www.w3.org/TR/REC-xml/#NT-EmptyElemTag
>>>
parseOnly (runTokenParser tokenEmptyElementTag) "<IMG align='left' src='http://www.w3.org/Icons/WWW/w3c_home' />"
Right (EmptyElementTag (QName {namePrefix = "", nameLocal = "IMG"}) [Attribute (QName {namePrefix = "", nameLocal = "align"}) [ContentText "left"],Attribute (QName {namePrefix = "", nameLocal = "src"}) [ContentText "http://www.w3.org/Icons/WWW/w3c_home"]])
tokenData :: CharParsing m => Monad m => TokenParser m [Content] Source #
https://www.w3.org/TR/REC-xml/#NT-CharData
>>>
parseOnly (runTokenParser tokenData) "Rock & roll"
Right [ContentText "Rock ",ContentReference (EntityRef "amp"),ContentText " roll"]
anyToken :: CharParsing m => Monad m => TokenParser m Token Source #
Parse any Token
.