Excluding Multiple XML Tags With But

61 views
Skip to first unread message

Vitaly Peressada

unread,
Apr 25, 2013, 1:06:27 PM4/25/13
to enliv...@googlegroups.com

Given xml below I want to exclude :as and :bs with all their children:

<a>
  <id>a1</id>
</a>
<b>
  <id>b1</id>
</b>
<as>
  <id>as1</id>
</as>
<bs>
  <id>bs1</id>
</bs>

Tried selector [but #{:as :bs}]  - no luck. Any ideas?

Xavi Caballé

unread,
Apr 25, 2013, 4:51:59 PM4/25/13
to enlive-clj
Do you mean that you want to remove <as> and <bs> elements? If that's
the case, then...

(require '[net.cgrand.enlive-html :as h])
(h/sniptest "<a><id>a1</id></a><b><id>b1</id></b><as><id>as1</id></as><bs><id>bs1</id></bs>"
[#{:as :bs}] nil)
; => "<a><id>a1</id></a><b><id>b1</id></b>"

If what you mean is that you want to apply a transformation to all
elements excluding <as>, <bs> and their children, then...

(h/sniptest "<a><id>a1</id></a><b><id>b1</id></b><as><id>as1</id></as><bs><id>bs1</id></bs>"
[(h/but #{:as :bs})] nil)
; => "<as></as><bs></bs>"

Cheers,
xavi
> --
> You received this message because you are subscribed to the Google Groups
> "Enlive" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to enlive-clj+...@googlegroups.com.
> To post to this group, send email to enliv...@googlegroups.com.
> Visit this group at http://groups.google.com/group/enlive-clj?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Vitaly Peressada

unread,
Apr 26, 2013, 5:22:19 AM4/26/13
to enliv...@googlegroups.com
Thanks xavi, I meant "remove :as and :bs". 

What would be an equivalent syntax for use with 
h/select? I tried

(h/select
  xml-node
  [#{:as :bs} nil])

but got

<id>as1</id>
<id>bs1</id>

Vitaly

Xavi Caballé

unread,
Apr 26, 2013, 7:07:41 AM4/26/13
to enlive-clj
About your attempt to adapt my proposed solution to select, notice
that you're wrongly trying to use nil as a selector, but nil is a
transformation: "It's the idiomatic way to remove an element",
https://github.com/cgrand/enlive#the-at-form .

Anyway, I can't find a way to do that with select, but maybe you can
still get the desired result using something similar to what I
suggested (i.e. instead of selecting the nodes you're interested in,
you can remove those that you're not interested in).

Cheers,

xavi
Reply all
Reply to author
Forward
0 new messages