snoyberg/xml — Issue #1: Example on Text.XML.Stream.Parse page doesn't work
Author: seanhess
Created: 2011-11-08 14:35:07+00:00
State: open

Hi, I'm pretty new to haskell, and was thrown off when the example below didn't work.

http://hackage.haskell.org/packages/archive/xml-enumerator/0.4.3.1/doc/html/Text-XML-Stream-Parse.html

This does work: It looks like there are some weird string things going on, and the arguments to parseFile_ are ParseSettings -> FilePath, not FilePath -> ParseSettings. Thanks!

{-# LANGUAGE OverloadedStrings #-}

import Text.XML.Stream.Parse
import Data.Text.Lazy (Text, unpack, pack)
import qualified Data.Text as T

data Person = Person { age :: Int, name :: Text }
deriving Show

parsePerson = tagName "person" (requireAttr "age") $ \age -> do
name <- content
return $ Person 10 (pack (T.unpack name))

parsePeople = tagNoAttr "people" $ many parsePerson

main = parseFile_ def "people.xml" $ force "people required" parsePeople