diff --git a/xml-conduit/Text/XML/Stream/Parse.hs b/xml-conduit/Text/XML/Stream/Parse.hs index 20dd43f2..ed75af4e 100644 --- a/xml-conduit/Text/XML/Stream/Parse.hs +++ b/xml-conduit/Text/XML/Stream/Parse.hs @@ -20,25 +20,26 @@ -- >>> import Data.Conduit (runConduit, (.|)) -- >>> import Data.Text (Text, unpack) -- >>> import Data.XML.Types (Event) --- >>> data Person = Person Int Text deriving Show +-- >>> data Person = Person Int Text Text deriving Show -- >>> :{ -- let parsePerson :: MonadThrow m => ConduitT Event o m (Maybe Person) --- parsePerson = tag' "person" (requireAttr "age") $ \age -> do +-- parsePerson = tag' "person" parseAttributes $ \(age, goodAtHaskell) -> do -- name <- content --- return $ Person (read $ unpack age) name +-- 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 -- [ "" -- , "" --- , " Michael" --- , " Eliezer" +-- , " Michael" +-- , " Eliezer" -- , "" -- ] -- :} -- -- >>> runConduit $ parseLBS def inputXml .| force "people required" parsePeople --- [Person 25 "Michael",Person 2 "Eliezer"] +-- [Person 25 "Michael" "yes",Person 2 "Eliezer" "might become"] -- -- -- This module also supports streaming results using 'yield'. @@ -56,8 +57,8 @@ -- :} -- -- >>> runConduit $ parseLBS def inputXml .| force "people required" parsePeople' .| CL.mapM_ print --- Person 25 "Michael" --- Person 2 "Eliezer" +-- 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