xml-parser-0.1.1.1: XML parser with informative error-reporting and simple API
Safe HaskellSafe-Inferred
LanguageHaskell2010

XmlParser

Synopsis

Execution

parseByteString :: Element a -> ByteString -> Either Text a Source #

Parse XML bytestring.

parseLazyByteString :: Element a -> ByteString -> Either Text a Source #

Parse XML lazy bytestring.

parseFile :: Element a -> FilePath -> IO (Either Text a) Source #

Parse XML file.

parseElementAst :: Element a -> Element -> Either Text a Source #

Parse an "xml-conduit" element AST.

Parsers by context

Element

data Element a Source #

Parse in the context of an element node.

Instances

Instances details
MonadFail Element Source # 
Instance details

Defined in XmlParser.AstParser

Methods

fail :: String -> Element a #

Applicative Element Source # 
Instance details

Defined in XmlParser.AstParser

Methods

pure :: a -> Element a #

(<*>) :: Element (a -> b) -> Element a -> Element b #

liftA2 :: (a -> b -> c) -> Element a -> Element b -> Element c #

(*>) :: Element a -> Element b -> Element b #

(<*) :: Element a -> Element b -> Element a #

Functor Element Source # 
Instance details

Defined in XmlParser.AstParser

Methods

fmap :: (a -> b) -> Element a -> Element b #

(<$) :: a -> Element b -> Element a #

Monad Element Source # 
Instance details

Defined in XmlParser.AstParser

Methods

(>>=) :: Element a -> (a -> Element b) -> Element b #

(>>) :: Element a -> Element b -> Element b #

return :: a -> Element a #

elementName :: (Maybe Text -> Text -> Either Text a) -> Element a Source #

Parse namespace and name with the given function.

elementNameIs :: Maybe Text -> Text -> Element () Source #

Fail if the namespace and name don't match the provided.

children :: Nodes a -> Element a Source #

Children sequence by order.

childrenByName :: ByName Element a -> Element a Source #

Look up elements by name and parse them.

attributesByName :: ByName Content a -> Element a Source #

Look up the last attribute by name and parse it.

astElement :: Element Element Source #

Expose the element's AST.

Nodes

data Nodes a Source #

Parser in the context of a sequence of nodes.

Instances

Instances details
Applicative Nodes Source # 
Instance details

Defined in XmlParser.AstParser

Methods

pure :: a -> Nodes a #

(<*>) :: Nodes (a -> b) -> Nodes a -> Nodes b #

liftA2 :: (a -> b -> c) -> Nodes a -> Nodes b -> Nodes c #

(*>) :: Nodes a -> Nodes b -> Nodes b #

(<*) :: Nodes a -> Nodes b -> Nodes a #

Functor Nodes Source # 
Instance details

Defined in XmlParser.AstParser

Methods

fmap :: (a -> b) -> Nodes a -> Nodes b #

(<$) :: a -> Nodes b -> Nodes a #

Monad Nodes Source # 
Instance details

Defined in XmlParser.AstParser

Methods

(>>=) :: Nodes a -> (a -> Nodes b) -> Nodes b #

(>>) :: Nodes a -> Nodes b -> Nodes b #

return :: a -> Nodes a #

elementNode :: Element a -> Nodes a Source #

Consume the next node expecting it to be element and parse its contents.

contentNode :: Content content -> Nodes content Source #

Consume the next node expecting it to be textual and parse its contents.

ByName

data ByName parser a Source #

Composable extension to a parser, which looks up its input by name.

Useful for searching elements and attributes by name.

Alternative and MonadPlus alternate only on lookup errors. When lookup is successful, but the deeper parser fails, the error propagates.

Monad and Applicative sequentially fetch contents by matching names.

Instances

Instances details
Alternative (ByName parser) Source # 
Instance details

Defined in XmlParser.AstParser

Methods

empty :: ByName parser a #

(<|>) :: ByName parser a -> ByName parser a -> ByName parser a #

some :: ByName parser a -> ByName parser [a] #

many :: ByName parser a -> ByName parser [a] #

Applicative (ByName parser) Source # 
Instance details

Defined in XmlParser.AstParser

Methods

pure :: a -> ByName parser a #

(<*>) :: ByName parser (a -> b) -> ByName parser a -> ByName parser b #

liftA2 :: (a -> b -> c) -> ByName parser a -> ByName parser b -> ByName parser c #

(*>) :: ByName parser a -> ByName parser b -> ByName parser b #

(<*) :: ByName parser a -> ByName parser b -> ByName parser a #

Functor (ByName parser) Source # 
Instance details

Defined in XmlParser.AstParser

Methods

fmap :: (a -> b) -> ByName parser a -> ByName parser b #

(<$) :: a -> ByName parser b -> ByName parser a #

Monad (ByName parser) Source # 
Instance details

Defined in XmlParser.AstParser

Methods

(>>=) :: ByName parser a -> (a -> ByName parser b) -> ByName parser b #

(>>) :: ByName parser a -> ByName parser b -> ByName parser b #

return :: a -> ByName parser a #

MonadPlus (ByName parser) Source # 
Instance details

Defined in XmlParser.AstParser

Methods

mzero :: ByName parser a #

mplus :: ByName parser a -> ByName parser a -> ByName parser a #

byName :: Maybe Text -> Text -> parser a -> ByName parser a Source #

Execute a parser on the result of looking up a content by namespace and name.

Content

data Content content Source #

Parser in the context of decoded textual content, which can be the value of an attribute or a textual node.

Instances

Instances details
MonadFail Content Source # 
Instance details

Defined in XmlParser.AstParser

Methods

fail :: String -> Content a #

Alternative Content Source # 
Instance details

Defined in XmlParser.AstParser

Methods

empty :: Content a #

(<|>) :: Content a -> Content a -> Content a #

some :: Content a -> Content [a] #

many :: Content a -> Content [a] #

Applicative Content Source # 
Instance details

Defined in XmlParser.AstParser

Methods

pure :: a -> Content a #

(<*>) :: Content (a -> b) -> Content a -> Content b #

liftA2 :: (a -> b -> c) -> Content a -> Content b -> Content c #

(*>) :: Content a -> Content b -> Content b #

(<*) :: Content a -> Content b -> Content a #

Functor Content Source # 
Instance details

Defined in XmlParser.AstParser

Methods

fmap :: (a -> b) -> Content a -> Content b #

(<$) :: a -> Content b -> Content a #

Monad Content Source # 
Instance details

Defined in XmlParser.AstParser

Methods

(>>=) :: Content a -> (a -> Content b) -> Content b #

(>>) :: Content a -> Content b -> Content b #

return :: a -> Content a #

MonadPlus Content Source # 
Instance details

Defined in XmlParser.AstParser

Methods

mzero :: Content a #

mplus :: Content a -> Content a -> Content a #

textContent :: Content Text Source #

Return the content as it is.

narrowedContent :: (Text -> Maybe a) -> Content a Source #

Map the content to a type if it's valid.

refinedContent :: (Text -> Either Text a) -> Content a Source #

Parse the content with a possibly failing function.

enumContent :: [(Text, a)] -> Content a Source #

Map the content using a dictionary.

attoparsedContent :: Parser a -> Content a Source #

Parse the content using the "attoparsec" parser.

qNameContent :: Content (Maybe Text, Text) Source #

Parse the content as XML Schema QName, automatically resolving the namespace as URI and failing, if none is associated.

Produces a URI associated with the namespace and name. If the content does not contain colon, produces an unnamespaced name.

Refs: