# Hpricot question

**URL:** <https://www.ruby-forum.com/t/hpricot-question/109808>\
**Category:** Ruby\
**Created:** [July 19, 2007, 8:33am UTC](https://www.ruby-forum.com/t/hpricot-question/109808 "2007-07-19T08:33:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![apie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@apie](https://www.ruby-forum.com/u/apie)\
**Post date:** [July 19, 2007, 8:33am UTC](https://www.ruby-forum.com/t/hpricot-question/109808/1 "2007-07-19T08:33:43Z")

</div>

I’m a total hpricot newbie, so this is only out of curiousity…

Is the following expected behaviour?  
I found this while struggling through a nasty xml parsing bug.

hstr = Hpricot(‘ **c** ’).to\_s #or to\_html

returns =\> ‘ **c** ’

I have found that using to\_original\_html returns ‘ **c** ’ as  
expected  
but I was wondering why you would want to wrap the other contents  
when  
it obviously isn’t correct? Is this handy behaviour for scrapping?

regards

---

<div class="post-metadata">

**Author:** ![apie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@apie](https://www.ruby-forum.com/u/apie)\
**Post date:** [July 19, 2007, 2:30pm UTC](https://www.ruby-forum.com/t/hpricot-question/109808/2 "2007-07-19T14:30:39Z")

</div>

On Jul 19, 2007, at 1:32 AM, Ivor P. wrote:

> expected  
> but I was wondering why you would want to wrap the other  
> contents when  
> it obviously isn’t correct? Is this handy behaviour for scrapping?
> 
> regards  
> Hmm… if you want modern markup, it is correct.  
> Link’s text here  
> You’d do well to avoid in favor of

---

<div class="post-metadata">

**Author:** ![apie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@apie](https://www.ruby-forum.com/u/apie)\
**Post date:** [July 19, 2007, 3:34pm UTC](https://www.ruby-forum.com/t/hpricot-question/109808/3 "2007-07-19T15:34:44Z")

</div>

On 7/19/07, Ivor P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> but I was wondering why you would want to wrap the other contents when  
> it obviously isn’t correct? Is this handy behaviour for scrapping?

 

Yeah, I never understand that either. But it’s easily fixed:

 

h = Hpricot(‘ **c** ’, :xml =\> true)  
h.to\_s =\> “ **c** ”

I think it’s because when you don’t define :xml as true, then Hpricot  
acts as an _HTML_ processor, and therefore tries to correct bad HTML…  
and somehow ends up with the badness of wrapping the empty element.

Cheers,  
Peter C.

> **[Ruby Inside: The Ruby Blog](http://www.rubyinside.com/)**
>
> The biggest Ruby and Rails blog since 2006 - tutorials, news, and lots more

---

<div class="post-metadata">

**Author:** ![apie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecccb3/32.png) [@apie](https://www.ruby-forum.com/u/apie)\
**Post date:** [July 19, 2007, 8:28pm UTC](https://www.ruby-forum.com/t/hpricot-question/109808/4 "2007-07-19T20:28:34Z")

</div>

Thanks peter - that is what I wanted to hear! I knew there was some  
reason  
like that.
