Code: Select all
( do-while (find "title" outlist)
( set 'i ( find "title" outlist ))
( set 'outlist ( i outlist))
( push (pop outlist) title-list )
)
Code: Select all
( do-while (find "title" outlist)
( set 'i ( find "title" outlist ))
( set 'outlist ( i outlist))
( push (pop outlist) title-list )
)
Code: Select all
(map rest (ref-all '("title" *) x match true))
Code: Select all
( do-while (find "title" outlist)
( set 'i ( find "title" outlist ))
( set 'outlist ( i outlist))
( pop outlist )
( push (pop outlist) title-list ))
Code: Select all
(define (sxml<-file FILEPATH)
(xml-type-tags nil nil nil nil)
(xml-parse (read-file FILEPATH) (+ 1 2 4 16)))
(define *wp-export-db* (sxml<-file "wp-export.xml"))
Code: Select all
(define (ref-all-match KEY LST) (ref-all KEY LST match true))
Code: Select all
(define (wpx-get-titles WPX)
(map last
(ref-all-match '("title" *)
(ref-all-match '("item" ("title" *) *) WPX))))
Code: Select all
> (wpx-get-titles *wp-export-db*)
("Sample Page" "About" "Things" "title" "Home" "Home" "title" "Notes on Clojure Records"
"Unit-Slope" "basis" "Horizontal" "Skating" "tumble" "separate" "simplescene" "simplescene"
"spirograph-demo" "StarFish" "Unit-Slope" "half-slope (1)" "Permutations of a Multiset"
"Ripping Access Databases in Clojure" "Reactive Swing via Observables Pt 1"
"Reactive Swing and Observables Pt 2" "Reactive Swing and Observables Pt 3"
"Reactive Swing and Observables pt 4" "Reactive Swing and Observables Pt 5" "Reactive Swing and Observables Pt 6"
"Fun with Functional Reactive Programming Pt 1" "A Simple Scene Graph in Clojure")
Code: Select all
(define (wpx-get-published-post-titles WPX)
(map last
(ref-all-match '("title" *)
(ref-all-match '("item" ("title" *) *
("wp:status" "publish") *
("wp:post_type" "post") *)
WPX))))
Code: Select all
> (wpx-get-published-post-titles *wp-export-db*)
("Permutations of a Multiset" "Ripping Access Databases in Clojure"
"Reactive Swing via Observables Pt 1" "Reactive Swing and Observables Pt 2"
"Reactive Swing and Observables Pt 3" "Reactive Swing and Observables pt 4"
"Reactive Swing and Observables Pt 5" "Reactive Swing and Observables Pt 6"
"Fun with Functional Reactive Programming Pt 1" "A Simple Scene Graph in Clojure")
Code: Select all
(define (wpx-extract-items WPX)
(ref-all-match '("item" *) WPX))
(define (mfilter M LST)
(filter (curry member M) LST))
(define (wpx-get-post-items WPX)
(mfilter '("wp:post_type" "post") (wpx-extract-items WPX)))
(define (wpx-get-published-post-items WPX)
(mfilter '("wp:status" "publish") (wpx-get-post-items WPX)))
(define (wpx-get-post-titles WPX)
(map (curry lookup "title") (wpx-get-post-items WPX)))
(define (wpx-get-published-post-titles WPX)
(map (curry lookup "title") (wpx-get-published-post-items WPX)))
in the next version newLISP translates XML : colons in tag names to dots in symbols names:like "wp:status". newLISP uses the colon too for symbol context qualification.
Code: Select all
<item>
<title>TEST</title>
<link>http://www.obeabe.de/?p=1090</link>
<pubDate>Thu, 10 Jan 2013 18:38:16 +0000</pubDate>
<dc:creator><![CDATA[Didi]]></dc:creator>
<category><![CDATA[Allgemein]]></category>
<category domain="category" nicename="allgemein"><![CDATA[Allgemein]]></category>
<guid isPermaLink="false">http://www.obeabe.de/?p=1090</guid>
<description></description>
<content:encoded><![CDATA[Testpost Testpost]]></content:encoded>
<excerpt:encoded><![CDATA[]]></excerpt:encoded>
<wp:post_id>1090</wp:post_id>
<wp:post_date>2013-01-10 18:38:16</wp:post_date>
<wp:post_date_gmt>2013-01-10 18:38:16</wp:post_date_gmt>
<wp:comment_status>open</wp:comment_status>
<wp:ping_status>open</wp:ping_status>
<wp:post_name>test</wp:post_name>
<wp:status>publish</wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
<wp:post_type>post</wp:post_type>
<wp:post_password></wp:post_password>
<wp:is_sticky>0</wp:is_sticky>
<wp:postmeta>
<wp:meta_key>_edit_lock</wp:meta_key>
<wp:meta_value>1357843097</wp:meta_value>
</wp:postmeta>
<wp:postmeta>
<wp:meta_key>_edit_last</wp:meta_key>
<wp:meta_value>1</wp:meta_value>
</wp:postmeta>
</item>
Code: Select all
(define *didi-example-item* (sxml<-file "didi-example-item.xml"))
(define (wpx-get-post-contents WPX)
(map (curry lookup "content:encoded") (wpx-get-post-items WPX)))
Code: Select all
> (wpx-get-post-contents *didi-example-item*)
("Testpost Testpost")
>
Code: Select all
(define (wpx-process-all-posts-from-wp-export WP-EXPORT-FILENAME)
(let (posts (wpx-get-post-items
(wpx-extract-items
(sxml<-file WP-EXPORT-FILENAME)))
post-filter
(fn (post)
(list 'post
(list 'title (lookup "title" post))
(list 'link (lookup "link" post))
(list 'author (lookup "dc:creator" post))
(list 'date (lookup "wp:post_date" post))
(list 'text (lookup "content:encoded" post)))))
(map post-filter posts)))
Code: Select all
> (wpx-process-all-posts-from-wp-export "didi-example-item.xml")
((post (title "TEST")
(link "http://www.obeabe.de/?p=1090")
(author "Didi")
(date "2013-01-10 18:38:16")
(text "Testpost Testpost")))
Code: Select all
<wp:postmeta>
<wp:meta_key>_oembed_f109b1315b82821c5f7d1d98a3530231</wp:meta_key>
<wp:meta_value><iframe width="500" height="375" src="http://www.youtube.com/embed/kKH77hfWYPU?fs=1&feature=oembed" frameborder="0" allowfullscreen></iframe></wp:meta_value>
</wp:postmeta>
Code: Select all
> (sxml<-file "didi-example-2-fix.xml")
(("wp:postmeta" ("wp:meta_key" "_oembed_f109b1315b82821c5f7d1d98a3530231") ("wp:meta_value"
"<iframe width=\"500\" height=\"375\" src=\"http://www.youtube.com/embed/kKH77hfWYPU?fs=1&feature=oembed\" frameborder=\"0\" allowfullscreen></iframe>")))