Hoogle Search

Within LTS Haskell 22.21 (ghc-9.6.5)

Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.

  1. module Text.XML.Stream.Parse

    This module provides both a native Haskell solution for parsing XML documents into a stream of events, and a set of parser combinators for dealing with a stream of events. As a simple example:

    >>> :set -XOverloadedStrings
    
    >>> import Conduit (runConduit, (.|))
    
    >>> import Data.Text (Text, unpack)
    
    >>> import Data.XML.Types (Event)
    
    >>> data Person = Person Int Text Text deriving Show
    
    >>> :{
    let parsePerson :: MonadThrow m => ConduitT Event o m (Maybe Person)
    parsePerson = tag' "person" parseAttributes $ \(age, goodAtHaskell) -> do
    name <- content
    return $ Person (read $ unpack age) name goodAtHaskell
    where parseAttributes = (,) <$> requireAttr "age" <*> requireAttr "goodAtHaskell" <* ignoreAttrs
    parsePeople :: MonadThrow m => ConduitT Event o m (Maybe [Person])
    parsePeople = tagNoAttr "people" $ many parsePerson
    inputXml = mconcat
    [ "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
    , "<people>"
    , "  <person age=\"25\" goodAtHaskell=\"yes\">Michael</person>"
    , "  <person age=\"2\" goodAtHaskell=\"might become\">Eliezer</person>"
    , "</people>"
    ]
    :}
    
    >>> runConduit $ parseLBS def inputXml .| force "people required" parsePeople
    [Person 25 "Michael" "yes",Person 2 "Eliezer" "might become"]
    
    This module also supports streaming results using yield. This allows parser results to be processed using conduits while a particular parser (e.g. many) is still running. Without using streaming results, you have to wait until the parser finished before you can process the result list. Large XML files might be easier to process by using streaming results. See http://stackoverflow.com/q/21367423/2597135 for a related discussion.
    >>> import Data.Conduit.List as CL
    
    >>> :{
    let parsePeople' :: MonadThrow m => ConduitT Event Person m (Maybe ())
    parsePeople' = tagNoAttr "people" $ manyYield parsePerson
    :}
    
    >>> runConduit $ parseLBS def inputXml .| force "people required" parsePeople' .| CL.mapM_ print
    Person 25 "Michael" "yes"
    Person 2 "Eliezer" "might become"
    
    Previous versions of this module contained a number of more sophisticated functions written by Aristid Breitkreuz and Dmitry Olshansky. To keep this package simpler, those functions are being moved to a separate package. This note will be updated with the name of the package(s) when available.

  2. data ParseSettings

    xml-conduit Text.XML.Stream.Parse

    No documentation available.

  3. parseBytes :: MonadThrow m => ParseSettings -> ConduitT ByteString Event m ()

    xml-conduit Text.XML.Stream.Parse

    Parses a byte stream into Events. This function is implemented fully in Haskell using attoparsec-text for parsing. The produced error messages do not give line/column information, so you may prefer to stick with the parser provided by libxml-enumerator. However, this has the advantage of not relying on any C libraries. This relies on detectUtf to determine character encoding, and parseText to do the actual parsing.

  4. parseBytesPos :: MonadThrow m => ParseSettings -> ConduitT ByteString EventPos m ()

    xml-conduit Text.XML.Stream.Parse

    No documentation available.

  5. parseFile :: MonadResource m => ParseSettings -> FilePath -> ConduitT i Event m ()

    xml-conduit Text.XML.Stream.Parse

    A helper function which reads a file from disk using enumFile, detects character encoding using detectUtf, parses the XML using parseBytes, and then hands off control to your supplied parser.

  6. parseLBS :: MonadThrow m => ParseSettings -> ByteString -> ConduitT i Event m ()

    xml-conduit Text.XML.Stream.Parse

    Parse an event stream from a lazy ByteString.

  7. parseText :: MonadThrow m => ParseSettings -> ConduitT Text Event m ()

    xml-conduit Text.XML.Stream.Parse

    Parses a character stream into Events. This function is implemented fully in Haskell using attoparsec-text for parsing. The produced error messages do not give line/column information, so you may prefer to stick with the parser provided by libxml-enumerator. However, this has the advantage of not relying on any C libraries. Since 1.2.4

  8. parseTextPos :: MonadThrow m => ParseSettings -> ConduitT Text EventPos m ()

    xml-conduit Text.XML.Stream.Parse

    Same as parseText, but includes the position of each event. Since 1.2.4

  9. data AttrParser a

    xml-conduit Text.XML.Stream.Parse

    A monad for parsing attributes. By default, it requires you to deal with all attributes present on an element, and will throw an exception if there are unhandled attributes. Use the requireAttr, attr et al functions for handling an attribute, and ignoreAttrs if you would like to skip the rest of the attributes on an element. Alternative instance behaves like First monoid: it chooses first parser which doesn't fail.

  10. UnparsedAttributes :: [(Name, [Content])] -> XmlException

    xml-conduit Text.XML.Stream.Parse

    No documentation available.

Page 1 of 2 | Next