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.Doctype
- data Instruction = Instruction Text Text
- 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.Doctype
data Instruction Source #
Processing instruction.
Instances
Eq Instruction Source # | |
Defined in Data.XML.Parser.Mid (==) :: Instruction -> Instruction -> Bool # (/=) :: Instruction -> Instruction -> Bool # | |
Ord Instruction Source # | |
Defined in Data.XML.Parser.Mid compare :: Instruction -> Instruction -> Ordering # (<) :: Instruction -> Instruction -> Bool # (<=) :: Instruction -> Instruction -> Bool # (>) :: Instruction -> Instruction -> Bool # (>=) :: Instruction -> Instruction -> Bool # max :: Instruction -> Instruction -> Instruction # min :: Instruction -> Instruction -> Instruction # | |
Read Instruction Source # | |
Defined in Data.XML.Parser.Mid readsPrec :: Int -> ReadS Instruction # readList :: ReadS [Instruction] # readPrec :: ReadPrec Instruction # readListPrec :: ReadPrec [Instruction] # | |
Show Instruction Source # | |
Defined in Data.XML.Parser.Mid showsPrec :: Int -> Instruction -> ShowS # show :: Instruction -> String # showList :: [Instruction] -> ShowS # |
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 #
https://www.w3.org/TR/REC-xml/#dt-pi
>>>
parseOnly (runTokenParser tokenInstruction) "<?xml-stylesheet type='text/xsl' href='style.xsl'?>"
Right (Instruction "xml-stylesheet" "type='text/xsl' href='style.xsl'")
tokenComment :: CharParsing m => Monad m => TokenParser m Text Source #
https://www.w3.org/TR/REC-xml/#NT-Comment
>>>
parseOnly (runTokenParser tokenComment) "<!-- declarations for <head> & <body> -->"
Right " declarations for <head> & <body> ">>>
parseOnly (runTokenParser tokenComment) "<!-- B+, B, or B--->"
Right " B+, B, or B-"
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 #
https://www.w3.org/TR/REC-xml/#NT-doctypedecl
>>>
parseOnly (runTokenParser tokenDoctype) "<!DOCTYPE greeting SYSTEM 'hello.dtd'>"
Right (Doctype "greeting" (Just (SystemID "hello.dtd")) [])>>>
parseOnly (runTokenParser tokenDoctype) "<!DOCTYPE foo [ <!ENTITY x '<'> ]>"
Right (Doctype "foo" Nothing [GeneralEntityDeclaration "x" [ContentReference (EntityRef "lt")]])
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
.