[Haskell-beginners] HXT and missing or null values

Ian Knopke ian.knopke at gmail.com
Wed Jun 13 17:29:32 CEST 2012

I have an xml file I'm trying to parse using HXT. This is the code
(for some reason the list seems to be rejecting the XML example):

data Thing = Thing {first :: String, second :: String}
  getThings = atTag "thing" >>>
  proc x -> do
      first     <- text <<< atTag "first" -< x
      second <- text <<< atTag "second" -< x

      returnA -< Thing {first = first,second = second}

atTag tag = deep (isElem >>> hasName tag)

text = getChildren >>> getText

parseThings str = runX (readString [withValidate no] str >>> getThings)

The problem is that sometimes one of the tags is empty.

I'd like the code to return something like Thing
{first="val",second=""} but instead the entire entry is skipped. Can
someone explain to me what I need to do to get a null or empty string
value inserted instead?


More information about the Beginners mailing list