Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (get-value "<a><b>SOMETHING</b></a>)" "b")
- "SOMETHING"
- user=> (use 'clojure.xml)
- user=> (for [x (xml-seq
- (parse (java.io.File. file)))
- :when (= :b (:tag x))]
- (first (:content x)))
- (require '[net.cgrand.enlive-html :as html])
- (map html/text
- (html/select (html/html-snippet "<a><b>SOMETHING</b></a>") [:a :b]))
- (import javax.xml.parsers.DocumentBuilderFactory)
- (import javax.xml.xpath.XPathFactory)
- (defn document [filename]
- (-> (DocumentBuilderFactory/newInstance)
- .newDocumentBuilder
- (.parse filename)))
- (defn get-value [document xpath]
- (-> (XPathFactory/newInstance)
- .newXPath
- (.compile xpath)
- (.evaluate document)))
- user=> (get-value (document "something.xml") "//a/b/text()")
- "SOMETHING"
- user=> (require '[clojure zip xml] '[clojure.contrib.zip-filter [xml :as x]])
- user=> (def z (-> (.getBytes "<a><b>SOMETHING</b></a>")
- java.io.ByteArrayInputStream.
- clojure.xml/parse clojure.zip/xml-zip))
- user=> (x/xml1-> z :b x/text)
- "SOMETHING"
- (use 'com.github.kyleburton.clj-xpath :only [$x:text])
- ($x:text "/a/b" "<a><b>SOMETHING</b></a>)")
Add Comment
Please, Sign In to add comment