我正在尝试将以下映射转换为 xml(具有向量值的任何键都需要为向量中的每个元素重复 xml 中的键)
(use 'clojure.xml)
(defn map-to-xml2 [k v]
(cond
(nil? k) (for [[e a] v] {:tag e :content (map-to-xml2 e a)})
(map? v) (for [[e a] v] {:tag e :content (map-to-xml2 e a)})
(vector? v) (for [x v] {:tag k :content (for [[e a] x] {:tag e :content (map-to-xml2 e a)})})
:else [(str v)]))
(def studios [{:company {:name "Acme Corp" :id 1 :rank 20 :employee
[{:fname "Mark" :lname "Jones"} {:fname "Leroy" :lname "Bell"}]}}
{:company {:name "Eastwood Studios" :id 2 :rank 35 :employee
[{:fname "Lee" :lname "Marvin"} {:fname "Clint" :lname "Eastwood"}]}}])
(->> studios first (map-to-xml2 nil) first emit with-out-str (spit "acme.xml"))
(->> studios second (map-to-xml2 nil) first emit with-out-str (spit "eastwood.xml"))
我得到以下xml
<?xml version='1.0' encoding='UTF-8'?>
<company>
<rank>35</rank>
<employee>
<employee>
<lname>Marvin</lname>
<fname>Lee</fname>
</employee>
<employee>
<lname>Eastwood</lname>
<fname>Clint</fname>
</employee>
</employee>
<name>Eastwood Studios</name>
<id>2</id>
</company>
当我真正需要通过肥皂发送的是
<?xml version='1.0' encoding='UTF-8'?>
<company>
<name>Eastwood Studios</name>
<id>2</id>
<rank>35</rank>
<employee>
<lname>Marvin</lname>
<fname>Lee</fname>
</employee>
<employee>
<lname>Eastwood</lname>
<fname>Clint</fname>
</employee>
</company>
我如何更正上述内容?
我正在尝试从 excel 文件中读取数据,并为具有相同 id 的每一行或每组行进行 web 服务调用,然后使用响应更新电子表格。以上就是生成webservice调用需要的xml。