On Wed, Feb 24, 2010 at 8:09 PM, James Sofra <james.so...@gmail.com> wrote:
> Hi all,
>
> I am trying to use (abuse? *) zip-filter to remove some nodes and
> return the xml tree to me.
> If I do something like this:
>    (xml1-> zipped-xml zf/descendants :model zip/remove zip/root)
>
> I can remove one :model node, but what if I want to remove more than
> one or all of the :model nodes?
>
> If I do this:
>    (xml-> zipped-xml zf/descendants :model zip/remove zip/root)
>
> I get multiple xml-trees each with one node removed from each. So I
> wrote a function "zip-top" to take me back to the top (like zip/root
> but returns the loc not node) and can do this:
>    (xml-> zipped-xml zf/descendants :model zip/remove zip-top zf/
> descendants :model zip/remove zip/root)
>
> and that will remove two of them but that is not really ideal I would
> like to remove all of them ... any ideas? am I way off track? is there
> better ways to manipulate xml trees in clojure? Enlive maybe? I
> haven't played with it yet.
>
> * I realise this probably abusing zip-filter since it is only supposed
> to take predicates and zip/remove is not really a predicate.

You have correctly identified the behavior of zip-filter and its
negative consequences.  I didn't realize until too late that my
design for zip-filter essentially prevents using it to edit more
than a single filter result.  I haven't thought deeply about what
could be done to fix it -- I think it would have to be pretty
radical.  Instead of returning a lazy seq it would have to have
some kind of mechanism for continuation, or perhaps using a monad
or one of these new cells.

Christophe Grand's "enlive" lib address a lot of these problems
for html and some xml.  I'd recommend you take a look at it and
see if it would work in your case.

--Chouser
http://joyofclojure.com/

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to