On 15 October 2015 at 18:00, Mike <m...@thefrederickhome.name> wrote:

(dzx/xml1-> my-zipper dz/descendants)
>
> gives me what appears to be the original zipper structure, which I wasn't
> expecting.  I was expecting a flattened-out seq of the nodes.
>

The dz/descendants function doesn't return a seq of nodes, but a seq of
zippers. Remember, the moment you convert back into an individual node you
lose the capability to go back up the tree. So the descendants are actually
zippers, with the root of each zipper set to a descendant node.

Because you're using xml1-> and not xml->, you only get the first result of
the seq. This is why it looks like it just returns the original zipper, but
it actually returns the first descendent zipper.

If you want to get a list of all the descendants as nodes, you need to use
xml->, and put clojure.zip/node on the end:

  (dzx/xml-> my-zipper dz/descendants z/node)



> (dzx/xml1-> my-zipper :html)
>
> returns *nil*, which I *really *wasn't expecting.  Examples on the web
> led me to believe that this last call should match on the html tag.  Can
> anyone provide any explanation on these call and why I got these return
> values?
>

This is because you're searching the children of the current node. So
you're looking for a html tag inside a html tag.

These should return non-nil values:

  (dzx/xml1-> my-zipper :head)
  (dzx/xml1-> my-zipper :body)

If you want to find your input:

  (dzx/xml1-> my-zipper :body :input z/node)

Or to do a descendant search:

  (dzx/xml1-> my-zipper dz/descendants :input z/node)

- James

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to