[Haskell-cafe] Capturing the parent element as I parse XML using parsec

Antoine Latter aslatter at gmail.com
Sun Jul 29 17:54:43 CEST 2012

On Sun, Jul 29, 2012 at 1:21 AM, C K Kashyap <ckkashyap at gmail.com> wrote:
> Hi,
> With the help of the cafe I've been able to write up the xml parser using
> parsec -
> https://github.com/ckkashyap/really-simple-xml-parser/blob/master/RSXP.hs
> I am struggling with an idea though - How can I capture the parent element
> of each element as I parse? Is it possible or would I have to do a second
> pass to do the fixup?

What are you trying to do? Maybe you could give an example of what
you'd like to produce?

Generally speaking, having tree elements in a Haskell datatype point
to their parent and their children is asking for trouble - it means
you can't change any part of the tree without re-building the entire
tree (otherwise your parent pointers point to the parent in the old
version of the tree).

If you're interested in complex traversals and transformation of XML
trees, I like the cursor API here:

HaXML is also popular for whole-tree queries and transformations.


More information about the Haskell-Cafe mailing list