<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 超越巔峰 閱讀(2871) 評論(0)  編輯  收藏 所屬分類: Clojure


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


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 无码乱人伦一区二区亚洲| 亚洲日韩国产精品第一页一区| 亚洲av不卡一区二区三区| xvideos永久免费入口| 国产乱人免费视频| 日本精品久久久久久久久免费| 特级淫片国产免费高清视频| 亚洲国产精品无码中文lv| 在线观看国产情趣免费视频| 国产亚洲精品国产福利在线观看| 国产免费观看青青草原网站| 一级特黄色毛片免费看| 亚洲线精品一区二区三区| 中文字幕无码免费久久| 久久久亚洲欧洲日产国码是AV| 91手机看片国产永久免费| 亚洲入口无毒网址你懂的| 日韩激情无码免费毛片| 国产亚洲日韩在线a不卡| 久久亚洲中文字幕精品一区四| 中文无码成人免费视频在线观看 | 亚洲中文无码永久免费| 精品国产免费观看久久久| 人体大胆做受免费视频| 亚洲va无码专区国产乱码| 免费精品国产日韩热久久| 在线观看亚洲专区| 久久久久久a亚洲欧洲AV| 成人黄18免费视频| 精品国产免费人成网站| 久久综合亚洲色一区二区三区| 女人被男人桶得好爽免费视频 | 精品免费tv久久久久久久| 亚洲AV无码乱码麻豆精品国产| 成人永久免费高清| 精品视频在线免费观看| 国产精品亚洲专区无码唯爱网| 国产AV无码专区亚洲Av| 久久午夜免费视频| 国产男女爽爽爽免费视频| 亚洲五月综合缴情婷婷|