Вот пример использования 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>
Вот три примера анализа XML в данных Clojureструктуры (формат Enlive) с использованием clojure.data.xml
, tupelo.parse.xml
и tupelo.parse.tagsoup
.