2
votes

I recently posted about using HXT pickles for parsing. After some reading I decided use regular HXT instead.

However, I am unable to create lists, ie. I have an XML document:

<meta>
    <sampleQuery>sample1</sampleQuery>
    <sampleQuery>sample2</sampleQuery>
</meta>

and a parsing function

parseMeta =
  proc x -> do
    meta          <- deep (isElem >>> hasName "meta") -< x
    sampleQueries <- getText <<< getChildren <<< deep (hasName "sampleQuery") -< meta
    returnA -< Meta sampleQueries

sampleQueries should have the type [String] (["sample1", "sample2"] in this case) but I am unable to achieve this.

1

1 Answers

2
votes

Arrow notation seems like overkill here.

import Text.XML.HXT.Core

xml = unlines 
  [ "<meta>"
  , "<sampleQuery>sample1</sampleQuery>"
  , "<sampleQuery>sample2</sampleQuery>"
  , "</meta>"
  ]

queries = hasName "meta" /> hasName "sampleQuery" /> getText

main = runX (readString [] xml /> queries) >>= print

This will print ["sample1","sample2"], as expected.