Hello,

I'm trying to use nokogiri gem to parse individual xhtml tags (not the
whole html document) and preform some processing on them.

Heres an example of a string that I want to process:

str = '<img
src="http://www.canadascapital.gc.ca/data/2/rec_imgs/5005_Pepsi_H1NB.gif"/>
some text<a href="#">test</a> ....'

The following code will add html/body and head tags, and also document
type which I dont want (I know I could go though html->body children of
the root node but I suspect there is some better way to get expected
part with NG):

  f = Nokogiri::HTML(str)
  f.search('//img').each do |url|
    #some processing
  end
  puts f


If I try to use XML fragment:

  f = Nokogiri::XML.fragment(str)
  f.search('//img').each do |node|
    #node.remove
  end
  puts f

The code wont parse the html string but it will print it without adding
standard tags to it.

What am I doing wrong?

Many thanks for help!
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to