[Haskell-cafe] Children elements with HXT

Tony Morris tonymorris at gmail.com
Tue Dec 22 18:40:44 EST 2009

I am trying to parse XML using HXT following

Here is my XML file (way.xml):

<way id="27776903" visible="true" timestamp="2009-05-31T13:39:15Z"
version="3" changeset="1368552" user="Matt" uid="70">
  <tag k="access" v="private"/>
  <tag k="highway" v="service"/>

The problem is when parsing, by reading the <tag> entries into the
list held by the Way data structure, I cannot get anything but an
empty list.

Here is my parsing code:

import Text.XML.HXT.Arrow

newtype Way = Way {
  tags :: [Tag]
} deriving (Eq, Show)

xpWay :: PU Way
xpWay = xpElem "way" (xpWrap (Way, tags) (xpList xpTag))

data Tag = Tag {
  k :: String,
  v :: String
} deriving (Eq, Show)

xpTag :: PU Tag
xpTag = xpElem "tag" (xpWrap (uncurry Tag, k &&& v) (xpPair (xpAttr
"k" xpText) (xpAttr "v" xpText)))

When I run, I get the following result:

Main> run = runX (xunpickleDocument xpWay [] "way.xml")
[Way {tags = []}]

Why is the tags list empty instead of holding two entries?

Tony Morris

More information about the Haskell-Cafe mailing list