[Haskell-cafe] HaXml combinators

DCE dcespin at fastmail.fm
Tue Mar 1 18:55:44 CET 2011


I'm trying to use HaXml to do some relatively simple XML processing, but
I can't figure out how to get started.

My documents look something like this:

  <a bar="x">
    <b foo="x"/>
    <b foo="y"/>
    <a bar="y">
      <b foo="z"/>

I want to find any element tagged <a> that has an attribute bar=y, then
find the element under it tagged <b> with attribute foo=z, then add an
attribute "baz=t" to this <b>. 

I've tried various incantations like (tag "b" `o` children `o` (tag "a"
`with` attrval ...)), but they don't seem to work. And in general, I'm
not sure how to accomplish looking up and down the XML tree from a given
node. I have figured out how to use mkElemAttr to build a new element,
just not how to find the correct elements in the first place.

Additionally, I'm confused about when to use foldXml, deep, multi, and so on
for processing elements, and whether the 'inplace' combinator is needed
for replacing the <b> element with the result of mkElemAttr.

Any help would be appreciated.

More information about the Haskell-Cafe mailing list