-
-
Save advorak/833794 to your computer and use it in GitHub Desktop.
Revisions
-
advorak revised this gist
Feb 18, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,7 @@ doc = Nokogiri::XML(fh) #insert thumbnail for selected authors. retval=(doc.xpath("//author[text()='Bob']/..")).collect do |item| # Array#map == Array#collect media=Nokogiri::XML::Node.new "media:thumbnail", item media.set_attribute("url","http://url/file.jpg") author=item.at_xpath "author" -
dtolj revised this gist
Feb 18, 2011 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,8 @@ <title>Book1</title> <author>Bob</author> <link>http://url1.com</link> </item> <item> <title>Book2</title> <author>Bob</author> <link>http://url1.com</link> -
dtolj created this gist
Feb 18, 2011 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ [myxml] <item> <title>Book1</title> <author>Bob</author> <link>http://url1.com</link> <title>Book2</title> <author>Bob</author> <link>http://url1.com</link> </item> doc = Nokogiri::XML(fh) #insert thumbnail for selected authors. retval=(doc.xpath("//author[text()='Bob']/..")).each do |item| media=Nokogiri::XML::Node.new "media:thumbnail", item media.set_attribute("url","http://url/file.jpg") author=item.at_xpath "author" author.add_next_sibling(media) end puts doc.to_xml #returns all nodes + Bob's thumbnails puts retval.to_xml #returns nothing How to assign the matching block value to an array?