"Jeremy Shaw" <[EMAIL PROTECTED]> writes:

> How do I create a HaXml filter that adds a new element as a child of
> an existing element. For example, let's say I have the XML document:
>     <a> <b/> <c/> </a>
> How do I add a new element under <a /> so that I have the document:
>     <a> <newElement/> <b/> <c/> </a>

Using the combinators, it goes something like this:

    mkElem "a" [ mkElem "newElement" []
               , children ] `o` tag "a"

Having matched the outer tag, you then rebuild it with some extra stuff
added.  Obviously you would abstract the common pattern if you do this
frequently:

    insertAtStart :: String -> String -> CFilter
    insertAtStart outer newelem =
        mkElem outer [ mkElem newElem []
                     , children ] `o` tag outer

Regards,
    Malcolm
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to