Preamble:

I've read some about xml and clojure, and done some mostly trivial things
(reading and writing values from and to xml). Most of the examples I've
seen of parse, zip, etc are very elegant and do a great job at reading a
specific x-path-like value or series of values. But I'm stuck trying to do
what I think is a more involved operation with xml - to the point where I'm
thinking clojure isn't the right tool. But I really enjoy programming in
clojure, and so I'm hoping some folks on the list can help point me in the
right direction. TIA!

Detail:

I have poked around some, read the APIs and examples, and I can even
navigate using something like (-> down down right node) but I can't seem to
reconcile or mix that manual navigation of the zipper (that is passing
"loc"s to each fn) and what I think I really want from something like xml->
(which doesn't return a loc, it returns a lazy-seq that's de-loc-ified).

Overview:

I have a backup of a database as xml. It's got a bunch of stuff in it, some
of which I want and some that I want to discard. But I mostly have a
blacklist of "this is what I need to discard" and I want everything else.
Once I have the parts of the db backup I want, I need to translate them to
insert statements to build the database back up. I'm having some difficulty
wrapping my head around what I haven't even gotten to solving yet - that I
need the list of tags and the value back, when something really nifty like
xml-> seems to be designed to only give me the values.

Code (ish):

Sample files below (or gisted https://gist.github.com/pbuckley/5060575).

xml:

<config xmlns="some-url">
  <FAKENAME xmlns="another-url">
    <SomeSettings>
      <SpecificSettings>
        <Foo>VAL1</Foo>
        <Bar>VAL3</Bar>
      </SpecificSettings>
    </SomeSettings>
    <DoNotWant>
      <SomeEnormousChildren>
      </SomEnormousChildren>
    </DoNotWant>
    <MoreConfig>
      <Baz>20</Baz>
      <Buz>300</Buz>
    </MoreConfig>
  </FAKENAME>
</config>

And this non-working somewhat pseudo-code (it gets more pseudo the further
you get):

(ns config-backup.confdbackup
  (:require [clojure.xml :as xml]
; I think I need both zip and data.zip?
            [clojure.zip :as zip] ; different from clojure.data.zip?
            [clojure.data.zip :as zf] ; used to be zip-filter?
            [clojure.data.zip.xml :as zx]))

(def my-xml (xml/parse "my-db-backup.xml"))

(def my-zipped-xml (zip/xml-zip my-xml))

(def this-worked (zx/xml-> my-zipped-xml :FAKENAME :SomeSettings
:SpecificSettings :Foo zx/text))

(def with-junk-removed (zip/remove (zx/xml-> my-zipped-xml :FAKENAME
:DoNotWant))) ; does not work

(defn transmogrifier
  "given the xml, nodes and text, create insert statements for them"
  [things]
  (do-some-magic))

(transmogrifier with-junk-removed) ; returns "insert FAKENAME SomeSettings
SpecificSettings Foo VAL1" and the stuff from MoreConfig etc




-- 
The king’s heart is like a stream of water directed by the Lord; He guides
it wherever He pleases.

-- 
-- 
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/groups/opt_out.


Reply via email to