<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    J2EE之巔

     

    Clojure XPath

    The functions to support using XPath in Clojure.

    Source Code

     1 ;The code was implemented by caichao@amazon.com
     2 ;You could use the code anyway, but should keep the comments
     3 ;Created 2012.10
     4 (ns clojure.ccsoft.xml
     5   (:require [clojure.xml :as xml]))
     6  
     7 (import '(java.io StringReader)
     8         '(java.io ByteArrayInputStream))
     9  
    10 (defn xml-structure [xml-txt] 
    11    [ (xml/parse (-> xml-txt
    12               (.getBytes)
    13               (ByteArrayInputStream.)
    14      )
    15     )]
    16 )
    17  
    18 (defn node [tag xmlStruct]
    19  
    20   (first (filter #(= (:tag %) tag) (:content xmlStruct)))
    21 )
    22  
    23 (defn node [path xml-txt]
    24    (loop [path path 
    25           xml-content (xml-structure xml-txt) 
    26           ]
    27       (let [current-tag (first path) current-elem (first xml-content)]
    28         (if (= (:tag current-elem ) current-tag)
    29  
    30           (if (= (count path) 1)
    31             current-elem 
    32             (recur  (rest path) (:content current-elem ))
    33           )
    34           (if (> (count  xml-content) 1)
    35            (recur path  (rest xml-content))
    36           )
    37         )
    38      )
    39     )
    40  )

    How to Use

    (def cmd-example "<command>
                       <header>
                         
    <type>script</type>
                         
    <transaction_id>12345</transaction_id>
                       
    </header>
                       
    <body>
                          println 
    3+4;
                       
    </body>
                      
    </command>")
     
     
    (node [:command :header :transaction_id] cmd
    -example)


    posted on 2012-10-15 10:15 超越巔峰 閱讀(2880) 評論(0)  編輯  收藏 所屬分類: Clojure


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 一区二区三区亚洲| 国产AV无码专区亚洲AV漫画| 亚洲韩国在线一卡二卡| 久久青草免费91线频观看站街| 亚洲毛片av日韩av无码| 特a级免费高清黄色片| 免费在线看片网站| 国产免费播放一区二区| 亚洲乱亚洲乱少妇无码| 精品一区二区三区高清免费观看 | 污视频网站在线观看免费| 日韩在线a视频免费播放| 国产精品国产亚洲区艳妇糸列短篇| 四虎成人免费网址在线| 在线亚洲精品视频| 2048亚洲精品国产| 国产日韩AV免费无码一区二区| 久久精品亚洲一区二区| 91久久青青草原线免费| jiz zz在亚洲| 又粗又黄又猛又爽大片免费| caoporm碰最新免费公开视频| 亚洲人成网亚洲欧洲无码久久 | 2022久久国产精品免费热麻豆| 亚洲精品国产福利在线观看| 美女被cao免费看在线看网站| 久久久久久亚洲av无码蜜芽| 亚洲成年人啊啊aa在线观看| 国产色爽免费无码视频| 亚洲综合校园春色| 亚洲?v无码国产在丝袜线观看| 免费观看一区二区三区| 亚洲人成网网址在线看| 免费在线观看黄网| 污视频在线免费观看| 亚洲中文字幕AV每天更新| 国产亚洲?V无码?V男人的天堂| 四虎国产精品永久免费网址| 亚洲AV成人一区二区三区观看 | 亚洲视频在线观看免费| 国产精品亚洲av色欲三区|