I used the listA
function to collect the result in a list. Here is my code :
module Famous where
import Text.XML.HXT.Core (isElem, hasName, getChildren, getText, listA, runX, readDocument, getName)
import Control.Arrow.ArrowTree (deep)
import Control.Arrow ((>>>), (&&&))
import Text.XML.HXT.Arrow.XmlArrow (ArrowXml)
import Text.XML.HXT.DOM.TypeDefs (XmlTree)
atTag :: ArrowXml a => String -> a XmlTree XmlTree
atTag tag = deep (isElem >>> hasName tag)
parseFamous :: ArrowXml a => a XmlTree [(String, String)]
parseFamous = atTag "famous_person" >>> listA (getChildren >>>
(getName &&& (getChildren >>> getText)))
main :: IO ()
main = do
let path = "famous.xml"
result <- runX (readDocument [] path >>> parseFamous)
print result