Comment detail

XMLから情報を取り出す (Nested Flatten)
全部パーズしてからsxpathで取り出すので効率は悪いです。 sxpathは一致するノード全てのリストを返すんで、最初のノードの内容だけmatch節で取り出してますが、お題ではそのへんがちょっと不明確? (lastBuildDataは必ずひとつなのか、とか) Gaucheの内部エンコーディングがutf-8でない場合は*data*のエンコーディングを変換しといてください。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
(use sxml.ssax)
(use sxml.sxpath)
(use rfc.http)
(use util.match)

(define *data* (values-ref (http-get "ja.doukaku.org" "/feeds/comments") 2))

(define (extract)
  (match ((sxpath '(// lastBuildDate))
          (call-with-input-string *data* (cut ssax:xml->sxml <> '())))
    [(('lastBuildDate content) . _) content]
    [else #f]))
自己レス。わざわざmatch使う必要無いや。
1
2
3
(define (extract)
  ((sxpath '(// lastBuildDate *text*))
   (call-with-input-string *data* (cut ssax:xml->sxml <> '()))))

Index

Feed

Other

Link

Pathtraq

loading...