Created
June 5, 2010 22:23
-
-
Save davidlowry/427052 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cats_hierarchy={} | |
(doc/"wp:category").each do |category| | |
cat_name = category.at("wp:category_nicename").innerHTML | |
cat_parent = category.at("wp:category_parent").innerHTML | |
if cats_hierarchy.include? cat_parent | |
cats_hierarchy[cat_parent] = cat_name | |
else | |
cats_hierarchy[cat_name] = nil | |
end | |
end | |
cats = cats_hierarchy.to_a.flatten.uniq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
?> cats = cats_hierarchy.to_a.flatten.uniq | |
=> ["route66", nil, "rails", "american-2008", "reciprocal-affection", "hope-for-the-future", "code", "blog", "review-blog", "rant", "brands", "projects", "yab_shop", "textpattern", "meaningful-labor", "giants", "accessibility", "root", "charity-project", "apple", "xhtml", "america-2006-route-66", "ruby", "learning", "america-2007", "uncategorized", "iphone", "america-2008"] | |
?> cats_hierarchy | |
=> {"route66"=>nil, "rails"=>nil, "american-2008"=>nil, "reciprocal-affection"=>nil, "hope-for-the-future"=>nil, "code"=>nil, "blog"=>"review-blog", "rant"=>nil, "brands"=>nil, "projects"=>nil, "yab_shop"=>nil, "textpattern"=>nil, "meaningful-labor"=>nil, "giants"=>nil, "accessibility"=>nil, "root"=>nil, "charity-project"=>nil, "apple"=>nil, "xhtml"=>nil, "america-2006-route-66"=>nil, "ruby"=>nil, "learning"=>nil, "america-2007"=>nil, "uncategorized"=>nil, "iphone"=>nil, "america-2008"=>nil} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- generator="WordPress/2.9.2" created="2010-06-05 19:53"--> | |
<rss version="2.0" | |
xmlns:excerpt="http://wordpress.org/export/1.0/excerpt/" | |
xmlns:content="http://purl.org/rss/1.0/modules/content/" | |
xmlns:wfw="http://wellformedweb.org/CommentAPI/" | |
xmlns:dc="http://purl.org/dc/elements/1.1/" | |
xmlns:wp="http://wordpress.org/export/1.0/" | |
> | |
<channel> | |
<title>David Lowry</title> | |
<link>http://davidlowry.co.uk</link> | |
<description>Setting out freelance with Web and AV Solutions</description> | |
<pubDate>Mon, 26 Apr 2010 12:12:31 +0000</pubDate> | |
<generator>http://wordpress.org/?v=2.9.2</generator> | |
<language>en</language> | |
<wp:wxr_version>1.0</wp:wxr_version> | |
<wp:base_site_url>http://davidlowry.co.uk</wp:base_site_url> | |
<wp:base_blog_url>http://davidlowry.co.uk</wp:base_blog_url> | |
<wp:category><wp:category_nicename>accessibility</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name><![CDATA[accessibility]]></wp:cat_name></wp:category> | |
<wp:category><wp:category_nicename>america-2006-route-66</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name><![CDATA[America 2006 Route 66]]></wp:cat_name></wp:category> | |
<wp:category><wp:category_nicename>america-2007</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name><![CDATA[America 2007]]></wp:cat_name></wp:category> | |
<wp:category><wp:category_nicename>america-2008</wp:category_nicename><wp:category_parent></wp:category_parent><wp:cat_name><![CDATA[America 2008]]></wp:cat_name></wp:category> | |
.... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
A set of gists from my article on importing Wordpress' exported XML into a ruby application. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cats_hierarchy={}
(doc/"wp:category").each do |category|
cat_name = category.at("wp:category_nicename").innerHTML
cat_parent = category.at("wp:category_parent").innerHTML
end
cats = cats_hierarchy.to_a.flatten.uniq