Hi all n = Nokogiri::HTML("<h1>H1</h1>") n.to_s # => <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><h1>H1</h1></body></html> Is there a method that only outputs the stuff I''ve read, and not the whole valid XHTML stuff? Needed output: <h1>H1</h1> Thanks a lot Josh -- Posted via http://www.ruby-forum.com/.
Marnen Laibow-Koser
2009-Oct-13 22:01 UTC
Re: Nokogiri: to_s WITHOUT html surrounding''s tags?
Joshua Muheim wrote:> Hi all > > n = Nokogiri::HTML("<h1>H1</h1>") > n.to_s > # => <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" > \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><h1>H1</h1></body></html> > > Is there a method that only outputs the stuff I''ve read, and not the > whole valid XHTML stuff? > > Needed output: > <h1>H1</h1>If all you need is the original input, then why bother running it through Nokogiri?> > Thanks a lot > JoshBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
> If all you need is the original input, then why bother running it > through Nokogiri?Obviously that''s just for presentation purposes... I will apply some other stuff to the DOM, too... -- Posted via http://www.ruby-forum.com/.
Marnen Laibow-Koser
2009-Oct-13 23:03 UTC
Re: Nokogiri: to_s WITHOUT html surrounding''s tags?
Joshua Muheim wrote:>> If all you need is the original input, then why bother running it >> through Nokogiri? > > Obviously that''s just for presentation purposes... I will apply some > other stuff to the DOM, too...OK. So try again with an example that is closer to what you actually need. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.
> OK. So try again with an example that is closer to what you actually > need.The example above is exactly what I need. I think my question is quite simple? -- Posted via http://www.ruby-forum.com/.
Hassan Schroeder
2009-Oct-13 23:33 UTC
Re: Nokogiri: to_s WITHOUT html surrounding''s tags?
On Tue, Oct 13, 2009 at 2:53 PM, Joshua Muheim <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> n = Nokogiri::HTML("<h1>H1</h1>") > n.to_s > # => <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" > \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n<html><body><h1>H1</h1></body></html> > > Is there a method that only outputs the stuff I''ve read, and not the > whole valid XHTML stuff?Well, it''s not XHTML, if you note the doctype :-) but ...> Needed output: > <h1>H1</h1>>> n = Nokogiri::HTML("<h1>H1</h1>").xpath(''//h1'').to_xml=> "<h1>H1</h1>" I would think that''d be pretty apparent from a glance at the examples in the rdoc, btw. Just sayin'' :-) -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan
On Tue, Oct 13, 2009 at 2:53 PM, Joshua Muheim < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi all > > n = Nokogiri::HTML("<h1>H1</h1>") > n.to_s > # => <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" > \"http://www.w3.org/TR/REC-html40/loose.dtd > \">\n<html><body><h1>H1</h1></body></html> > > Is there a method that only outputs the stuff I''ve read, and not the > whole valid XHTML stuff? > > Needed output: > <h1>H1</h1> > > Thanks a lot > Josh >You can do the following: Nokogiri::HTML("<h1>H1</h1>").css( ''h1'' ) Good luck, -Conrad> -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Tue, Oct 13, 2009 at 4:49 PM, Conrad Taylor <conradwt-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Tue, Oct 13, 2009 at 2:53 PM, Joshua Muheim < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> >> Hi all >> >> n = Nokogiri::HTML("<h1>H1</h1>") >> n.to_s >> # => <!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" >> \"http://www.w3.org/TR/REC-html40/loose.dtd >> \">\n<html><body><h1>H1</h1></body></html> >> >> Is there a method that only outputs the stuff I''ve read, and not the >> whole valid XHTML stuff? >> >> Needed output: >> <h1>H1</h1> >> >> Thanks a lot >> Josh >> > > You can do the following: > > Nokogiri::HTML("<h1>H1</h1>").css( ''h1'' ) > >The example above produces a node of the DOM and adding ''to_s'' will give you the string.> Good luck, > > -Conrad > > >> -- >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thank you, guys. I didn''t know that Nokogiri creates a complete (X)HTML DOM when reading an incomplete structure. Have a great day! -- Posted via http://www.ruby-forum.com/.
Joshua Muheim wrote:> Thank you, guys. I didn''t know that Nokogiri creates a complete (X)HTML > DOM when reading an incomplete structure. > > Have a great day!Another question. I don''t get Nokogiri to produce XHTML. So for example I get unclosed tags like <hr> instead of <hr />. I found some options (http://nokogiri.rubyforge.org/nokogiri/Nokogiri/XML/ParseOptions.html) but I don''t really know how to get them to work... -- Posted via http://www.ruby-forum.com/.