答案 0 :(得分:0)
以下是使用clojure.data.xml
的示例:
(ns tst.tupelo.parse.xml
(:use tupelo.core tupelo.test)
(:require
[clojure.data.xml :as clj-xml]))
(def enlive-tree-normalized-nonblank
{:tag :foo,
:attrs {},
:content [{:tag :name, :attrs {}, :content ["John"]}
{:tag :address, :attrs {}, :content ["1 hacker way"]}
{:tag :phone, :attrs {}, :content []}
{:tag :school,
:attrs {},
:content [{:tag :name, :attrs {}, :content ["Joe"]}
{:tag :state, :attrs {}, :content ["CA"]}
{:tag :type, :attrs {}, :content ["FOOBAR"]}]}
{:tag :college,
:attrs {},
:content [{:tag :name, :attrs {}, :content ["mit"]}
{:tag :address, :attrs {}, :content []}
{:tag :state, :attrs {}, :content ["Denial"]}]}]})
(println (clj-xml/indent-str enlive-tree-normalized-nonblank))
结果:
<?xml version="1.0" encoding="UTF-8"?>
<foo>
<name>John</name>
<address>1 hacker way</address>
<phone/>
<school>
<name>Joe</name>
<state>CA</state>
<type>FOOBAR</type>
</school>
<college>
<name>mit</name>
<address/>
<state>Denial</state>
</college>
</foo>
Here are three examples,使用clojure.data.xml
,tupelo.parse.xml
和tupelo.parse.tagsoup
将XML解析为Clojure数据结构(实时格式)。
答案 1 :(得分:0)
这正是您所需要的:
(:require [clojure.data.xml :as xml])
(xml/emit-str
(xml/element
:response {}
(map (fn make-node [[f s]]
(if (map? s)
(xml/element f {} (map make-node (seq s)))
(xml/element f {} s)))
(seq --your-map--))))