# Nokogiri usage

**URL:** <https://www.ruby-forum.com/t/nokogiri-usage/177848>\
**Category:** Ruby\
**Created:** [October 25, 2009, 10:31am UTC](https://www.ruby-forum.com/t/nokogiri-usage/177848 "2009-10-25T10:31:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [October 25, 2009, 10:31am UTC](https://www.ruby-forum.com/t/nokogiri-usage/177848/1 "2009-10-25T10:31:53Z")

</div>

Hi,

In one of my Rails app, I have a content attribute that hosts some html  
code. I want to parse this content and replace ![]() tags by something  
else. I used to do Nokogiri::HTML(content), and then do my parsing, then  
return the content.

The problem is that nokogiri injects the doctype and tags  
which obviously messes up my final html page because of these duplicate  
tags.

So how to perform the parsing without having to first initialize the  
content with Nokogiri::HTML, or how to not initialize a full html page  
from my content?

Cheers,

---

<div class="post-metadata">

**Author:** ![fipa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/9e8a1a/32.png) [@fipa](https://www.ruby-forum.com/u/fipa)\
**Post date:** [October 25, 2009, 7:14pm UTC](https://www.ruby-forum.com/t/nokogiri-usage/177848/2 "2009-10-25T19:14:35Z")

</div>

On Sun, Oct 25, 2009 at 5:31 AM, Fernando P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> So how to perform the parsing without having to first initialize the  
> content with Nokogiri::HTML, or how to not initialize a full html page  
> from my content?

Try Nokogiri::HTML::DocumentFragment.parse(content).
