Back

attrs (clj)

(source)

variable

Examples

clojure

(ns clojure.test-clojure.clojure-xml
  (:use clojure.test)
  (:require [clojure.xml :as xml])
  (:import [java.io ByteArrayInputStream]))

(deftest CLJ-2611-avoid-XXE
  (let [xml-str "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<!DOCTYPE foo [
  <!ELEMENT foo ANY >
  <!ENTITY xxe SYSTEM \"file:///etc/hostname\" >]>
<foo>&xxe;</foo>"]
    (is (= {:tag :foo, :attrs nil, :content nil}
           (with-open [input (ByteArrayInputStream. (.getBytes xml-str))]
             (xml/parse input))))))
; parse
reborg/clojure-essential-reference
(require '[clojure.xml :as xml]
         '[clojure.java.io :as io])

;; {:tag :html,
;;  :attrs {:xmlns "http://www.w3.org/1999/xhtml"},
;;  :content [{:tag :article, :attrs nil, :content ["Hello"]}]}
reborg/clojure-essential-reference
(require '[clojure.xml :as xml]) ; <1>

(keys document) ; <3>
;; (:tag :attrs :content)
reborg/clojure-essential-reference
(require '[clojure.java.io :as io])
(require '[clojure.xml :as xml])

;; ({:tag :accountId, :attrs nil, :content ["3764882"]}
    {:tag :currentBalance, :attrs nil, :content ["80.12389"]}
    {:tag :contractId, :attrs nil, :content ["77488"]}
    {:tag :currentBalance, :attrs nil, :content ["1921.89"]})
reborg/clojure-essential-reference
(require '[clojure.java.io :as io])
(require '[clojure.xml :as xml])

;; ({:tag :accountId, :attrs nil, :content ["3764882"]}
    {:tag :currentBalance, :attrs nil, :content ["80.12389"]}
    {:tag :contractId, :attrs nil, :content ["77488"]}
    {:tag :currentBalance, :attrs nil, :content ["1921.89"]})
zhaojw/closerve
(ns closerve.snippet
  (:require [hickory.core :as h]
            [clojure.zip :as zip]
            [clojure.set :as set]
            [clojure.core.async :refer [go close! >!! <! >! sliding-buffer chan]])
  (:use [clojure.xml] 
        [clojure.walk]        
        [clojure.contrib.core]
        [hickory zip render]
        [ring.util.time :only (format-date)]
        [ring.util.codec :as codec]
        [closerve state util html wscmd liftutil]))

(register-lift-snippet
 "LazyLoad"
 [node req page-id lift-instr]
 (let [uuid (make-random-uuid)
       fastret (assoc-in node [:attrs :id] uuid)
       fastret (assoc fastret :content ["Loading..."])]
   (go (let [slowret (process-snippets node req page-id)]
         (send-cmd-to-page page-id {:act :replaceWith
                                    :selector (str "#" uuid)
                                    :html (hickory-to-html slowret)})))
   fastret)
 )

(register-lift-snippet
 "comet"
 [node req page-id lift-instr]
 (let [uuid (make-random-uuid)
       actor-fn (@name->comet (lift-instr "type"))
       comet-ch (chan)
       fastret (assoc node [:attrs :id] uuid)]
   (swap! page->comet-ch assoc-into-key-values page-id comet-ch)
   (if actor-fn (actor-fn comet-ch req page-id uuid))
   fastret))